chiark / gitweb /
devscripts (2.10.69+squeeze4) stable-security; urgency=high
[devscripts.git] / scripts / cvs-debrelease.sh
1 #! /bin/bash -e
2
3 # cvs-debrelease: Call dupload/dput to upload package built with
4 #                 cvs-buildpackage or cvs-debuild
5 #
6 # Based on debrelease; see it for copyright information
7 # Based on cvs-buildpackage, copyright 1997 Manoj Srivastava
8 # (CVS Id: cvs-buildpackage,v 1.58 2003/08/22 17:24:29 srivasta Exp)
9 # This code is copyright 2003, Julian Gilbey <jdg@debian.org>
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23
24 PROGNAME=`basename $0 .sh`  # .sh for debugging purposes
25
26 usage () {
27     echo \
28 "Usage: $PROGNAME [cvs-debrelease options] [--dopts [dupload/dput options]]
29   Upload the .changes file(s) just created by cvs-buildpackage or
30   cvs-debuild, as listed in the .changes file generated on that run.
31
32   Note that unlike cvs-buildpackage, the only way to specify the
33   source package name is with the -P option; you cannot simply have it
34   as the last parameter.
35
36   Also uses the cvs-buildpackage configuration files to determine the
37   location of the build tree, as described in its manpage.
38
39   Available cvs-debrelease options:
40     -M<module>        CVS module name
41     -P<package>       Package name
42     -V<version>       Package version
43     -T<tag>           CVS tag to use
44     -R<root dir>      Root directory
45     -W<work dir>      Working directory
46     -x<prefix>        CVS default module prefix
47     -a<arch>          Search for .changes file made for Debian build <arch>
48     -t<target>        Search for .changes file made for GNU <target> arch
49     --dupload         Use dupload to upload files (default)
50     --dput            Use dput to upload files
51     --no-conf, --noconf
52                       Don't read devscripts config files;
53                       must be the first option given
54     --dopts           The remaining options are for dupload/dput
55     --help            Show this message
56     --version         Show version and copyright information
57   Other cvs-buildpackage options will be silently ignored.
58
59 Default settings modified by devscripts configuration files:
60   (no configuration files are read by $PROGNAME)
61 For information on default debrelease settings modified by the
62 configuration files, run:  debrelease --help"
63 }
64
65
66 version () { echo \
67 "This is $PROGNAME, from the Debian devscripts package, version ###VERSION###
68 This code is copyright 2003, Julian Gilbey <jdg@debian.org>,
69 all rights reserved.
70 Based on original code by Christoph Lameter and Manoj Srivastava.
71 This program comes with ABSOLUTELY NO WARRANTY.
72 You are free to redistribute this code under the terms of
73 the GNU General Public License, version 2 or later."
74 }
75
76 setq() {
77     # Variable Value Doc string
78     if [ "x$2" = "x" ]; then
79         echo >&2 "$progname: Unable to determine $3"
80         exit 1;
81     else
82         if [ ! "x$Verbose" = "x" ]; then
83             echo "$progname: $3 is $2";
84         fi
85         eval "$1=\"\$2\"";
86     fi
87 }
88
89 # Is cvs-buildpackage installed?
90 if ! command -v cvs-buildpackage >/dev/null 2>&1; then
91     echo "$PROGNAME: need the cvs-buildpackage package installed to run this" >&2
92     exit 1
93 fi
94
95 # Long term variables, which may be set in the cvsdeb config file or the
96 # environment: 
97 # rootdir workdir (if all original sources are kept in one dir)
98
99 TEMPDIR=$(mktemp -dt cvs-debrelease.XXXXXXXX) || {
100     echo "$PROGNAME: Unable to create temporary directory" >&2
101     echo "Aborting...." >&2
102     exit 1
103 }
104 TEMPFILE=$TEMPDIR/cl-tmp
105 trap "rm -f $TEMPFILE; rmdir $TEMPDIR" 0 1 2 3 7 10 13 15
106
107 TAGOPT=
108
109 # Command line
110 # Start by pulling off all options up to --dopts
111 declare -a cvsopts debreleaseopts
112 if [ "$1" = --no-conf -o "$1" = --noconf ]; then
113     debreleaseopts=("$1")
114     shift
115 fi
116
117 debreleaseopts=("${debreleaseopts[@]}" "--check-dirname-level=0")
118
119 while [ $# -gt 0 ]; do
120     if [ "$1" = "--dopts" ]; then
121         shift
122         break
123     fi
124     cvsopts=("${cvsopts[@]}" "$1")
125     shift
126 done
127
128 # This will bomb out if there is an unrecognised option
129 TEMP=$(getopt -a -s bash \
130        -o hC:EH:G:M:P:R:T:U:V:W:Ff:dcnr:x:Bp:Dk:a:Sv:m:e:i:I:t: \
131        --long help,version,ctp,tC,sgpg,spgp,us,uc,op \
132        --long si,sa,sd,ap,sp,su,sk,sr,sA,sP,sU,sK,sR,ss,sn \
133        --long dupload,dput,no-conf,noconf \
134        --long check-dirname-level:,check-dirname-regex: \
135        -n "$PROGNAME" -- "${cvsopts[@]}")
136
137 eval set -- $TEMP
138
139 while true ; do
140     case "$1" in
141         -h|--help)   usage;   exit 0  ; shift   ;;
142         --version)   version; exit 0  ; shift   ;;
143         -M) opt_cvsmodule="$2"        ; shift 2 ;;
144         -P) opt_package="$2"          ; shift 2 ;;
145         -R) opt_rootdir="$2"          ; shift 2 ;;
146         -T) opt_tag="$2"              ; shift 2 ;;
147         -V) opt_version="$2"          ; shift 2 ;;
148         -W) opt_workdir="$2"          ; shift 2 ;;
149         -x) opt_prefix="$2"           ; shift 2 ;;
150         -a) debreleaseopts=("${debreleaseopts[@]}" "$1" "$2")
151             targetarch="$2"           ; shift 2 ;;
152         -t) if [ "$2" != "C" ]; then
153                 debreleaseopts=("${debreleaseopts[@]}" "$1" "$2")
154                 targetgnusystem="$2"
155             fi
156             shift 2 ;;
157         --dupload|--dput)
158             debreleaseopts=("${debreleaseopts[@]}" "$1");  shift ;;
159         --no-conf|--noconf)
160             echo "$PROGNAME: $1 is only acceptable as the first command-line option!" >&2
161             exit 1 ;;
162         --check-dirname-level|--check-dirname-regex)
163             debreleaseopts=("${debreleaseopts[@]}" "$1" "$2");  shift 2 ;;
164
165         # everything else is silently ignored
166         -[CHfGUr])                      shift 2 ;;
167         -[FnE])                         shift   ;;
168        --ctp|--op|--tC)                 shift   ;;
169         -[dDBbS])                       shift   ;;
170         -p)                             shift 2 ;;
171        --us|--uc|--sgpg|--spgp)         shift   ;;
172        --s[idapukrAPUKRns])             shift   ;;
173        --ap)                            shift   ;;
174         -[kvmeiI])                      shift 2 ;;
175
176         --) shift ; break ;;
177          *) echo >&2 "Internal error! ($1)"
178             usage; exit 1 ;;
179     esac
180 done
181
182 if [ "x$opt_cvsmodule" = "x" -a "x$opt_package" = "x" -a \
183       ! -e 'debian/changelog' ] ; then
184     echo >&2 "$progname should be run in the top working directory of"
185     echo >&2 "a Debian Package, or an explicit package (or CVS module) name"
186     echo >&2 "should be given." 
187     exit 1
188 fi
189
190 if [ "x$opt_tag" != "x" ]; then
191     TAGOPT=-r$opt_tag
192 fi
193
194 # Command line, env variable, config file, or default
195 # This anomalous position is in case we need to check out the changelog
196 # below (anaomalous since we ahve not loaded the config file yet)
197 if [ ! "x$opt_prefix" = "x" ]; then
198     prefix="$opt_prefix"
199 elif [ ! "x$CVSDEB_PREFIX" = "x" ]; then
200     prefix="$CVSDEB_PREFIX"
201 elif [ ! "x$conf_prefix" = "x" ]; then
202     prefix="$conf_prefix"
203 else
204     prefix=""
205 fi
206
207 # put a slash at the end of the prefix
208 if [ "X$prefix" != "X" ]; then
209     prefix="$prefix/";
210     prefix=`echo $prefix | sed 's://:/:g'`;
211 fi
212
213 if [ ! -f CVS/Root ]; then
214     if [ "X$CVSROOT" = "X" ]; then
215         echo "no CVS/Root file found, and CVSROOT var is empty" >&2
216         exit 1
217     fi
218 else
219     CVSROOT=$(cat CVS/Root)
220     export CVSROOT
221 fi
222
223 if [ "x$opt_package" = "x" ]; then
224     # Get the official package name and version.
225     if [ -f debian/changelog ]; then
226         # Ok, changelog exists
227          setq "package" \
228             "`dpkg-parsechangelog | sed -n 's/^Source: //p'`" \
229                 "source package"
230         setq "version" \
231             "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" \
232                 "source version"
233     elif [ "x$opt_cvsmodule" != "x" ]; then
234         # Hmm. Well, see if we can checkout the changelog file
235         rm -f $TEMPFILE
236         cvs -q co -p $TAGOPT $opt_cvsmodule/debian/changelog > $TEMPFILE
237         setq "package" \
238             "`dpkg-parsechangelog -l$TEMPFILE | sed -n 's/^Source: //p'`" \
239           "source package"
240         setq "version" \
241           "`dpkg-parsechangelog -l$TEMPFILE | sed -n 's/^Version: //p'`" \
242           "source version"
243         rm -f "$TEMPFILE"
244     else
245         # Well. We don't know what this package is.
246         echo >&2 " This does not appear be a Debian source tree, since"
247         echo >&2 " theres is no debian/changelog, and there was no"
248         echo >&2 " package name or cvs module given on the comand line"
249         echo >&2 " it is hard to figure out what the package name "
250         echo >&2 " should be. I give up."
251         exit 1
252     fi
253 else
254     # The user knows best; package name is provided
255     setq "package" "$opt_package" "source package"
256
257     # Now, the version number
258     if [ "x$opt_version" != "x" ]; then
259         # All hail the user provided value
260         setq "version" "$opt_version" "source package"
261     elif [ -f debian/changelog ]; then
262         # Fine, see what the changelog says
263         setq "version" \
264             "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" \
265                 "source version"
266     elif [ "x$opt_cvsmodule" != "x" ]; then
267         # Hmm. The CVS module name is known, so lets us try exporting changelog
268         rm -f $TEMPFILE
269         cvs -q co -p $TAGOPT $opt_cvsmodule/debian/changelog > $TEMPFILE
270         setq "version" \
271           "`dpkg-parsechangelog -l$TEMPFILE | sed -n 's/^Version: //p'`" \
272           "source version"
273         rm -f "$TEMPFILE"
274     else
275         # Ok, try exporting the package name
276         rm -f $TEMPFILE
277         cvsmodule="${prefix}$package"
278         cvs -q co -p $TAGOPT $cvsmodule/debian/changelog > $TEMPFILE
279         setq "version" \
280           "`dpkg-parsechangelog -l$TEMPFILE | sed -n 's/^Version: //p'`" \
281           "source version"
282         rm -f "$TEMPFILE"
283     fi
284 fi
285
286 rm -f $TEMPFILE
287 rmdir $TEMPDIR
288 trap "" 0 1 2 3 7 10 13 15
289
290
291 non_epoch_version=$(echo -n "$version" | perl -pe 's/^\d+://')
292 upstream_version=$(echo -n "$non_epoch_version" | sed  -e 's/-[^-]*$//')
293 debian_version=$(echo -n $non_epoch_version |  perl -nle 'm/-([^-]*)$/ && print $1')
294
295 # The default
296 if [ "X$opt_rootdir" != "X" ]; then
297     rootdir="$opt_rootdir"
298 else
299     rootdir='/usr/local/src/Packages'
300 fi
301
302 if [ "X$opt_workdir" != "X" ]; then
303     workdir="$opt_workdir"
304 else
305     workdir="$rootdir/$package"
306 fi
307
308 # Load site defaults and over rides.
309 if [ -f /etc/cvsdeb.conf ]; then
310     . /etc/cvsdeb.conf
311 fi
312
313 # Load user defaults and over rides.
314 if [ -f ~/.cvsdeb.conf ]; then
315     . ~/.cvsdeb.conf
316 fi
317
318 # Command line, env variable, config file, or default
319 if [ ! "x$opt_rootdir" = "x" ]; then
320     rootdir="$opt_rootdir"
321 elif [ ! "x$CVSDEB_ROOTDIR" = "x" ]; then
322     rootdir="$CVSDEB_ROOTDIR"
323 elif [ ! "x$conf_rootdir" = "x" ]; then
324     rootdir="$conf_rootdir"
325 fi
326
327 # Command line, env variable, config file, or default
328 if [ ! "x$opt_workdir" = "x" ]; then
329     workdir="$opt_workdir"
330 elif [ ! "x$CVSDEB_WORKDIR" = "x" ]; then
331     workdir="$CVSDEB_WORKDIR"
332 elif [ ! "x$conf_workdir" = "x" ]; then
333     workdir="$conf_workdir"
334 else
335     workdir="$rootdir/$package"
336 fi
337
338 if [ ! -d "$workdir" ]; then
339     echo >&2 "The working directory, $workdir, does not exist. Aborting"
340     if [ ! -d "$rootdir" ]; then
341         echo >&2 "The root directory, $rootdir, does not exist either."
342     fi
343     exit 1;
344 fi
345
346 pkgdir="$workdir/$package-$upstream_version"
347
348 if [ ! -d "$pkgdir" ]; then
349     echo "The build directory $pkgdir does not exist!" >&2
350     echo "Have you built the package yet?" >&2
351     exit 1
352 fi
353
354 setq arch "`dpkg-architecture -a${targetarch} -t${targetgnusystem} -qDEB_HOST_ARCH`" "build architecture"
355
356 pva="${package}_${non_epoch_version}_${arch}"
357 changes="$pva.changes"
358
359 if [ ! -f "$workdir/$changes" ]; then
360     echo "Can't find $workdir/$changes!" >&2
361     echo "Have you built the package yet?" >&2
362     exit 1
363 fi
364
365
366 cd $pkgdir || {
367     echo "Couldn't cd $pkgdir.  Aborting" >&2
368     exit 1
369 }
370
371 # Just call debrelease, now that we are in the correct directory
372
373 SUBPROG=${PROGNAME#cvs-}
374
375 exec $SUBPROG "${debreleaseopts[@]}" "$@"