grml-cheatcodes.txt: replace vlock with physlock
[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
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     $(git log --format=oneline -1)
46
47  -- grml-live Auto Build <grml-live-git@$(hostname)>  $DATE
48
49 EOF
50   git add debian/changelog
51   git commit -m "Releasing ${GRML_LIVE_VERSION}-~autobuild${UNIXTIME} (auto build)"
52 else
53   since=v$(dpkg-parsechangelog | awk '/^Version:/ {print $2}')
54   git-dch --ignore-branch --since=$since \
55           --id-length=7 --meta --multimaint-merge -S
56   printf "OK\n"
57 fi
58
59 if [ -z "${AUTOBUILD:-}" ] ; then
60   if ! $EDITOR debian/changelog ; then
61     printf "Exiting as editing debian/changelog returned an error." >&2
62     exit 1
63   fi
64 fi
65
66 debian_version="$(dpkg-parsechangelog | awk '/^Version:/ {print $2}')"
67
68 dorelease="true"
69 if echo "$debian_version" | grep -q '\.gbp' ; then
70   printf "Building snapshot version, not releasing.\n"
71   dorelease="false"
72 fi
73
74 printf "Updating GRML_LIVE_VERSION string in grml-live script: "
75 sed -i "s/^GRML_LIVE_VERSION=.*/GRML_LIVE_VERSION='$debian_version'/" grml-live
76 printf "OK\n"
77
78 printf "Comparing versions of debian/changelog with grml-live version string: "
79 script_version="$(awk -F= '/^GRML_LIVE_VERSION=/ {print $2}' grml-live | sed "s/'//g")"
80 debian_version="$(dpkg-parsechangelog | awk '/^Version:/ {print $2}')"
81
82 if [[ "$script_version" == "$debian_version" ]] ; then
83   printf "OK\n"
84 else
85   printf "FAILED\n."
86   printf "Debian package version ($debian_version) does not match script version ($script_version).\n"
87   exit 1
88 fi
89
90 if $dorelease || [ -n "${AUTOBUILD:-}" ] ; then
91   git add debian/changelog grml-live
92   git commit -s -m "Release new version ${debian_version}."
93 fi
94
95 printf "Building debian packages:\n"
96 if [ -n "${AUTOBUILD:-}" ] ; then
97   [ -d ../grml-live.build-area ] || mkdir ../grml-live.build-area
98   rm -rf ../grml-live.build-area/grml-live* # otherwise we're keeping files forever...
99   git-buildpackage --git-ignore-branch --git-ignore-new --git-export-dir=../grml-live.build-area -us -uc
100 else
101   git-buildpackage --git-ignore-branch --git-ignore-new $*
102   printf "Finished execution of $(basename $0). Do not forget to tag release ${debian_version}\n"
103 fi
104
105 if [ -n "${AUTOBUILD:-}" ] ; then
106    (
107      cd ../grml-live.build-area
108      dpkg-scanpackages . /dev/null > Packages
109      dpkg-scanpackages . /dev/null | gzip > Packages.gz
110    )
111    git checkout master
112    git branch -D ${autobuild_branch} || true
113
114    env APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none sudo apt-get update
115
116    PACKAGES=$(dpkg --list grml-live\* | awk '/^ii/ {print $2}')
117    env APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none sudo apt-get -y \
118      -o DPkg::Options::=--force-confmiss \
119      -o DPkg::Options::=--force-confnew  \
120      --allow-unauthenticated install $PACKAGES
121 fi
122
123 ## END OF FILE #################################################################