2 # $MirOS: contrib/hosted/tg/deb/BuildDSC.sh,v 1.14 2011/11/17 15:27:53 tg Exp $
4 # Copyright (c) 2010, 2011
5 # Thorsten Glaser <t.glaser@tarent.de>
7 # Provided that these terms and disclaimer and all copyright notices
8 # are retained or reproduced in an accompanying document, permission
9 # is granted to deal in this work without restriction, including un-
10 # limited rights to use, publicly perform, distribute, sell, modify,
11 # merge, give away, or sublicence.
13 # This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
14 # the utmost extent permitted by applicable law, neither express nor
15 # implied; without malicious intent or gross negligence. In no event
16 # may a licensor, author or contributor be held liable for indirect,
17 # direct, other damage, loss, or other issues arising in any way out
18 # of dealing in the work, even if advised of the possibility of such
19 # damage or existence of a defect, except proven that it results out
20 # of said person's immediate fault when using the work as intended.
22 # The current working directory, or else the directory in which this
23 # script resides, must be the root directory of a (extracted) Debian
24 # source package. It will then be renamed to the proper dirname, and
25 # a source package (*.dsc + others) will be created, then it will be
27 # -s arg: make a snapshot with "arg" being the version number suffix
28 # -S: build a snapshot with snapshot.YYYYMMDD.HHMMSS (UTC) as suffix
29 # Any further arguments will be passed to debian/rules via MAKEFLAGS
31 # sanitise environment
39 stime_rfc=$(date +"%a, %d %b %Y %H:%M:%S %z")
40 stime_vsn=$(date -u +"%Y%m%d.%H%M%S")
44 while getopts "Ss:" ch; do
47 ssuf=snapshot.$stime_vsn
52 (*) print -u2 Syntax error.
60 if (( snap )) && [[ -z $DEBEMAIL ]]; then
61 print -u2 'Please set $DEBEMAIL to "First M. Last <email@domain.com>"'
67 echo >&2 "=== trying . = $(pwd)"
68 dh_testdir >/dev/null 2>&1 && break
69 if [[ -s debian/control.in && -s debian/rules && \
70 -x debian/rules && ! -e debian/control ]]; then
72 debian/rules debian/control
74 dh_testdir >/dev/null 2>&1 && break
75 (( rmc )) && debian/rules remove/control
78 print -u2 "=== trying basedir = $(pwd)"
79 dh_testdir >/dev/null 2>&1 && break
80 if [[ -s debian/control.in && -s debian/rules && \
81 -x debian/rules && ! -e debian/control ]]; then
83 debian/rules debian/control
85 dh_testdir >/dev/null 2>&1 && break
86 (( rmc )) && debian/rules remove/control
87 print -u2 "FAILED! Please change to the correct directory."
91 pkgstem=$(dpkg-parsechangelog -n1 | sed -n '/^Source: /s///p')
92 version=$(dpkg-parsechangelog -n1 | sed -n '/^Version: /s///p')
95 if ! T=$(mktemp "$updir/BuildDSC.tmp.XXXXXXXXXX"); then
96 (( rmc )) && debian/rules remove/control
97 print -u2 Could not create temporary file.
100 cat debian/changelog >"$T"
101 touch -r debian/changelog "$T"
102 dist=$(dpkg-parsechangelog -n1 | sed -n '/^Distribution: /s///p')
103 if [[ $dist = UNRELEASED || $dist = x* ]]; then
104 # we’re at “current” already, reduce
105 version=$version'~'$ssuf
107 # we’re at an uploaded version, raise
108 version=$version'+'$ssuf
110 print "$pkgstem ($version) UNRELEASED; urgency=low\n\n *" \
111 "Automatically built snapshot (not backport) package.\n\n --" \
112 "$DEBEMAIL $stime_rfc\n" >debian/changelog
113 cat "$T" >>debian/changelog
114 touch -r "$T" debian/changelog
117 debian/rules debian/control
120 upstreamversion=${version%%-*([!-])}
121 upstreamversion=${upstreamversion#+([0-9]):}
124 newname=$pkgstem-$upstreamversion
125 [[ $newname = $curname ]] || mv "$curname" "$newname"
127 dpkg-buildpackage -rfakeroot -S -I -i
129 fakeroot debian/rules clean
131 [[ $newname = $curname ]] || mv "$newname" "$curname"
135 cat "$T" >debian/changelog
136 touch -r "$T" debian/changelog
139 (( rmc )) && debian/rules remove/control