chiark / gitweb /
devscripts (2.10.69+squeeze4) stable-security; urgency=high
[devscripts.git] / scripts / dpkg-buildpackage-snapshot
1 #!/bin/sh
2
3 set -e
4
5 version="1.13.17"; # This line modified by Makefile
6
7 progname="`basename \"$0\"`"
8 usageversion () {
9         cat >&2 <<END
10 Debian dpkg-buildpackage $version.  
11 Copyright (C) 1996 Ian Jackson.
12 Copyright (C) 2000 Wichert Akkerman
13 This is free software; see the GNU General Public Licence version 2
14 or later for copying conditions.  There is NO warranty.
15
16 Usage: dpkg-buildpackage [options]
17 Options: -r<gain-root-command>
18          -p<sign-command>
19          -d            do not check build dependencies and conflicts
20          -D            check build dependencies and conflicts
21          -k<keyid>     the key to use for signing
22          -sgpg         the sign-command is called like GPG
23          -spgp         the sign-command is called like PGP 
24          -us           unsigned source
25          -uc           unsigned changes
26          -a<arch>      Debian architecture we build for (implies -d)
27          -b            binary-only, do not build source } also passed to
28          -B            binary-only, no arch-indep files } dpkg-genchanges
29          -S            source only, no binary files     } 
30          -t<system>    set GNU system type  } passed to dpkg-architecture
31          -v<version>   changes since version <version>      }
32          -m<maint>     maintainer for package is <maint>    } 
33          -e<maint>     maintainer for release is <maint>    } only passed
34          -C<descfile>  changes are described in <descfile>  }  to dpkg-
35          -si (default) src includes orig for rev. 0 or 1    } genchanges
36          -sa           uploaded src always includes orig    }
37          -sd           uploaded src is diff and .dsc only   }
38          -nc           do not clean source tree (implies -b)
39          -tc           clean source tree when finished
40          -ap           add pause before starting signature process
41          -h            print this message
42          -W            Turn certain errors into warnings.      } passed to
43          -E            When -W is turned on, -E turned it off. } dpkg-source
44          -i[<regex>]   ignore diffs of files matching regex    } only passed
45          -I<filename>  filter out files when building tarballs } to dpkg-source
46 END
47 }
48
49 rootcommand=''
50 signcommand=""
51 if (( [ -n "$GNUPGHOME" ] && [ -e "$GNUPGHOME" ] ) || [ -e "$HOME/.gnupg" ] ) && \
52                 command -v gpg > /dev/null 2>&1; then
53         signcommand=gpg
54 elif command -v pgp > /dev/null 2>&1 ; then
55         signcommand=pgp
56 fi
57
58 signsource='withecho signfile'
59 signchanges='withecho signfile'
60 cleansource=false
61 checkbuilddep=true
62 checkbuilddep_args=''
63 binarytarget=binary
64 sourcestyle=''
65 version=''
66 since=''
67 maint=''
68 desc=''
69 noclean=false
70 usepause=false
71 warnable_error=0
72 passopts=''
73
74 while [ $# != 0 ]
75 do
76         value="`echo x\"$1\" | sed -e 's/^x-.//'`"
77         case "$1" in
78         -h)     usageversion; exit 0 ;;
79         -r*)    rootcommand="$value" ;;
80         -p*)    signcommand="$value" ;;
81         -k*)    signkey="$value" ;;
82         -d)     checkbuilddep=false ;;
83         -D)     checkbuilddep=true ;;
84         -sgpg)  forcesigninterface=gpg ;;
85         -spgp)  forcesigninterface=pgp ;;
86         -us)    signsource=: ;;
87         -uc)    signchanges=: ;;
88         -ap)    usepause="true";;
89         -a*)    targetarch="$value"; checkbuilddep=false ;;
90         -si)    sourcestyle=-si ;;
91         -sa)    sourcestyle=-sa ;;
92         -sd)    sourcestyle=-sd ;;
93         -i*)    diffignore=$1;;
94         -I*)    tarignore="$tarignore $1";;
95         -tc)    cleansource=true ;;
96         -t*)    targetgnusystem="$value" ;;          # Order DOES matter!
97         -nc)    noclean=true; if [ -z "$binaryonly" ]; then binaryonly=-b; fi ;;
98         -b)     binaryonly=-b; [ "$sourceonly" ] && \
99                         { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
100         -B)     binaryonly=-B; checkbuilddep_args=-B; binarytarget=binary-arch; [ "$sourceonly" ] && \
101                         { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
102         -S)     sourceonly=-S; checkbuilddep=false; [ "$binaryonly" ] && \
103                         { echo >&2 "$progname: cannot combine $binaryonly and $1" ; exit 2 ; } ;;
104         -v*)    since="$value" ;;
105         -m*)    maint="$value" ;;
106         -e*)    changedby="$value" ;;
107         -C*)    desc="$value" ;;
108         -W)     warnable_error=1; passopts="$passopts -W";;
109         -E)     warnable_error=0; passopts="$passopts -E";;     
110         *)      echo >&2 "$progname: unknown option or argument $1"
111                 usageversion; exit 2 ;;
112         esac
113         shift
114 done
115
116 if [ -z "$signcommand"  ] ; then
117         signsource=:
118         signchanges=:
119 fi
120
121 if test -n "$forcesigninterface" ; then
122   signinterface=$forcesigninterface
123 if [ "$signinterface" != "gpg" ] && [ "$signinterface" != "pgp" ] ; then
124         echo >&2 "$progname: invalid sign interface specified"
125         exit 1
126 fi
127 else
128   signinterface=$signcommand
129 fi
130
131
132 mustsetvar () {
133         if [ "x$2" = x ]; then
134                 echo >&2 "$progname: unable to determine $3" ; \
135                 exit 1
136         else
137                 echo "$progname: $3 $2" ; \
138                 eval "$1=\"\$2\""
139         fi
140 }
141
142 curd="`pwd`"
143 dirn="`basename \"$curd\"`"
144 mustsetvar package "`dpkg-parsechangelog | sed -n 's/^Source: //p'`" "source package is"
145 mustsetvar version "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" "source version is"
146 if [ -n "$changedby" ]; then maintainer="$changedby";
147 elif [ -n "$maint" ]; then maintainer="$maint";
148 else mustsetvar maintainer "`dpkg-parsechangelog | sed -n 's/^Maintainer: //p'`" "source changed by"; fi
149 eval `dpkg-architecture -a${targetarch} -t${targetgnusystem} -s -f`
150
151 if [ x$sourceonly = x ]; then
152         mustsetvar arch "`dpkg-architecture -a${targetarch} -t${targetgnusystem} -qDEB_HOST_ARCH`" "host architecture"
153 else
154         arch=source
155 fi
156 sversion=`echo "$version" | perl -pe 's/^\d+://'`
157 pv="${package}_${sversion}"
158 pva="${package}_${sversion}_${arch}"
159
160 signfile () {
161         if test "$signinterface" = "gpg" ; then
162                 (cat "../$1" ; echo "") | \
163                 $signcommand --local-user "${signkey:-$maintainer}" --clearsign --armor \
164                         --textmode  > "../$1.asc" 
165         else
166                 $signcommand -u "${signkey:-$maintainer}" +clearsig=on -fast <"../$1" \
167                         >"../$1.asc"
168         fi
169         status=$?
170         if [ $status -eq 0 ]; then
171                 mv -- "../$1.asc" "../$1"
172         else
173                 /bin/rm -f "../$1.asc"
174         fi
175         echo
176         return $status
177 }
178
179 withecho () {
180         echo " $@" >&2
181         "$@"
182 }
183
184 if [ "$checkbuilddep" = "true" ]; then
185         if ! dpkg-checkbuilddeps $checkbuilddep_args; then
186                 echo >&2 "$progname: Build dependencies/conflicts unsatisfied; aborting."
187                 echo >&2 "$progname: (Use -d flag to override.)"
188                 exit 3
189         fi
190 fi
191
192 set -- $binaryonly $sourceonly $sourcestyle
193 if [ -n "$maint"        ]; then set -- "$@" "-m$maint"          ; fi
194 if [ -n "$changedby"    ]; then set -- "$@" "-e$changedby"      ; fi
195 if [ -n "$since"        ]; then set -- "$@" "-v$since"          ; fi
196 if [ -n "$desc"         ]; then set -- "$@" "-C$desc"           ; fi
197
198 if [ x$noclean != xtrue ]; then
199         withecho $rootcommand debian/rules clean
200 fi
201 if [ x$binaryonly = x ]; then
202         cd ..; withecho dpkg-source $passopts $diffignore $tarignore -b "$dirn"; cd "$dirn"
203 fi
204 if [ x$sourceonly = x ]; then
205         withecho debian/rules build 
206         withecho $rootcommand debian/rules $binarytarget
207 fi
208 if [ "$usepause" = "true" ] && \
209    ( [ "$signchanges" != ":" ] || ( [ -z "$binaryonly" ] && [ "$signsource" != ":" ] ) ) ; then
210     echo Press the return key to start signing process
211     read dummy_stuff
212 fi
213
214 signerrors=
215 if [ x$binaryonly = x ]; then
216         if ! $signsource "$pv.dsc"; then
217                 signerrors="(WARNING: Failed to sign .dsc and .changes file)"
218                 signchanges=:
219         fi
220 fi
221 chg=../"$pva.changes"
222 withecho dpkg-genchanges "$@" >"$chg"
223
224 fileomitted () {
225         set +e
226         test -z "`sed -n '/^Files:/,/^[^ ]/ s/'$1'$//p' <$chg`"
227         fir=$?
228         set -e
229         return $fir
230 }       
231
232
233 if fileomitted '\.deb'; then
234         # source only upload
235         if fileomitted '\.diff\.gz'; then
236                 srcmsg='source only upload: Debian-native package'
237         elif fileomitted '\.orig\.tar\.gz'; then
238                 srcmsg='source only, diff-only upload (original source NOT included)'
239         else
240                 srcmsg='source only upload (original source is included)'
241         fi
242 else
243         srcmsg='full upload (original source is included)'
244         if fileomitted '\.dsc'; then
245                 srcmsg='binary only upload (no source included)'
246         elif fileomitted '\.diff\.gz'; then
247                 srcmsg='full upload; Debian-native package (full source is included)'
248         elif fileomitted '\.orig\.tar\.gz'; then
249                 srcmsg='binary and diff upload (original source NOT included)'
250         else
251                 srcmsg='full upload (original source is included)'
252         fi
253 fi
254
255 if ! $signchanges "$pva.changes"; then
256         signerrors="(WARNING: Failed to sign .changes file)"
257 fi
258
259 if $cleansource; then
260         withecho $rootcommand debian/rules clean
261 fi
262
263 echo "dpkg-buildpackage: $srcmsg"
264 if [ -n "$signerrors" ]; then
265         echo >&2 $signerrors
266         exit 1
267 fi