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