dpkg-buildpackage.sh 8.6 KB

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