source: trunk/debathena/scripts/dasource @ 25513

Revision 25513, 5.2 KB checked in by jdreed, 12 years ago (diff)
Unset the trap before we exit
  • Property svn:executable set to *
RevLine 
[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
16set -e
17
[25512]18trap 'echo "dasource failed: Source package _not_ created"' EXIT
19
[22742]20die() {
21  echo "$@" >&2
22  exit 1
23}
24
25usage() {
26  die "dasource [-r repos] [packagename ...]"
27}
28
[25420]29basedir=$(dirname "$(readlink -f "$0")")
[22704]30repo=svn+ssh://svn.mit.edu/athena/trunk
31
32while getopts r: opt; do
33  case "$opt" in
34  r)
[23917]35    repo="$OPTARG"
[22704]36    ;;
37  \?)
[22742]38    usage
[22704]39    ;;
40  esac
41done
[23917]42shift $(($OPTIND - 1))
[22704]43
44do_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
76  # Extract the changelog version and strip off the epoch and Debian component.
[22704]77  changever=$(cd $dir && dpkg-parsechangelog | sed -n 's/Version: //p')
[22706]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.
[22704]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
[22706]88
[22720]89  # Add autoconf goo if it's an Athena source directory.
90  case $pkgpath in
91  athena/*)
[24567]92    if [ -e "$dir/configure.in" ]; then
[24437]93        (cd $dir && $basedir/daconfiscate)
94    fi
[22720]95    ;;
96  esac
97
[23407]98  # Generate debian/control from debian/control.in if control.in exists
[23446]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!"
[23290]101
[25498]102  # Read in debian-versions
103  . $basedir/debian-versions.sh
104
[25512]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)
[25498]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
[22786]126  # Create a suitable orig tarball if necessary.
[23440]127  (cd $dir && $basedir/daorig)
[22706]128
129  # Build an unsigned package, ignoring version control subdirs in the source.
[22704]130  echo "Creating source package"
[22766]131  (cd $dir && debuild -S -i -I.svn -sa -us -uc)
[24886]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
[22704]140}
141
[24375]142packages=packages
143
144if [ ! -r "$packages" ]; then
145    packages=/mit/debathena/packages/packages
146fi
147if [ ! -r "$packages" ]; then
[22745]148  die "Can't read packages file; create with gen-packages"
149fi
150
[22704]151if [ $# -gt 0 ]; then
152  # Build specific source packages.
153  for pkgname; do
[24424]154    pkgname="${pkgname%/}"
[24375]155    pkgpath=$(sed -nre "s/^$pkgname[[:space:]]+//p" "$packages")
[24717]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
[22704]166    do_package $pkgname $pkgpath
167  done
168else
169  # Build all source packages.
[24375]170  exec <"$packages"
[22704]171  while read pkgname pkgpath; do
172    do_package $pkgname $pkgpath
173  done
174fi
[25513]175# Unset trap
176trap - EXIT
Note: See TracBrowser for help on using the repository browser.