source: trunk/debathena/scripts/dasource @ 25578

Revision 25578, 5.4 KB checked in by jdreed, 12 years ago (diff)
Don't build UNRELEASED packages
  • Property svn:executable set to *
Line 
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
16set -e
17
18trap 'echo "dasource failed: Source package _not_ created"' EXIT
19
20die() {
21  echo "$@" >&2
22  exit 1
23}
24
25usage() {
26  die "dasource [-r repos] [packagename ...]"
27}
28
29basedir=$(dirname "$(readlink -f "$0")")
30repo=svn+ssh://svn.mit.edu/athena/trunk
31
32while getopts r: opt; do
33  case "$opt" in
34  r)
35    repo="$OPTARG"
36    ;;
37  \?)
38    usage
39    ;;
40  esac
41done
42shift $(($OPTIND - 1))
43
44do_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  # 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
83  # Extract the changelog version and strip off the epoch and Debian component.
84  changever=$(cd $dir && dpkg-parsechangelog | sed -n 's/Version: //p')
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.
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
95
96  # Add autoconf goo if it's an Athena source directory.
97  case $pkgpath in
98  athena/*)
99    if [ -e "$dir/configure.in" ]; then
100        (cd $dir && $basedir/daconfiscate)
101    fi
102    ;;
103  esac
104
105  # Generate debian/control from debian/control.in if control.in exists
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!"
108
109  # Read in debian-versions
110  . $basedir/debian-versions.sh
111
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)
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
133  # Create a suitable orig tarball if necessary.
134  (cd $dir && $basedir/daorig)
135
136  # Build an unsigned package, ignoring version control subdirs in the source.
137  echo "Creating source package"
138  (cd $dir && debuild -S -i -I.svn -sa -us -uc)
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
147}
148
149packages=packages
150
151if [ ! -r "$packages" ]; then
152    packages=/mit/debathena/packages/packages
153fi
154if [ ! -r "$packages" ]; then
155  die "Can't read packages file; create with gen-packages"
156fi
157
158if [ $# -gt 0 ]; then
159  # Build specific source packages.
160  for pkgname; do
161    pkgname="${pkgname%/}"
162    pkgpath=$(sed -nre "s/^$pkgname[[:space:]]+//p" "$packages")
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
173    do_package $pkgname $pkgpath
174  done
175else
176  # Build all source packages.
177  exec <"$packages"
178  while read pkgname pkgpath; do
179    do_package $pkgname $pkgpath
180  done
181fi
182# Unset trap
183trap - EXIT
Note: See TracBrowser for help on using the repository browser.