scripts/release_helper.sh: fix debian/changelog format.
[grml-live.git] / scripts / release_helper.sh
index ce6ba6d..c418e7f 100755 (executable)
@@ -1,19 +1,51 @@
 #!/bin/bash
 # Filename:      scripts/release_helper.sh
-# Purpose:       helper script to build grml-live Debian packages (WFM style though)
+# Purpose:       helper script to build grml-live Debian packages
 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
 # Bug-Reports:   see http://grml.org/bugs/
 # License:       This file is licensed under the GPL v2 or any later version.
 ################################################################################
+## How to set up autobuild (for automatically updating grml-live.git and
+## build packages out of git tree and install them, e.g. for usage on
+## daily.grml.org):
+# echo "deb file:/home/grml-live-git/grml-live.build-area/ ./" >> /etc/apt/sources.list.d/grml-live.list
+# adduser --disabled-login --disabled-password grml-live-git
+# visudo -> add "grml-live-git ALL=NOPASSWD: /usr/bin/apt-get"
+# su - grml-live-git
+# mkdir /home/grml-live-git/grml-live.build-area
+# git clone git://git.grml.org/grml-live.git
+# git config --global user.name "Grml-Live Git Autobuild"
+# git config --global user.email "grml-live-git@$(hostname)"
+#
+# Finally install a cron job (as user grml-live-git) like:
+# 30 00 * * * cd /home/grml-live-git/grml-live.git/ && env AUTOBUILD=1 scripts/release_helper.sh >/home/grml-live-git/grml-live-build.log
+#
+# Tip: To find out the build date of the installed grml-live package just run:
+#
+# % apt-cache policy grml-live | grep 'Installed.*autobuild'
+#  Installed: 0.13.1~autobuild1300450381
+#
+# and run "date -ud @$STRING" where $STRING is the number
+# behind the "autobuild", like:
+# % date -ud @1300450081
+# Fri Mar 18 12:08:01 UTC 2011
+################################################################################
 
 set -e
 set -u
 
+export LC_ALL=C
+export LANG=C
+
 debian_version=''
 script_version=''
 
+autobuild_branch="autobuild_$(date +%Y%m%d_%H%M%S)"
+
 if [ -n "${AUTOBUILD:-}" ] ; then
-  git checkout autobuild # has to exist
+  git checkout master
+  git pull
+  git checkout -b "$autobuild_branch"
 else
   if git status --porcelain | grep -q '^?? '; then
     printf "Uncommited changes in current working tree. Please commit/clean up.\n"
@@ -21,17 +53,34 @@ else
   fi
 fi
 
+printf "Building debian/changelog: "
 if [ -n "${AUTOBUILD:-}" ] ; then
-  since=$(git show -s --pretty="tformat:%h")
+  # since=$(git show -s --pretty="tformat:%h")
+  eval $(grep '^GRML_LIVE_VERSION=' grml-live)
+  DATE=$(date -R)
+  UNIXTIME=$(date +%s)
+
+  cat > debian/changelog << EOF
+grml-live (${GRML_LIVE_VERSION}~autobuild${UNIXTIME}) UNRELEASED; urgency=low
+
+  * Automatically built package based on the state of
+    git repository at http://git.grml.org/?p=grml-live.git
+    on $DATE ->
+
+    $(git log --format=oneline -1)
+
+ -- grml-live Auto Build <grml-live-git@$(hostname)>  $DATE
+
+EOF
+  git add debian/changelog
+  git commit -m "Releasing ${GRML_LIVE_VERSION}-~autobuild${UNIXTIME} (auto build)"
 else
   since=v$(dpkg-parsechangelog | awk '/^Version:/ {print $2}')
+  git-dch --ignore-branch --since=$since \
+          --id-length=7 --meta --multimaint-merge -S
+  printf "OK\n"
 fi
 
-printf "Building debian/changelog: "
-git-dch --ignore-branch --since=$since \
-        --id-length=7 --meta --multimaint-merge -S
-printf "OK\n"
-
 if [ -z "${AUTOBUILD:-}" ] ; then
   if ! $EDITOR debian/changelog ; then
     printf "Exiting as editing debian/changelog returned an error." >&2
@@ -71,6 +120,7 @@ fi
 printf "Building debian packages:\n"
 if [ -n "${AUTOBUILD:-}" ] ; then
   [ -d ../grml-live.build-area ] || mkdir ../grml-live.build-area
+  rm -f ../grml-live.build-area/grml-live* # otherwise we're keeping files forever...
   git-buildpackage --git-ignore-branch --git-ignore-new --git-export-dir=../grml-live.build-area -us -uc
 else
   git-buildpackage --git-ignore-branch --git-ignore-new $*
@@ -82,9 +132,11 @@ if [ -n "${AUTOBUILD:-}" ] ; then
      cd ../grml-live.build-area
      dpkg-scanpackages . /dev/null > Packages
    )
-   apt-get update
+   git checkout master
+   git branch -D ${autobuild_branch} || true
+   sudo apt-get update
    PACKAGES=$(dpkg --list grml-live\* | awk '/^ii/ {print $2}')
-   apt-get -y --allow-unauthenticated install $PACKAGES
+   sudo apt-get -y --allow-unauthenticated install $PACKAGES
 fi
 
 ## END OF FILE #################################################################