a5fba5572f2f7dfd907f070b413086f27f743eb6
[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 export LC_ALL=C
13 export LANG=C
14
15 debian_version=''
16 script_version=''
17
18 autobuild_branch="autobuild_$(date +%Y%m%d_%H%M%S)"
19
20 if [ -n "${AUTOBUILD:-}" ] ; then
21   git checkout master
22   git pull
23   git checkout -b "$autobuild_branch"
24 else
25   if git status --porcelain | grep -q '^?? '; then
26     printf "Uncommited changes in current working tree. Please commit/clean up.\n"
27     exit 1
28   fi
29 fi
30
31 printf "Building debian/changelog: "
32 if [ -n "${AUTOBUILD:-}" ] ; then
33   # since=$(git show -s --pretty="tformat:%h")
34   eval $(grep '^GRML_LIVE_VERSION=' grml-live)
35   DATE=$(date -R)
36   UNIXTIME=$(date +%s)
37
38   cat > debian/changelog << EOF
39 grml-live (${GRML_LIVE_VERSION}~autobuild${UNIXTIME}) UNRELEASED; urgency=low
40
41   * Automatically built package based on the state of
42     git repository at http://git.grml.org/?p=grml-live.git
43     on $DATE
44
45  -- grml-live Auto Build <mika@grml.org>  $DATE
46
47 EOF
48   git add debian/changelog
49   git commit -m "Releasing ${GRML_LIVE_VERSION}-~autobuild${UNIXTIME} (auto build)"
50 else
51   since=v$(dpkg-parsechangelog | awk '/^Version:/ {print $2}')
52   git-dch --ignore-branch --since=$since \
53           --id-length=7 --meta --multimaint-merge -S
54   printf "OK\n"
55 fi
56
57 if [ -z "${AUTOBUILD:-}" ] ; then
58   if ! $EDITOR debian/changelog ; then
59     printf "Exiting as editing debian/changelog returned an error." >&2
60     exit 1
61   fi
62 fi
63
64 debian_version="$(dpkg-parsechangelog | awk '/^Version:/ {print $2}')"
65
66 dorelease="true"
67 if echo "$debian_version" | grep -q '\.gbp' ; then
68   printf "Building snapshot version, not releasing.\n"
69   dorelease="false"
70 fi
71
72 printf "Updating GRML_LIVE_VERSION string in grml-live script: "
73 sed -i "s/^GRML_LIVE_VERSION=.*/GRML_LIVE_VERSION='$debian_version'/" grml-live
74 printf "OK\n"
75
76 printf "Comparing versions of debian/changelog with grml-live version string: "
77 script_version="$(awk -F= '/^GRML_LIVE_VERSION=/ {print $2}' grml-live | sed "s/'//g")"
78 debian_version="$(dpkg-parsechangelog | awk '/^Version:/ {print $2}')"
79
80 if [[ "$script_version" == "$debian_version" ]] ; then
81   printf "OK\n"
82 else
83   printf "FAILED\n."
84   printf "Debian package version ($debian_version) does not match script version ($script_version).\n"
85   exit 1
86 fi
87
88 if $dorelease || [ -n "${AUTOBUILD:-}" ] ; then
89   git add debian/changelog grml-live
90   git commit -s -m "Release new version ${debian_version}."
91 fi
92
93 printf "Building debian packages:\n"
94 if [ -n "${AUTOBUILD:-}" ] ; then
95   [ -d ../grml-live.build-area ] || mkdir ../grml-live.build-area
96   git-buildpackage --git-ignore-branch --git-ignore-new --git-export-dir=../grml-live.build-area -us -uc
97 else
98   git-buildpackage --git-ignore-branch --git-ignore-new $*
99   printf "Finished execution of $(basename $0). Do not forget to tag release ${debian_version}\n"
100 fi
101
102 if [ -n "${AUTOBUILD:-}" ] ; then
103    (
104      cd ../grml-live.build-area
105      dpkg-scanpackages . /dev/null > Packages
106    )
107    git checkout master
108    git branch -D ${autobuild_branch} || true
109    apt-get update
110    PACKAGES=$(dpkg --list grml-live\* | awk '/^ii/ {print $2}')
111    apt-get -y --allow-unauthenticated install $PACKAGES
112 fi
113
114 ## END OF FILE #################################################################