dpkg-buildpackage.sh 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #!/bin/sh
  2. set -e
  3. version="1.3.0"; # This line modified by Makefile
  4. progname="`basename \"$0\"`"
  5. usageversion () {
  6. cat >&2 <<END
  7. Debian GNU/Linux dpkg-buildpackage $version.
  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
  11. or later for copying conditions. There is NO warranty.
  12. Usage: dpkg-buildpackage [options]
  13. Options: -r<gain-root-command>
  14. -p<sign-command>
  15. -k<keyid> the key to use for signing
  16. -sgpg the sign-command is called like GPG
  17. -spgp the sign-command is called like PGP
  18. -sdebsign the sign-command works like debsign
  19. -us unsigned source
  20. -uc unsigned changes
  21. -a<arch> Debian architecture we build for
  22. -b binary-only, do not build source } also passed to
  23. -B binary-only, no arch-indep files } dpkg-genchanges
  24. -S source only, no binary files }
  25. -t<system> set GNU system type } passed to dpkg-architecture
  26. -v<version> changes since version <version> }
  27. -m<maint> maintainer for package is <maint> }
  28. -e<maint> maintainer for release is <maint> } only passed
  29. -C<descfile> changes are described in <descfile> } to dpkg-
  30. -si (default) src includes orig for rev. 0 or 1 } genchanges
  31. -sa uploaded src always includes orig }
  32. -sd uploaded src is diff and .dsc only }
  33. -nc do not clean source tree (implies -b)
  34. -tc clean source tree when finished
  35. -ap add pause before starting signature process
  36. -h print this message
  37. -i[<regex>] ignore diffs of files matching regex } only passed
  38. to dpkg-source
  39. END
  40. }
  41. rootcommand=''
  42. signcommand=""
  43. if [ -e $GNUPGHOME/secring.gpg -o -e $HOME/.gnupg/secring.gpg ] && \
  44. command -v gpg > /dev/null 2>&1; then
  45. signcommand=gpg
  46. elif command -v pgp > /dev/null 2>&1 ; then
  47. signcommand=pgp
  48. fi
  49. signsource='withecho signfile'
  50. signchanges='withecho signfile'
  51. cleansource=false
  52. binarytarget=binary
  53. sourcestyle=''
  54. version=''
  55. since=''
  56. maint=''
  57. desc=''
  58. noclean=false
  59. usepause=false
  60. while [ $# != 0 ]
  61. do
  62. value="`echo x\"$1\" | sed -e 's/^x-.//'`"
  63. case "$1" in
  64. -h) usageversion; exit 0 ;;
  65. -r*) rootcommand="$value" ;;
  66. -p*) signcommand="$value" ;;
  67. -k*) signkey="$value" ;;
  68. -sgpg) forcesigninterface=gpg ;;
  69. -spgp) forcesigninterface=pgp ;;
  70. -sdebsign) forcesigninterface=debsign ;;
  71. -us) signsource=: ;;
  72. -uc) signchanges=: ;;
  73. -ap) usepause="true";;
  74. -a*) targetarch="$value" ;;
  75. -si) sourcestyle=-si ;;
  76. -sa) sourcestyle=-sa ;;
  77. -sd) sourcestyle=-sd ;;
  78. -i*) diffignore=$1;;
  79. -tc) cleansource=true ;;
  80. -t*) targetgnusystem="$value" ;; # Order DOES matter!
  81. -nc) noclean=true; if [ -z "$binaryonly" ]; then binaryonly=-b; fi ;;
  82. -b) binaryonly=-b; [ "$sourceonly" ] && \
  83. { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
  84. -B) binaryonly=-B; binarytarget=binary-arch; [ "$sourceonly" ] && \
  85. { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
  86. -S) sourceonly=-S; [ "$binaryonly" ] && \
  87. { echo >&2 "$progname: cannot combine $binaryonly and $1" ; exit 2 ; } ;;
  88. -v*) since="$value" ;;
  89. -m*) maint="$value" ;;
  90. -e*) changedby="$value" ;;
  91. -C*) desc="$value" ;;
  92. *) echo >&2 "$progname: unknown option or argument $1"
  93. usageversion; exit 2 ;;
  94. esac
  95. shift
  96. done
  97. if [ -z "$signcommand" ] ; then
  98. signsource=:
  99. signchanges=:
  100. fi
  101. if test -n "$forcesigninterface" ; then
  102. signinterface=$forcesigninterface
  103. else
  104. signinterface=$signcommand
  105. fi
  106. if [ "$signinterface" != "gpg" -a "$signinterface" != "pgp" -a \
  107. "$signitnerface" != "debsign" ] ; \
  108. echo >&2 "$progname: invalid sign interface specified"
  109. exit 1
  110. fi
  111. if test "$signinterface" = "debsign"; then
  112. signsource=:
  113. fi
  114. mustsetvar () {
  115. if [ "x$2" = x ]; then
  116. echo >&2 "$progname: unable to determine $3" ; \
  117. exit 1
  118. else
  119. echo "$progname: $3 is $2" ; \
  120. eval "$1=\"\$2\""
  121. fi
  122. }
  123. curd="`pwd`"
  124. dirn="`basename \"$curd\"`"
  125. mustsetvar package "`dpkg-parsechangelog | sed -n 's/^Source: //p'`" "source package"
  126. mustsetvar version "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" "source version"
  127. if [ -n "$maint" ]; then maintainer="$maint";
  128. else mustsetvar maintainer "`dpkg-parsechangelog | sed -n 's/^Maintainer: //p'`" "source maintainer"; fi
  129. eval `dpkg-architecture -a${arch} -t${targetgnusystem} -s`
  130. archlist=`dpkg-architecture -a${targetarch} -t${targetgnusystem} -f 2> /dev/null`
  131. if [ x$sourceonly = x ]; then
  132. mustsetvar arch "`dpkg-architecture -a${targetarch} -t${targetgnusystem} -qDEB_HOST_ARCH`" "build architecture"
  133. else
  134. arch=source
  135. fi
  136. sversion=`echo "$version" | perl -pe 's/^\d+://'`
  137. pv="${package}_${sversion}"
  138. pva="${package}_${sversion}_${arch}
  139. signfile () {
  140. if test "$signinterface" = "gpg" ; then
  141. (cat "../$1" ; echo "") | \
  142. $signcommand --local-user "${signkey:-$maintainer}" --clearsign --armor \
  143. --textmode > "../$1.asc"
  144. elif test "$signinterface" = "debsign"; then
  145. if test x$signkey != x; then
  146. $signcommand -k"$signkey" ../$1
  147. else
  148. $signcommand ../$1
  149. fi
  150. return
  151. else
  152. $signcommand -u "${signkey:-$maintainer}" +clearsig=on -fast <"../$1" \
  153. >"../$1.asc"
  154. fi
  155. echo
  156. mv -- "../$1.asc" "../$1"
  157. }
  158. withecho () {
  159. echo " $@" >&2
  160. "$@"
  161. }
  162. set -- $binaryonly $sourceonly $sourcestyle
  163. if [ -n "$maint" ]; then set -- "$@" "-m$maint" ; fi
  164. if [ -n "$changedby" ]; then set -- "$@" "-e$changedby" ; fi
  165. if [ -n "$since" ]; then set -- "$@" "-v$since" ; fi
  166. if [ -n "$desc" ]; then set -- "$@" "-C$desc" ; fi
  167. if [ x$noclean != xtrue ]; then
  168. withecho $rootcommand debian/rules clean $archlist
  169. fi
  170. if [ x$binaryonly = x ]; then
  171. cd ..; withecho dpkg-source $diffignore -b "$dirn"; cd "$dirn"
  172. fi
  173. if [ x$sourceonly = x ]; then
  174. withecho debian/rules build $archlist
  175. withecho $rootcommand debian/rules $binarytarget $archlist
  176. fi
  177. if [ "$usepause" = "true" -a "signchanges" != ":" ] && [ "x$binaryonly" = x -o "x$signchanges" != x ] ; then
  178. echo Press the return key to start signing process
  179. read dummy_stuff
  180. fi
  181. if [ x$binaryonly = x ]; then
  182. $signsource "$pv.dsc"
  183. fi
  184. chg=../"$pva.changes"
  185. withecho dpkg-genchanges "$@" >"$chg"
  186. fileomitted () {
  187. set +e
  188. test -z "`sed -n '/^Files:/,/^[^ ]/ s/'$1'$//p' <$chg`"
  189. fir=$?
  190. set -e
  191. return $fir
  192. }
  193. if fileomitted '\.deb'; then
  194. # source only upload
  195. if fileomitted '\.diff\.gz'; then
  196. srcmsg='source only upload: Debian-native package'
  197. elif fileomitted '\.orig\.tar\.gz'; then
  198. srcmsg='source only, diff-only upload (original source NOT included)'
  199. else
  200. srcmsg='source only upload (original source is included)'
  201. fi
  202. else
  203. srcmsg='full upload (original source is included)'
  204. if fileomitted '\.dsc'; then
  205. srcmsg='binary only upload (no source included)'
  206. elif fileomitted '\.diff\.gz'; then
  207. srcmsg='full upload; Debian-native package (full source is included)'
  208. elif fileomitted '\.orig\.tar\.gz'; then
  209. srcmsg='binary and diff upload (original source NOT included)'
  210. else
  211. srcmsg='full upload (original source is included)'
  212. fi
  213. fi
  214. $signchanges "$pva.changes"
  215. if $cleansource; then
  216. withecho $rootcommand debian/rules clean $archlist
  217. fi
  218. echo "dpkg-buildpackage: $srcmsg"