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