dpkg-buildpackage.sh 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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; [ "$sourceonly" ] && \
  103. { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
  104. -B) binaryonly=-B; checkbuilddep_args=-B; binarytarget=binary-arch; [ "$sourceonly" ] && \
  105. { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
  106. -S) sourceonly=-S; checkbuilddep=false; [ "$binaryonly" ] && \
  107. { echo >&2 "$progname: cannot combine $binaryonly and $1" ; exit 2 ; } ;;
  108. -v*) since="$value" ;;
  109. -m*) maint="$value" ;;
  110. -e*) changedby="$value" ;;
  111. -C*) desc="$value" ;;
  112. -W) warnable_error=1; passopts="$passopts -W";;
  113. -E) warnable_error=0; passopts="$passopts -E";;
  114. *) echo >&2 "$progname: unknown option or argument $1"
  115. usage; exit 2 ;;
  116. esac
  117. shift
  118. done
  119. if [ -z "$signcommand" ] ; then
  120. signsource=:
  121. signchanges=:
  122. fi
  123. if test -n "$forcesigninterface" ; then
  124. signinterface=$forcesigninterface
  125. if [ "$signinterface" != "gpg" ] && [ "$signinterface" != "pgp" ] ; then
  126. echo >&2 "$progname: invalid sign interface specified"
  127. exit 1
  128. fi
  129. else
  130. signinterface=$signcommand
  131. fi
  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. curd="`pwd`"
  142. dirn="`basename \"$curd\"`"
  143. mustsetvar package "`dpkg-parsechangelog | sed -n 's/^Source: //p'`" "source package is"
  144. mustsetvar changesversion "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" "source version is"
  145. if [ -n "$changedby" ]; then maintainer="$changedby";
  146. elif [ -n "$maint" ]; then maintainer="$maint";
  147. else mustsetvar maintainer "`dpkg-parsechangelog | sed -n 's/^Maintainer: //p'`" "source changed by"; fi
  148. eval `dpkg-architecture -a${targetarch} -t${targetgnusystem} -s -f`
  149. if [ x$sourceonly = x ]; then
  150. mustsetvar arch "`dpkg-architecture -a${targetarch} -t${targetgnusystem} -qDEB_HOST_ARCH`" "host architecture"
  151. else
  152. arch=source
  153. fi
  154. mustsetvar sversion "`echo \"$changesversion\" | perl -pe 's/^\d+://'`" "source version without epoch"
  155. pv="${package}_${sversion}"
  156. pva="${package}_${sversion}_${arch}"
  157. signfile () {
  158. if test "$signinterface" = "gpg" ; then
  159. (cat "../$1" ; echo "") | \
  160. $signcommand --local-user "${signkey:-$maintainer}" --clearsign --armor \
  161. --textmode > "../$1.asc"
  162. else
  163. $signcommand -u "${signkey:-$maintainer}" +clearsig=on -fast <"../$1" \
  164. >"../$1.asc"
  165. fi
  166. status=$?
  167. if [ $status -eq 0 ]; then
  168. mv -- "../$1.asc" "../$1"
  169. else
  170. /bin/rm -f "../$1.asc"
  171. fi
  172. echo
  173. return $status
  174. }
  175. withecho () {
  176. echo " $@" >&2
  177. "$@"
  178. }
  179. if [ "$checkbuilddep" = "true" ]; then
  180. if ! dpkg-checkbuilddeps $checkbuilddep_args; then
  181. echo >&2 "$progname: Build dependencies/conflicts unsatisfied; aborting."
  182. echo >&2 "$progname: (Use -d flag to override.)"
  183. exit 3
  184. fi
  185. fi
  186. set -- $binaryonly $sourceonly $sourcestyle
  187. if [ -n "$maint" ]; then set -- "$@" "-m$maint" ; fi
  188. if [ -n "$changedby" ]; then set -- "$@" "-e$changedby" ; fi
  189. if [ -n "$since" ]; then set -- "$@" "-v$since" ; fi
  190. if [ -n "$desc" ]; then set -- "$@" "-C$desc" ; fi
  191. if [ x$noclean != xtrue ]; then
  192. withecho $rootcommand debian/rules clean
  193. fi
  194. if [ x$binaryonly = x ]; then
  195. cd ..; withecho dpkg-source $passopts $diffignore $tarignore -b "$dirn"; cd "$dirn"
  196. fi
  197. if [ x$sourceonly = x ]; then
  198. withecho debian/rules build
  199. withecho $rootcommand debian/rules $binarytarget
  200. fi
  201. if [ "$usepause" = "true" ] && \
  202. ( [ "$signchanges" != ":" ] || ( [ -z "$binaryonly" ] && [ "$signsource" != ":" ] ) ) ; then
  203. echo Press the return key to start signing process
  204. read dummy_stuff
  205. fi
  206. signerrors=
  207. if [ x$binaryonly = x ]; then
  208. if ! $signsource "$pv.dsc"; then
  209. signerrors="(WARNING: Failed to sign .dsc and .changes file)"
  210. signchanges=:
  211. fi
  212. fi
  213. chg=../"$pva.changes"
  214. withecho dpkg-genchanges "$@" >"$chg"
  215. fileomitted () {
  216. set +e
  217. test -z "`sed -n '/^Files:/,/^[^ ]/ s/'$1'$//p' <$chg`"
  218. fir=$?
  219. set -e
  220. return $fir
  221. }
  222. if fileomitted '\.deb'; then
  223. # source only upload
  224. if fileomitted '\.diff\.gz'; then
  225. srcmsg='source only upload: Debian-native package'
  226. elif fileomitted '\.orig\.tar\.gz'; then
  227. srcmsg='source only, diff-only upload (original source NOT included)'
  228. else
  229. srcmsg='source only upload (original source is included)'
  230. fi
  231. else
  232. srcmsg='full upload (original source is included)'
  233. if fileomitted '\.dsc'; then
  234. srcmsg='binary only upload (no source included)'
  235. elif fileomitted '\.diff\.gz'; then
  236. srcmsg='full upload; Debian-native package (full source is included)'
  237. elif fileomitted '\.orig\.tar\.gz'; then
  238. srcmsg='binary and diff upload (original source NOT included)'
  239. else
  240. srcmsg='full upload (original source is included)'
  241. fi
  242. fi
  243. if ! $signchanges "$pva.changes"; then
  244. signerrors="(WARNING: Failed to sign .changes file)"
  245. fi
  246. if $cleansource; then
  247. withecho $rootcommand debian/rules clean
  248. fi
  249. echo "dpkg-buildpackage: $srcmsg"
  250. if [ -n "$signerrors" ]; then
  251. echo >&2 $signerrors
  252. exit 1
  253. fi