source: trunk/debathena/scripts/dasource @ 25498

Revision 25498, 5.1 KB checked in by jdreed, 12 years ago (diff)
Revert r25479 and r25479
  • 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
18die() {
19  echo "$@" >&2
20  exit 1
21}
22
23usage() {
24  die "dasource [-r repos] [packagename ...]"
25}
26
27basedir=$(dirname "$(readlink -f "$0")")
28repo=svn+ssh://svn.mit.edu/athena/trunk
29
30while getopts r: opt; do
31  case "$opt" in
32  r)
33    repo="$OPTARG"
34    ;;
35  \?)
36    usage
37    ;;
38  esac
39done
40shift $(($OPTIND - 1))
41
42do_package() {
43  pkgname=$1
44  pkgpath=$2
45  if [ ! -d $pkgname ]; then
46    echo "Creating directory $pkgname"
47    mkdir $pkgname
48  fi
49
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
59  # Check out or update the package source.
60  pattern="$pkgname/$pkgname-[0-9]*[0-9]"
61  if [ $(echo $pattern | wc -w) -gt 1 ]; then
62    die "More than one checkout under $pkgname!"
63  elif [ -d $pattern ]; then
64    dir=$(echo $pattern)
65    echo "Updating and cleaning $dir"
66    (cd $dir && svn update && svn revert -R . &&
67     svn st | awk '/^?/ {print $2}' | xargs rm -vrf)
68  else
69    dir=$pkgname/$pkgname
70    echo "Checking out $repo/$pkgpath into $dir"
71    svn co $repo/$pkgpath $dir
72  fi
73
74  # Extract the changelog version and strip off the epoch and Debian component.
75  changever=$(cd $dir && dpkg-parsechangelog | sed -n 's/Version: //p')
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.
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
86
87  # Add autoconf goo if it's an Athena source directory.
88  case $pkgpath in
89  athena/*)
90    if [ -e "$dir/configure.in" ]; then
91        (cd $dir && $basedir/daconfiscate)
92    fi
93    ;;
94  esac
95
96  # Generate debian/control from debian/control.in if control.in exists
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!"
99
100  # Read in debian-versions
101  . $basedir/debian-versions.sh
102
103  NOBUILD=$(grep-dctrl -n -s Debathena-No-Build -F Debathena-No-Build -e . "$dir/debian/control")
104  BUILDFOR=$(grep-dctrl -n -s Debathena-Build-For -F Debathena-Build-For -e . "$dir/debian/control")
105  if [ -n "$NOBUILD" ] && [ -n "$BUILDFOR" ]; then
106      echo "It is an error to specify both X-Debathena-Build-For and"
107      echo "X-Debathena-No-Build.  Pick one and try again."
108      die
109  elif [ -z "$NOBUILD" ] && [ -z "$BUILDFOR" ]; then
110      [ -f "$pkgname/nobuild" ] && echo "NOTE: Please migrate legacy ./nobuild to X-Debathena-No-Build!"
111  else
112      [ -f "$pkgname/nobuild" ] && rm "$pkgname/nobuild"
113      if [ -n "$BUILDFOR" ]; then
114          NOBUILD=
115          for code in $DEBIAN_CODES; do
116              if ! echo "$BUILDFOR" | fgrep -q "$code"; then
117                  NOBUILD="$NOBUILD $code"
118              fi
119          done
120      fi
121      echo "$NOBUILD" > "$pkgname/nobuild"
122  fi
123
124  # Create a suitable orig tarball if necessary.
125  (cd $dir && $basedir/daorig)
126
127  # Build an unsigned package, ignoring version control subdirs in the source.
128  echo "Creating source package"
129  (cd $dir && debuild -S -i -I.svn -sa -us -uc)
130
131  if grep '^Architecture: ' $dir/debian/control | grep -q -v 'Architecture: all'; then
132    echo "At least one arch-dependent binary package; run sbuildhack WITHOUT -A." >&2
133  elif grep -q '^Architecture: ' $dir/debian/control; then
134    echo "No arch-dependent binary packages; run sbuildhack with -A." >&2
135  else
136    echo "No binary packages???" >&2
137  fi
138}
139
140packages=packages
141
142if [ ! -r "$packages" ]; then
143    packages=/mit/debathena/packages/packages
144fi
145if [ ! -r "$packages" ]; then
146  die "Can't read packages file; create with gen-packages"
147fi
148
149if [ $# -gt 0 ]; then
150  # Build specific source packages.
151  for pkgname; do
152    pkgname="${pkgname%/}"
153    pkgpath=$(sed -nre "s/^$pkgname[[:space:]]+//p" "$packages")
154    if ! [ -n "$pkgpath" ]; then
155        echo "Can't find package $pkgname" >&2
156        echo >&2
157        echo "This may be because the list of packages is not up to date. If" >&2
158        echo "this is a new package, and you have the bits, run gen-packages" >&2
159        echo "with /mit/debathena/packages as your working directory." >&2
160        echo "Otherwise, run gen-packages in this directory and dasource will" >&2
161        echo "use the generated file instead." >&2
162        die
163    fi
164    do_package $pkgname $pkgpath
165  done
166else
167  # Build all source packages.
168  exec <"$packages"
169  while read pkgname pkgpath; do
170    do_package $pkgname $pkgpath
171  done
172fi
Note: See TracBrowser for help on using the repository browser.