dpkg-buildpackage.sh 8.7 KB

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