1 | #!/bin/bash |
---|
2 | |
---|
3 | # Usage: dasource [-r REPOS] [PACKAGENAME ...] |
---|
4 | |
---|
5 | # Creates or updates a checkout and source package for each listed |
---|
6 | # PACKAGENAME, or for all regular packages if no PACKAGENAME is |
---|
7 | # specified. |
---|
8 | |
---|
9 | # If REPOS is specified, it is used in preference to the canonical |
---|
10 | # Athena repository trunk. |
---|
11 | |
---|
12 | # Package subdirectories are created in the cwd. The source checkout |
---|
13 | # will reside in PACKAGENAME/PACKAGENAME-VERSION and the source |
---|
14 | # package will be created in PACKAGENAME. |
---|
15 | |
---|
16 | set -e |
---|
17 | |
---|
18 | trap 'echo "dasource failed: Source package _not_ created"' EXIT |
---|
19 | |
---|
20 | die() { |
---|
21 | echo "$@" >&2 |
---|
22 | exit 1 |
---|
23 | } |
---|
24 | |
---|
25 | usage() { |
---|
26 | die "dasource [-r repos] [packagename ...]" |
---|
27 | } |
---|
28 | |
---|
29 | basedir=$(dirname "$(readlink -f "$0")") |
---|
30 | repo=svn+ssh://svn.mit.edu/athena/trunk |
---|
31 | |
---|
32 | while getopts r: opt; do |
---|
33 | case "$opt" in |
---|
34 | r) |
---|
35 | repo="$OPTARG" |
---|
36 | ;; |
---|
37 | \?) |
---|
38 | usage |
---|
39 | ;; |
---|
40 | esac |
---|
41 | done |
---|
42 | shift $(($OPTIND - 1)) |
---|
43 | |
---|
44 | do_package() { |
---|
45 | pkgname=$1 |
---|
46 | pkgpath=$2 |
---|
47 | if [ ! -d $pkgname ]; then |
---|
48 | echo "Creating directory $pkgname" |
---|
49 | mkdir $pkgname |
---|
50 | fi |
---|
51 | |
---|
52 | # Work around a bad interaction between dpkg-source and AFS. |
---|
53 | # (dpkg-source invokes perl's Tempfile which checks if the parent |
---|
54 | # directory is writable using mode bits). This will not actually |
---|
55 | # grant any outside access to the directory since AFS ignores |
---|
56 | # non-user mode bits. |
---|
57 | if fs whichcell . >/dev/null 2>&1; then |
---|
58 | chmod 777 $pkgname |
---|
59 | fi |
---|
60 | |
---|
61 | # Check out or update the package source. |
---|
62 | pattern="$pkgname/$pkgname-[0-9]*[0-9]" |
---|
63 | if [ $(echo $pattern | wc -w) -gt 1 ]; then |
---|
64 | die "More than one checkout under $pkgname!" |
---|
65 | elif [ -d $pattern ]; then |
---|
66 | dir=$(echo $pattern) |
---|
67 | echo "Updating and cleaning $dir" |
---|
68 | (cd $dir && svn update && svn revert -R . && |
---|
69 | svn st | awk '/^?/ {print $2}' | xargs rm -vrf) |
---|
70 | else |
---|
71 | dir=$pkgname/$pkgname |
---|
72 | echo "Checking out $repo/$pkgpath into $dir" |
---|
73 | svn co $repo/$pkgpath $dir |
---|
74 | fi |
---|
75 | |
---|
76 | # Extract the changelog version and strip off the epoch and Debian component. |
---|
77 | changever=$(cd $dir && dpkg-parsechangelog | sed -n 's/Version: //p') |
---|
78 | sver=$(echo $changever | sed -re 's/^[0-9]+://p') |
---|
79 | upver=$(echo $sver | sed -re 's/-[^-]*$//') |
---|
80 | |
---|
81 | # Rename the source checkout if necessary. |
---|
82 | correctdir=$pkgname/${pkgname}-$upver |
---|
83 | if [ $dir != $correctdir ]; then |
---|
84 | echo "Renaming $dir to $correctdir" |
---|
85 | mv $dir $correctdir |
---|
86 | dir=$correctdir |
---|
87 | fi |
---|
88 | |
---|
89 | # Add autoconf goo if it's an Athena source directory. |
---|
90 | case $pkgpath in |
---|
91 | athena/*) |
---|
92 | if [ -e "$dir/configure.in" ]; then |
---|
93 | (cd $dir && $basedir/daconfiscate) |
---|
94 | fi |
---|
95 | ;; |
---|
96 | esac |
---|
97 | |
---|
98 | # Generate debian/control from debian/control.in if control.in exists |
---|
99 | ([ -f "$dir/debian/control.in" ] && cd $dir && DEB_AUTO_UPDATE_DEBIAN_CONTROL=yes debian/rules debian/control || :) |
---|
100 | [ -f "$dir/debian/control" ] || die "Can't find or generate debian/control!" |
---|
101 | |
---|
102 | # Read in debian-versions |
---|
103 | . $basedir/debian-versions.sh |
---|
104 | |
---|
105 | NOBUILD=$(grep-dctrl -n -s X-Debathena-No-Build -F X-Debathena-No-Build -e . "$dir/debian/control" || true) |
---|
106 | BUILDFOR=$(grep-dctrl -n -s X-Debathena-Build-For -F X-Debathena-Build-For -e . "$dir/debian/control" || true) |
---|
107 | if [ -n "$NOBUILD" ] && [ -n "$BUILDFOR" ]; then |
---|
108 | echo "It is an error to specify both X-Debathena-Build-For and" |
---|
109 | echo "X-Debathena-No-Build. Pick one and try again." |
---|
110 | die |
---|
111 | elif [ -z "$NOBUILD" ] && [ -z "$BUILDFOR" ]; then |
---|
112 | [ -f "$pkgname/nobuild" ] && echo "NOTE: Please migrate legacy ./nobuild to X-Debathena-No-Build!" |
---|
113 | else |
---|
114 | [ -f "$pkgname/nobuild" ] && rm "$pkgname/nobuild" |
---|
115 | if [ -n "$BUILDFOR" ]; then |
---|
116 | NOBUILD= |
---|
117 | for code in $DEBIAN_CODES; do |
---|
118 | if ! echo "$BUILDFOR" | fgrep -q "$code"; then |
---|
119 | NOBUILD="$NOBUILD $code" |
---|
120 | fi |
---|
121 | done |
---|
122 | fi |
---|
123 | echo "$NOBUILD" > "$pkgname/nobuild" |
---|
124 | fi |
---|
125 | |
---|
126 | # Create a suitable orig tarball if necessary. |
---|
127 | (cd $dir && $basedir/daorig) |
---|
128 | |
---|
129 | # Build an unsigned package, ignoring version control subdirs in the source. |
---|
130 | echo "Creating source package" |
---|
131 | (cd $dir && debuild -S -i -I.svn -sa -us -uc) |
---|
132 | |
---|
133 | if grep '^Architecture: ' $dir/debian/control | grep -q -v 'Architecture: all'; then |
---|
134 | echo "At least one arch-dependent binary package; run sbuildhack WITHOUT -A." >&2 |
---|
135 | elif grep -q '^Architecture: ' $dir/debian/control; then |
---|
136 | echo "No arch-dependent binary packages; run sbuildhack with -A." >&2 |
---|
137 | else |
---|
138 | echo "No binary packages???" >&2 |
---|
139 | fi |
---|
140 | } |
---|
141 | |
---|
142 | packages=packages |
---|
143 | |
---|
144 | if [ ! -r "$packages" ]; then |
---|
145 | packages=/mit/debathena/packages/packages |
---|
146 | fi |
---|
147 | if [ ! -r "$packages" ]; then |
---|
148 | die "Can't read packages file; create with gen-packages" |
---|
149 | fi |
---|
150 | |
---|
151 | if [ $# -gt 0 ]; then |
---|
152 | # Build specific source packages. |
---|
153 | for pkgname; do |
---|
154 | pkgname="${pkgname%/}" |
---|
155 | pkgpath=$(sed -nre "s/^$pkgname[[:space:]]+//p" "$packages") |
---|
156 | if ! [ -n "$pkgpath" ]; then |
---|
157 | echo "Can't find package $pkgname" >&2 |
---|
158 | echo >&2 |
---|
159 | echo "This may be because the list of packages is not up to date. If" >&2 |
---|
160 | echo "this is a new package, and you have the bits, run gen-packages" >&2 |
---|
161 | echo "with /mit/debathena/packages as your working directory." >&2 |
---|
162 | echo "Otherwise, run gen-packages in this directory and dasource will" >&2 |
---|
163 | echo "use the generated file instead." >&2 |
---|
164 | die |
---|
165 | fi |
---|
166 | do_package $pkgname $pkgpath |
---|
167 | done |
---|
168 | else |
---|
169 | # Build all source packages. |
---|
170 | exec <"$packages" |
---|
171 | while read pkgname pkgpath; do |
---|
172 | do_package $pkgname $pkgpath |
---|
173 | done |
---|
174 | fi |
---|