scripts/release_helper.sh: cancel if editing changelog returned error, provide cmdlin...
[grml-live.git] / scripts / release_helper.sh
1 #!/bin/bash
2 # Filename:      scripts/release_helper.sh
3 # Purpose:       helper script to build grml-live Debian packages (WFM style though)
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 ################################################################################
8
9 set -e
10 set -u
11
12 debian_version=''
13 script_version=''
14
15 if git status --porcelain | grep -q '^?? '; then
16   printf "Uncommited changes in current working tree. Please commit/clean up.\n"
17   exit 1
18 fi
19
20 printf "Building debian/changelog: "
21 git-dch --debian-branch="$(git branch | awk -F\*\  '/^* / { print $2}' )" \
22         --since=v$(dpkg-parsechangelog | awk '/^Version:/ {print $2}') \
23         --id-length=7 --meta --multimaint-merge -S
24 printf "OK\n"
25
26 if ! $EDITOR debian/changelog ; then
27   printf "Exiting as editing debian/changelog returned an error." >&2
28   exit 1
29 fi
30
31 debian_version="$(dpkg-parsechangelog | awk '/^Version:/ {print $2}')"
32
33 dorelease="true"
34 if echo "$debian_version" | grep -q '\.gbp' ; then
35   printf "Building snapshot version, not releasing.\n"
36   dorelease="false"
37 fi
38
39 printf "Updating GRML_LIVE_VERSION string in grml-live script: "
40 sed -i "s/^GRML_LIVE_VERSION=.*/GRML_LIVE_VERSION='$debian_version'/" grml-live
41 printf "OK\n"
42
43 printf "Comparing versions of debian/changelog with grml-live version string: "
44 script_version="$(awk -F= '/^GRML_LIVE_VERSION=/ {print $2}' grml-live | sed "s/'//g")"
45 debian_version="$(dpkg-parsechangelog | awk '/^Version:/ {print $2}')"
46
47 if [[ "$script_version" == "$debian_version" ]] ; then
48   printf "OK\n"
49 else
50   printf "FAILED\n."
51   printf "Debian package version ($debian_version) does not match script version ($script_version).\n"
52   exit 1
53 fi
54
55 if $dorelease ; then
56   git add debian/changelog grml-live
57   git commit -s -m "Release new version ${debian_version}."
58 fi
59
60 printf "Building debian packages:\n"
61 git-buildpackage --git-debian-branch="$(git branch | awk -F\*\  '/^* / { print $2}' )" --git-ignore-new $*
62 printf "Finished execution of $(basename $0). Do not forget to tag release ${debian_version}\n"
63
64 ## END OF FILE #################################################################