dpkg-buildpackage.sh 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. -h, --help show this help message.
  48. --version show the version.
  49. END
  50. }
  51. rootcommand=''
  52. signcommand=""
  53. if (( [ -n "$GNUPGHOME" ] && [ -e "$GNUPGHOME" ] ) || [ -e "$HOME/.gnupg" ] ) && \
  54. command -v gpg > /dev/null 2>&1; then
  55. signcommand=gpg
  56. elif command -v pgp > /dev/null 2>&1 ; then
  57. signcommand=pgp
  58. fi
  59. signsource='withecho signfile'
  60. signchanges='withecho signfile'
  61. cleansource=false
  62. checkbuilddep=true
  63. checkbuilddep_args=''
  64. binarytarget=binary
  65. sourcestyle=''
  66. changesversion=''
  67. since=''
  68. maint=''
  69. desc=''
  70. noclean=false
  71. usepause=false
  72. warnable_error=0
  73. passopts=''
  74. while [ $# != 0 ]
  75. do
  76. value="`echo x\"$1\" | sed -e 's/^x-.//'`"
  77. case "$1" in
  78. -h|--help)
  79. usage; exit 0 ;;
  80. --version)
  81. showversion; exit 0 ;;
  82. -r*) rootcommand="$value" ;;
  83. -p*) signcommand="$value" ;;
  84. -k*) signkey="$value" ;;
  85. -d) checkbuilddep=false ;;
  86. -D) checkbuilddep=true ;;
  87. -sgpg) forcesigninterface=gpg ;;
  88. -spgp) forcesigninterface=pgp ;;
  89. -us) signsource=: ;;
  90. -uc) signchanges=: ;;
  91. -ap) usepause="true";;
  92. -a*) targetarch="$value"; checkbuilddep=false ;;
  93. -si) sourcestyle=-si ;;
  94. -sa) sourcestyle=-sa ;;
  95. -sd) sourcestyle=-sd ;;
  96. -s[nsAkurKUR]) passopts="$passopts $1";; # passed to dpkg-source
  97. -i*) diffignore=$1;;
  98. -I*) tarignore="$tarignore $1";;
  99. -tc) cleansource=true ;;
  100. -t*) targetgnusystem="$value" ;; # Order DOES matter!
  101. -nc) noclean=true; if [ -z "$binaryonly" ]; then binaryonly=-b; fi ;;
  102. -b) binaryonly=-b;
  103. checkbuilddep_args='';
  104. binarytarget=binary;
  105. [ "$sourceonly" ] && \
  106. { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
  107. -B) binaryonly=-B; checkbuilddep_args=-B; binarytarget=binary-arch; [ "$sourceonly" ] && \
  108. { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
  109. -S) sourceonly=-S; checkbuilddep=false; [ "$binaryonly" ] && \
  110. { echo >&2 "$progname: cannot combine $binaryonly and $1" ; exit 2 ; } ;;
  111. -v*) since="$value" ;;
  112. -m*) maint="$value" ;;
  113. -e*) changedby="$value" ;;
  114. -C*) desc="$value" ;;
  115. -W) warnable_error=1; passopts="$passopts -W";;
  116. -E) warnable_error=0; passopts="$passopts -E";;
  117. *) echo >&2 "$progname: unknown option or argument $1"
  118. usage; exit 2 ;;
  119. esac
  120. shift
  121. done
  122. if [ -z "$signcommand" ] ; then
  123. signsource=:
  124. signchanges=:
  125. fi
  126. if test -n "$forcesigninterface" ; then
  127. signinterface=$forcesigninterface
  128. else
  129. signinterface=$signcommand
  130. fi
  131. if [ -n "$signcommand" ] && [ "$signinterface" != "gpg" ] && [ "$signinterface" != "pgp" ] ; then
  132. echo >&2 "$progname: unknown sign command, assuming pgp style interface"
  133. fi
  134. mustsetvar () {
  135. if [ "x$2" = x ]; then
  136. echo >&2 "$progname: unable to determine $3" ; \
  137. exit 1
  138. else
  139. echo "$progname: $3 $2" ; \
  140. eval "$1=\"\$2\""
  141. fi
  142. }
  143. curd="`pwd`"
  144. dirn="`basename \"$curd\"`"
  145. mustsetvar package "`dpkg-parsechangelog | sed -n 's/^Source: //p'`" "source package is"
  146. mustsetvar changesversion "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" "source version is"
  147. if [ -n "$changedby" ]; then maintainer="$changedby";
  148. elif [ -n "$maint" ]; then maintainer="$maint";
  149. else mustsetvar maintainer "`dpkg-parsechangelog | sed -n 's/^Maintainer: //p'`" "source changed by"; fi
  150. eval `dpkg-architecture -a${targetarch} -t${targetgnusystem} -s -f`
  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. mustsetvar sversion "`echo \"$changesversion\" | perl -pe 's/^\d+://'`" "source version without epoch"
  157. pv="${package}_${sversion}"
  158. pva="${package}_${sversion}_${arch}"
  159. signfile () {
  160. if test "$signinterface" = "gpg" ; then
  161. (cat "../$1" ; echo "") | \
  162. $signcommand --local-user "${signkey:-$maintainer}" --clearsign --armor \
  163. --textmode > "../$1.asc"
  164. else
  165. $signcommand -u "${signkey:-$maintainer}" +clearsig=on -fast <"../$1" \
  166. >"../$1.asc"
  167. fi
  168. status=$?
  169. if [ $status -eq 0 ]; then
  170. mv -- "../$1.asc" "../$1"
  171. else
  172. /bin/rm -f "../$1.asc"
  173. fi
  174. echo
  175. return $status
  176. }
  177. withecho () {
  178. echo " $@" >&2
  179. "$@"
  180. }
  181. if [ "$checkbuilddep" = "true" ]; then
  182. if ! dpkg-checkbuilddeps $checkbuilddep_args; then
  183. echo >&2 "$progname: Build dependencies/conflicts unsatisfied; aborting."
  184. echo >&2 "$progname: (Use -d flag to override.)"
  185. exit 3
  186. fi
  187. fi
  188. set -- $binaryonly $sourceonly $sourcestyle
  189. if [ -n "$maint" ]; then set -- "$@" "-m$maint" ; fi
  190. if [ -n "$changedby" ]; then set -- "$@" "-e$changedby" ; fi
  191. if [ -n "$since" ]; then set -- "$@" "-v$since" ; fi
  192. if [ -n "$desc" ]; then set -- "$@" "-C$desc" ; fi
  193. if [ x$noclean != xtrue ]; then
  194. withecho $rootcommand debian/rules clean
  195. fi
  196. if [ x$binaryonly = x ]; then
  197. cd ..; withecho dpkg-source $passopts $diffignore $tarignore -b "$dirn"; cd "$dirn"
  198. fi
  199. if [ x$sourceonly = x ]; then
  200. withecho debian/rules build
  201. withecho $rootcommand debian/rules $binarytarget
  202. fi
  203. if [ "$usepause" = "true" ] && \
  204. ( [ "$signchanges" != ":" ] || ( [ -z "$binaryonly" ] && [ "$signsource" != ":" ] ) ) ; then
  205. echo Press the return key to start signing process
  206. read dummy_stuff
  207. fi
  208. signerrors=
  209. if [ x$binaryonly = x ]; then
  210. if ! $signsource "$pv.dsc"; then
  211. signerrors="(WARNING: Failed to sign .dsc and .changes file)"
  212. signchanges=:
  213. fi
  214. fi
  215. chg=../"$pva.changes"
  216. withecho dpkg-genchanges "$@" >"$chg"
  217. fileomitted () {
  218. set +e
  219. test -z "`sed -n '/^Files:/,/^[^ ]/ s/'$1'$//p' <$chg`"
  220. fir=$?
  221. set -e
  222. return $fir
  223. }
  224. if fileomitted '\.deb'; then
  225. # source only upload
  226. if fileomitted '\.diff\.gz'; then
  227. srcmsg='source only upload: Debian-native package'
  228. elif fileomitted '\.orig\.tar\.gz'; then
  229. srcmsg='source only, diff-only upload (original source NOT included)'
  230. else
  231. srcmsg='source only upload (original source is included)'
  232. fi
  233. else
  234. srcmsg='full upload (original source is included)'
  235. if fileomitted '\.dsc'; then
  236. srcmsg='binary only upload (no source included)'
  237. elif fileomitted '\.diff\.gz'; then
  238. srcmsg='full upload; Debian-native package (full source is included)'
  239. elif fileomitted '\.orig\.tar\.gz'; then
  240. srcmsg='binary and diff upload (original source NOT included)'
  241. else
  242. srcmsg='full upload (original source is included)'
  243. fi
  244. fi
  245. if ! $signchanges "$pva.changes"; then
  246. signerrors="(WARNING: Failed to sign .changes file)"
  247. fi
  248. if $cleansource; then
  249. withecho $rootcommand debian/rules clean
  250. fi
  251. echo "dpkg-buildpackage: $srcmsg"
  252. if [ -n "$signerrors" ]; then
  253. echo >&2 $signerrors
  254. exit 1
  255. fi