[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 | |
---|
[22742] | 18 | die() { |
---|
| 19 | echo "$@" >&2 |
---|
| 20 | exit 1 |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | usage() { |
---|
| 24 | die "dasource [-r repos] [packagename ...]" |
---|
| 25 | } |
---|
| 26 | |
---|
[22720] | 27 | basedir=$(dirname "$0") |
---|
[22704] | 28 | repo=svn+ssh://svn.mit.edu/athena/trunk |
---|
| 29 | |
---|
| 30 | while getopts r: opt; do |
---|
| 31 | case "$opt" in |
---|
| 32 | r) |
---|
[23917] | 33 | repo="$OPTARG" |
---|
[22704] | 34 | ;; |
---|
| 35 | \?) |
---|
[22742] | 36 | usage |
---|
[22704] | 37 | ;; |
---|
| 38 | esac |
---|
| 39 | done |
---|
[23917] | 40 | shift $(($OPTIND - 1)) |
---|
[22704] | 41 | |
---|
| 42 | do_package() { |
---|
| 43 | pkgname=$1 |
---|
| 44 | pkgpath=$2 |
---|
| 45 | if [ ! -d $pkgname ]; then |
---|
| 46 | echo "Creating directory $pkgname" |
---|
| 47 | mkdir $pkgname |
---|
| 48 | fi |
---|
[22706] | 49 | |
---|
[23064] | 50 | # Work around a bad interaction between dpkg-source and AFS. |
---|
| 51 | # (dpkg-source invokes perl's Tempfile which checks if the parent |
---|
| 52 | # directory is writable using mode bits). This will not actually |
---|
| 53 | # grant any outside access to the directory since AFS ignores |
---|
| 54 | # non-user mode bits. |
---|
| 55 | if fs whichcell . >/dev/null 2>&1; then |
---|
| 56 | chmod 777 $pkgname |
---|
| 57 | fi |
---|
| 58 | |
---|
[22706] | 59 | # Check out or update the package source. |
---|
[22767] | 60 | pattern="$pkgname/$pkgname-[0-9]*[0-9]" |
---|
| 61 | if [ $(echo $pattern | wc -w) -gt 1 ]; then |
---|
[22704] | 62 | die "More than one checkout under $pkgname!" |
---|
[22767] | 63 | elif [ -d $pattern ]; then |
---|
| 64 | dir=$(echo $pattern) |
---|
[22712] | 65 | echo "Updating and cleaning $dir" |
---|
| 66 | (cd $dir && svn update && svn revert -R . && |
---|
| 67 | svn st | awk '/^?/ {print $2}' | xargs rm -vrf) |
---|
[22704] | 68 | else |
---|
| 69 | dir=$pkgname/$pkgname |
---|
| 70 | echo "Checking out $repo/$pkgpath into $dir" |
---|
| 71 | svn co $repo/$pkgpath $dir |
---|
| 72 | fi |
---|
[22706] | 73 | |
---|
| 74 | # Extract the changelog version and strip off the epoch and Debian component. |
---|
[22704] | 75 | changever=$(cd $dir && dpkg-parsechangelog | sed -n 's/Version: //p') |
---|
[22706] | 76 | sver=$(echo $changever | sed -re 's/^[0-9]+://p') |
---|
| 77 | upver=$(echo $sver | sed -re 's/-[^-]*$//') |
---|
| 78 | |
---|
| 79 | # Rename the source checkout if necessary. |
---|
[22704] | 80 | correctdir=$pkgname/${pkgname}-$upver |
---|
| 81 | if [ $dir != $correctdir ]; then |
---|
| 82 | echo "Renaming $dir to $correctdir" |
---|
| 83 | mv $dir $correctdir |
---|
| 84 | dir=$correctdir |
---|
| 85 | fi |
---|
[22706] | 86 | |
---|
[22720] | 87 | # Add autoconf goo if it's an Athena source directory. |
---|
| 88 | case $pkgpath in |
---|
| 89 | athena/*) |
---|
[24537] | 90 | if [ -e "$basedir/configure.in" ]; then |
---|
[24437] | 91 | (cd $dir && $basedir/daconfiscate) |
---|
| 92 | fi |
---|
[22720] | 93 | ;; |
---|
| 94 | esac |
---|
| 95 | |
---|
[23407] | 96 | # Generate debian/control from debian/control.in if control.in exists |
---|
[23446] | 97 | ([ -f "$dir/debian/control.in" ] && cd $dir && DEB_AUTO_UPDATE_DEBIAN_CONTROL=yes debian/rules debian/control || :) |
---|
| 98 | [ -f "$dir/debian/control" ] || die "Can't find or generate debian/control!" |
---|
[23290] | 99 | |
---|
[22786] | 100 | # Create a suitable orig tarball if necessary. |
---|
[23440] | 101 | (cd $dir && $basedir/daorig) |
---|
[22706] | 102 | |
---|
| 103 | # Build an unsigned package, ignoring version control subdirs in the source. |
---|
[22704] | 104 | echo "Creating source package" |
---|
[22766] | 105 | (cd $dir && debuild -S -i -I.svn -sa -us -uc) |
---|
[22704] | 106 | } |
---|
| 107 | |
---|
[24375] | 108 | packages=packages |
---|
| 109 | |
---|
| 110 | if [ ! -r "$packages" ]; then |
---|
| 111 | packages=/mit/debathena/packages/packages |
---|
| 112 | fi |
---|
| 113 | if [ ! -r "$packages" ]; then |
---|
[22745] | 114 | die "Can't read packages file; create with gen-packages" |
---|
| 115 | fi |
---|
| 116 | |
---|
[22704] | 117 | if [ $# -gt 0 ]; then |
---|
| 118 | # Build specific source packages. |
---|
| 119 | for pkgname; do |
---|
[24424] | 120 | pkgname="${pkgname%/}" |
---|
[24375] | 121 | pkgpath=$(sed -nre "s/^$pkgname[[:space:]]+//p" "$packages") |
---|
[22704] | 122 | [ -n "$pkgpath" ] || die "Can't find package $pkgname" |
---|
| 123 | do_package $pkgname $pkgpath |
---|
| 124 | done |
---|
| 125 | else |
---|
| 126 | # Build all source packages. |
---|
[24375] | 127 | exec <"$packages" |
---|
[22704] | 128 | while read pkgname pkgpath; do |
---|
| 129 | do_package $pkgname $pkgpath |
---|
| 130 | done |
---|
| 131 | fi |
---|