[24425] | 1 | #!/bin/bash |
---|
[22704] | 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 | |
---|
[25512] | 18 | trap 'echo "dasource failed: Source package _not_ created"' EXIT |
---|
| 19 | |
---|
[22742] | 20 | die() { |
---|
| 21 | echo "$@" >&2 |
---|
| 22 | exit 1 |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | usage() { |
---|
| 26 | die "dasource [-r repos] [packagename ...]" |
---|
| 27 | } |
---|
| 28 | |
---|
[25420] | 29 | basedir=$(dirname "$(readlink -f "$0")") |
---|
[22704] | 30 | repo=svn+ssh://svn.mit.edu/athena/trunk |
---|
| 31 | |
---|
| 32 | while getopts r: opt; do |
---|
| 33 | case "$opt" in |
---|
| 34 | r) |
---|
[23917] | 35 | repo="$OPTARG" |
---|
[22704] | 36 | ;; |
---|
| 37 | \?) |
---|
[22742] | 38 | usage |
---|
[22704] | 39 | ;; |
---|
| 40 | esac |
---|
| 41 | done |
---|
[23917] | 42 | shift $(($OPTIND - 1)) |
---|
[22704] | 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 |
---|
[22706] | 51 | |
---|
[23064] | 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 | |
---|
[22706] | 61 | # Check out or update the package source. |
---|
[22767] | 62 | pattern="$pkgname/$pkgname-[0-9]*[0-9]" |
---|
| 63 | if [ $(echo $pattern | wc -w) -gt 1 ]; then |
---|
[22704] | 64 | die "More than one checkout under $pkgname!" |
---|
[22767] | 65 | elif [ -d $pattern ]; then |
---|
| 66 | dir=$(echo $pattern) |
---|
[22712] | 67 | echo "Updating and cleaning $dir" |
---|
| 68 | (cd $dir && svn update && svn revert -R . && |
---|
| 69 | svn st | awk '/^?/ {print $2}' | xargs rm -vrf) |
---|
[22704] | 70 | else |
---|
| 71 | dir=$pkgname/$pkgname |
---|
| 72 | echo "Checking out $repo/$pkgpath into $dir" |
---|
| 73 | svn co $repo/$pkgpath $dir |
---|
| 74 | fi |
---|
[22706] | 75 | |
---|
[25578] | 76 | # Ensure that we're not trying to do something stupid |
---|
| 77 | distribution=$(cd $dir && dpkg-parsechangelog | sed -n 's/Distribution: //p') |
---|
| 78 | if [ "$distribution" = "UNRELEASED" ]; then |
---|
| 79 | echo "You can't/shouldn't build a package marked as UNRELEASED." |
---|
| 80 | exit 1 |
---|
| 81 | fi |
---|
| 82 | |
---|
[22706] | 83 | # Extract the changelog version and strip off the epoch and Debian component. |
---|
[22704] | 84 | changever=$(cd $dir && dpkg-parsechangelog | sed -n 's/Version: //p') |
---|
[22706] | 85 | sver=$(echo $changever | sed -re 's/^[0-9]+://p') |
---|
| 86 | upver=$(echo $sver | sed -re 's/-[^-]*$//') |
---|
| 87 | |
---|
| 88 | # Rename the source checkout if necessary. |
---|
[22704] | 89 | correctdir=$pkgname/${pkgname}-$upver |
---|
| 90 | if [ $dir != $correctdir ]; then |
---|
| 91 | echo "Renaming $dir to $correctdir" |
---|
| 92 | mv $dir $correctdir |
---|
| 93 | dir=$correctdir |
---|
| 94 | fi |
---|
[22706] | 95 | |
---|
[22720] | 96 | # Add autoconf goo if it's an Athena source directory. |
---|
| 97 | case $pkgpath in |
---|
| 98 | athena/*) |
---|
[24567] | 99 | if [ -e "$dir/configure.in" ]; then |
---|
[24437] | 100 | (cd $dir && $basedir/daconfiscate) |
---|
| 101 | fi |
---|
[22720] | 102 | ;; |
---|
| 103 | esac |
---|
| 104 | |
---|
[23407] | 105 | # Generate debian/control from debian/control.in if control.in exists |
---|
[23446] | 106 | ([ -f "$dir/debian/control.in" ] && cd $dir && DEB_AUTO_UPDATE_DEBIAN_CONTROL=yes debian/rules debian/control || :) |
---|
| 107 | [ -f "$dir/debian/control" ] || die "Can't find or generate debian/control!" |
---|
[23290] | 108 | |
---|
[25498] | 109 | # Read in debian-versions |
---|
| 110 | . $basedir/debian-versions.sh |
---|
| 111 | |
---|
[25512] | 112 | NOBUILD=$(grep-dctrl -n -s X-Debathena-No-Build -F X-Debathena-No-Build -e . "$dir/debian/control" || true) |
---|
| 113 | BUILDFOR=$(grep-dctrl -n -s X-Debathena-Build-For -F X-Debathena-Build-For -e . "$dir/debian/control" || true) |
---|
[25498] | 114 | if [ -n "$NOBUILD" ] && [ -n "$BUILDFOR" ]; then |
---|
| 115 | echo "It is an error to specify both X-Debathena-Build-For and" |
---|
| 116 | echo "X-Debathena-No-Build. Pick one and try again." |
---|
| 117 | die |
---|
| 118 | elif [ -z "$NOBUILD" ] && [ -z "$BUILDFOR" ]; then |
---|
| 119 | [ -f "$pkgname/nobuild" ] && echo "NOTE: Please migrate legacy ./nobuild to X-Debathena-No-Build!" |
---|
| 120 | else |
---|
| 121 | [ -f "$pkgname/nobuild" ] && rm "$pkgname/nobuild" |
---|
| 122 | if [ -n "$BUILDFOR" ]; then |
---|
| 123 | NOBUILD= |
---|
| 124 | for code in $DEBIAN_CODES; do |
---|
| 125 | if ! echo "$BUILDFOR" | fgrep -q "$code"; then |
---|
| 126 | NOBUILD="$NOBUILD $code" |
---|
| 127 | fi |
---|
| 128 | done |
---|
| 129 | fi |
---|
| 130 | echo "$NOBUILD" > "$pkgname/nobuild" |
---|
| 131 | fi |
---|
| 132 | |
---|
[22786] | 133 | # Create a suitable orig tarball if necessary. |
---|
[23440] | 134 | (cd $dir && $basedir/daorig) |
---|
[22706] | 135 | |
---|
| 136 | # Build an unsigned package, ignoring version control subdirs in the source. |
---|
[22704] | 137 | echo "Creating source package" |
---|
[22766] | 138 | (cd $dir && debuild -S -i -I.svn -sa -us -uc) |
---|
[24886] | 139 | |
---|
| 140 | if grep '^Architecture: ' $dir/debian/control | grep -q -v 'Architecture: all'; then |
---|
| 141 | echo "At least one arch-dependent binary package; run sbuildhack WITHOUT -A." >&2 |
---|
| 142 | elif grep -q '^Architecture: ' $dir/debian/control; then |
---|
| 143 | echo "No arch-dependent binary packages; run sbuildhack with -A." >&2 |
---|
| 144 | else |
---|
| 145 | echo "No binary packages???" >&2 |
---|
| 146 | fi |
---|
[22704] | 147 | } |
---|
| 148 | |
---|
[24375] | 149 | packages=packages |
---|
| 150 | |
---|
| 151 | if [ ! -r "$packages" ]; then |
---|
| 152 | packages=/mit/debathena/packages/packages |
---|
| 153 | fi |
---|
| 154 | if [ ! -r "$packages" ]; then |
---|
[22745] | 155 | die "Can't read packages file; create with gen-packages" |
---|
| 156 | fi |
---|
| 157 | |
---|
[22704] | 158 | if [ $# -gt 0 ]; then |
---|
| 159 | # Build specific source packages. |
---|
| 160 | for pkgname; do |
---|
[24424] | 161 | pkgname="${pkgname%/}" |
---|
[24375] | 162 | pkgpath=$(sed -nre "s/^$pkgname[[:space:]]+//p" "$packages") |
---|
[24717] | 163 | if ! [ -n "$pkgpath" ]; then |
---|
| 164 | echo "Can't find package $pkgname" >&2 |
---|
| 165 | echo >&2 |
---|
| 166 | echo "This may be because the list of packages is not up to date. If" >&2 |
---|
| 167 | echo "this is a new package, and you have the bits, run gen-packages" >&2 |
---|
| 168 | echo "with /mit/debathena/packages as your working directory." >&2 |
---|
| 169 | echo "Otherwise, run gen-packages in this directory and dasource will" >&2 |
---|
| 170 | echo "use the generated file instead." >&2 |
---|
| 171 | die |
---|
| 172 | fi |
---|
[22704] | 173 | do_package $pkgname $pkgpath |
---|
| 174 | done |
---|
| 175 | else |
---|
| 176 | # Build all source packages. |
---|
[24375] | 177 | exec <"$packages" |
---|
[22704] | 178 | while read pkgname pkgpath; do |
---|
| 179 | do_package $pkgname $pkgpath |
---|
| 180 | done |
---|
| 181 | fi |
---|
[25513] | 182 | # Unset trap |
---|
| 183 | trap - EXIT |
---|