dpkg-buildpackage.sh 6.5 KB

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