2 # $MirOS: contrib/hosted/tg/deb/BuildDSC.sh,v 1.19 2016/02/23 18:05:35 tg Exp $
4 # Copyright (c) 2010, 2011
5 # Thorsten Glaser <t.glaser@tarent.de>
6 # Copyright © 2015, 2016
7 # mirabilos <m@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 (ignore B-D absence)
30 # -N: pass -nc to dpkg-buildpackage (do not clean)
31 # -s arg: make a snapshot with “arg” being the version number suffix
32 # -S: build a snapshot with snapshot.YYYYMMDD.HHMMSS (UTC) as suffix
33 # Any further arguments will be passed to debian/rules via MAKEFLAGS
35 # sanitise environment
43 stime_rfc=$(date +"%a, %d %b %Y %H:%M:%S %z")
44 stime_vsn=$(date -u +"%Y%m%d.%H%M%S")
50 while getopts "dNSs:" ch; do
61 ssuf=snapshot.$stime_vsn
72 (*) print -u2 Syntax error.
80 if (( snap )) && [[ $DEBEMAIL != +([A-Za-z])*' <'*'>' ]]; then
81 print -u2 'Please set $DEBEMAIL to "First M. Last <email@domain.com>"'
87 echo >&2 "=== trying . = $(pwd)"
88 dh_testdir >/dev/null 2>&1 && break
89 if [[ -s debian/control.in && -s debian/rules && \
90 -x debian/rules && ! -e debian/control ]]; then
92 debian/rules debian/control
94 dh_testdir >/dev/null 2>&1 && break
95 (( rmc )) && debian/rules remove/control
98 print -u2 "=== trying basedir = $(pwd)"
99 dh_testdir >/dev/null 2>&1 && break
100 if [[ -s debian/control.in && -s debian/rules && \
101 -x debian/rules && ! -e debian/control ]]; then
103 debian/rules debian/control
105 dh_testdir >/dev/null 2>&1 && break
106 (( rmc )) && debian/rules remove/control
107 print -u2 "FAILED! Please change to the correct directory."
111 pkgstem=$(dpkg-parsechangelog -n1 | sed -n '/^Source: /s///p')
112 version=$(dpkg-parsechangelog -n1 | sed -n '/^Version: /s///p')
115 if ! T=$(mktemp "$updir/BuildDSC.tmp.XXXXXXXXXX"); then
116 (( rmc )) && debian/rules remove/control
117 print -u2 Could not create temporary file.
120 cat debian/changelog >"$T"
121 touch -r debian/changelog "$T"
122 dist=$(dpkg-parsechangelog -n1 | sed -n '/^Distribution: /s///p')
123 if [[ $dist = UNRELEASED || $dist = x* ]]; then
124 # we’re at “current” already, reduce
125 version=$version'~'$ssuf
127 # we’re at an uploaded version, raise
128 version=$version'+'$ssuf
130 print "$pkgstem ($version) UNRELEASED; urgency=low\n\n *" \
131 "Automatically built snapshot (not backport) package.\n\n --" \
132 "$DEBEMAIL $stime_rfc\n" >debian/changelog
133 cat "$T" >>debian/changelog
134 touch -r "$T" debian/changelog
137 debian/rules debian/control
140 upstreamversion=${version%%-*([!-])}
141 upstreamversion=${upstreamversion#+([0-9]):}
144 newname=$pkgstem-$upstreamversion
145 [[ $newname = $curname ]] || mv "$curname" "$newname"
147 dpkg-buildpackage -rfakeroot -S -I -i $optd $optN -us -uc
149 [[ -n $optN ]] || fakeroot debian/rules clean
151 [[ $newname = $curname ]] || mv "$newname" "$curname"
155 cat "$T" >debian/changelog
156 touch -r "$T" debian/changelog
159 (( rmc )) && debian/rules remove/control