Nightly build script with more robust handling of debian patches.
[wmaker-crm.git] / debian / nightly_build.sh
blob3c3640ce5bf6a1213f32ef5f2667f0f443eb73e5
1 #!/bin/sh
3 CHLOGBKP="/tmp/$$-chlog"
4 BASEVERSION="0.93.0"
5 REPOVERSION="git-`date +%Y%m%d-%H%M`"
7 CHANGELOG="Automatic build from the GIT on `date`"
8 BUILDLOG="${HOME}/log/wmaker-testing-nightly.log"
10 STATUSCMD="git log -1 --pretty=oneline"
11 PULLCMD="git pull"
12 if [ -n "${WMAKER_DISTRO}" ]; then
13 case ${WMAKER_DISTRO} in
14 unstable)
15 BUILDLOG="${HOME}/log/wmaker-unstable-nightly.log"
17 esac
20 FORCE="0"
22 if [ $# -gt 0 ]; then
23 case $1 in
24 -f|--force)
25 FORCE="1"
28 echo "Usage $0 [-f|--force]"
29 exit 0
31 esac
34 cleanup() {
35 test -f ${CHLOGBKP} && mv ${CHLOGBKP} debian/changelog
38 errorExit() {
39 echo "$@" 1>&2
40 cleanup
41 exit 2
44 doPull() {
45 RC="1"
46 LATEST="`$STATUSCMD`"
47 $PULLCMD >>$BUILDLOG 2>&1 || errorExit "Error pulling from the repo"
48 CURRENT="`$STATUSCMD`"
49 if [ "$FORCE" = "1" -o "$LATEST" != "$CURRENT" ]; then
50 echo "last revision: $LATEST" >>$BUILDLOG
51 echo "new revision: $CURRENT" >>$BUILDLOG
52 echo "FORCE: $FORCE" >>$BUILDLOG
53 RC="0"
54 else
55 echo "No changes to build, and FORCE not given." >>$BUILDLOG
57 return $RC
60 doEnv() {
61 for var in `env | grep GNUSTEP | sed "s/=.*//"`; do
62 unset $var
63 done
66 doChlog() {
67 cp debian/changelog ${CHLOGBKP}
68 debchange -v ${BASEVERSION}-${REPOVERSION} "${CHANGELOG}" || return 1
71 doBuild() {
72 ARGS=""
73 if [ -n "${WM_GPG_KEY}" ]; then
74 ARGS="-k${WM_GPG_KEY}"
76 fakeroot dpkg-buildpackage $ARGS >>${BUILDLOG} 2>&1
79 install -d `dirname $BUILDLOG`
80 >$BUILDLOG
81 trap 'cleanup; exit 2' 2
82 trap 'cleanup; exit 2' 9
83 trap 'cleanup; exit 2' 15
85 test -d debian || errorExit "This script must be called from the toplevel source dir, ./debian must exist."
87 #git status | grep modified: | awk '{ print $3 }' | xargs git checkout
88 git checkout -f >/dev/null
89 RC=0
90 if doPull ; then
91 doEnv
92 doChlog || errorExit "Error adding new changelog entry."
93 doBuild || errorExit "Error during build of .deb package."
94 else
95 RC=1
98 cleanup
99 exit $RC