ce6ba6dda65e9988a9c9688b920f38be54a41802
[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 [ -n "${AUTOBUILD:-}" ] ; then
16   git checkout autobuild # has to exist
17 else
18   if git status --porcelain | grep -q '^?? '; then
19     printf "Uncommited changes in current working tree. Please commit/clean up.\n"
20     exit 1
21   fi
22 fi
23
24 if [ -n "${AUTOBUILD:-}" ] ; then
25   since=$(git show -s --pretty="tformat:%h")
26 else
27   since=v$(dpkg-parsechangelog | awk '/^Version:/ {print $2}')
28 fi
29
30 printf "Building debian/changelog: "
31 git-dch --ignore-branch --since=$since \
32         --id-length=7 --meta --multimaint-merge -S
33 printf "OK\n"
34
35 if [ -z "${AUTOBUILD:-}" ] ; then
36   if ! $EDITOR debian/changelog ; then
37     printf "Exiting as editing debian/changelog returned an error." >&2
38     exit 1
39   fi
40 fi
41
42 debian_version="$(dpkg-parsechangelog | awk '/^Version:/ {print $2}')"
43
44 dorelease="true"
45 if echo "$debian_version" | grep -q '\.gbp' ; then
46   printf "Building snapshot version, not releasing.\n"
47   dorelease="false"
48 fi
49
50 printf "Updating GRML_LIVE_VERSION string in grml-live script: "
51 sed -i "s/^GRML_LIVE_VERSION=.*/GRML_LIVE_VERSION='$debian_version'/" grml-live
52 printf "OK\n"
53
54 printf "Comparing versions of debian/changelog with grml-live version string: "
55 script_version="$(awk -F= '/^GRML_LIVE_VERSION=/ {print $2}' grml-live | sed "s/'//g")"
56 debian_version="$(dpkg-parsechangelog | awk '/^Version:/ {print $2}')"
57
58 if [[ "$script_version" == "$debian_version" ]] ; then
59   printf "OK\n"
60 else
61   printf "FAILED\n."
62   printf "Debian package version ($debian_version) does not match script version ($script_version).\n"
63   exit 1
64 fi
65
66 if $dorelease || [ -n "${AUTOBUILD:-}" ] ; then
67   git add debian/changelog grml-live
68   git commit -s -m "Release new version ${debian_version}."
69 fi
70
71 printf "Building debian packages:\n"
72 if [ -n "${AUTOBUILD:-}" ] ; then
73   [ -d ../grml-live.build-area ] || mkdir ../grml-live.build-area
74   git-buildpackage --git-ignore-branch --git-ignore-new --git-export-dir=../grml-live.build-area -us -uc
75 else
76   git-buildpackage --git-ignore-branch --git-ignore-new $*
77   printf "Finished execution of $(basename $0). Do not forget to tag release ${debian_version}\n"
78 fi
79
80 if [ -n "${AUTOBUILD:-}" ] ; then
81    (
82      cd ../grml-live.build-area
83      dpkg-scanpackages . /dev/null > Packages
84    )
85    apt-get update
86    PACKAGES=$(dpkg --list grml-live\* | awk '/^ii/ {print $2}')
87    apt-get -y --allow-unauthenticated install $PACKAGES
88 fi
89
90 ## END OF FILE #################################################################