source: trunk/debathena/scripts/dasource @ 25850

Revision 25850, 5.6 KB checked in by jdreed, 9 years ago (diff)
Whine loudly when we encounter a CDBS package (Trac: #1312)
  • 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: ${DA_SCRIPTS_DIR="$(dirname "$(readlink -f "$0")")"}
29basedir="$DA_SCRIPTS_DIR"
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" ] && echo "NOTE: Obsolete CDBS package -- convert to DH7!"
107  ([ -f "$dir/debian/control.in" ] && cd $dir && DEB_AUTO_UPDATE_DEBIAN_CONTROL=yes debian/rules debian/control || :)
108  [ -f "$dir/debian/control" ] || die "Can't find or generate debian/control!"
109
110  # Read in debian-versions
111  . $basedir/debian-versions.sh
112
113  NOBUILD=$(grep-dctrl -n -s X-Debathena-No-Build -F X-Debathena-No-Build -e . "$dir/debian/control" || true)
114  BUILDFOR=$(grep-dctrl -n -s X-Debathena-Build-For -F X-Debathena-Build-For -e . "$dir/debian/control" || true)
115  if [ -n "$NOBUILD" ] && [ -n "$BUILDFOR" ]; then
116      echo "It is an error to specify both X-Debathena-Build-For and"
117      echo "X-Debathena-No-Build.  Pick one and try again."
118      die
119  elif [ -z "$NOBUILD" ] && [ -z "$BUILDFOR" ]; then
120      [ -f "$pkgname/nobuild" ] && echo "NOTE: Please migrate legacy ./nobuild to X-Debathena-No-Build!"
121  else
122      [ -f "$pkgname/nobuild" ] && rm "$pkgname/nobuild"
123      if [ -n "$BUILDFOR" ]; then
124          NOBUILD=
125          for code in $DEBIAN_CODES; do
126              if ! echo "$BUILDFOR" | fgrep -q "$code"; then
127                  NOBUILD="$NOBUILD $code"
128              fi
129          done
130      fi
131      echo "$NOBUILD" > "$pkgname/nobuild"
132  fi
133
134  # Create a suitable orig tarball if necessary.
135  (cd $dir && $basedir/daorig)
136
137  # Build an unsigned package, ignoring version control subdirs in the source.
138  echo "Creating source package"
139  (cd $dir && debuild -S -i -I.svn -sa -us -uc)
140
141  if grep '^Architecture: ' $dir/debian/control | grep -q -v 'Architecture: all'; then
142    echo "At least one arch-dependent binary package; run sbuildhack WITHOUT -A." >&2
143  elif grep -q '^Architecture: ' $dir/debian/control; then
144    echo "No arch-dependent binary packages; run sbuildhack with -A." >&2
145  else
146    echo "No binary packages???" >&2
147  fi
148}
149
150packages=packages
151
152if [ ! -r "$packages" ]; then
153    packages=/mit/debathena/packages/packages
154fi
155if [ ! -r "$packages" ]; then
156  die "Can't read packages file; create with gen-packages"
157fi
158
159if [ $# -gt 0 ]; then
160  # Build specific source packages.
161  for pkgname; do
162    pkgname="${pkgname%/}"
163    pkgpath=$(sed -nre "s/^$pkgname[[:space:]]+//p" "$packages")
164    if ! [ -n "$pkgpath" ]; then
165        echo "Can't find package $pkgname" >&2
166        echo >&2
167        echo "This may be because the list of packages is not up to date. If" >&2
168        echo "this is a new package, and you have the bits, run gen-packages" >&2
169        echo "with /mit/debathena/packages as your working directory." >&2
170        echo "Otherwise, run gen-packages in this directory and dasource will" >&2
171        echo "use the generated file instead." >&2
172        die
173    fi
174    do_package $pkgname $pkgpath
175  done
176else
177  # Build all source packages.
178  exec <"$packages"
179  while read pkgname pkgpath; do
180    do_package $pkgname $pkgpath
181  done
182fi
183# Unset trap
184trap - EXIT
Note: See TracBrowser for help on using the repository browser.