Add debianisation code and automatic build script
[wmaker-crm.git] / debian / nightly_build.sh
1 #!/bin/sh
2
3 CHLOGBKP="/tmp/$$-chlog"
4 BASEVERSION="0.93.0"
5 REPOVERSION="git-`date +%Y%m%d-%H%M`"
6
7 CHANGELOG="Automatic build from the GIT on `date`"
8 BUILDLOG="${HOME}/log/wmaker-nightly.log"
9
10 STATUSCMD="git log -1 --pretty=oneline"
11 PULLCMD="git pull"
12 FORCE="0"
13
14 if [ $# -gt 0 ]; then
15 case $1 in
16 -f|--force)
17 FORCE="1"
18 ;;
19 *)
20 echo "Usage $0 [-f|--force]"
21 exit 0
22 ;;
23 esac
24 fi
25
26 cleanup() {
27 mv ${CHLOGBKP} debian/changelog
28 }
29
30 errorExit() {
31 echo "$@" 1>&2
32 cleanup
33 exit 2
34 }
35
36 doPull() {
37 RC="1"
38 LATEST="`$STATUSCMD`"
39 $PULLCMD >>$BUILDLOG 2>&1 || errorExit "Error pulling from the repo"
40 CURRENT="`$STATUSCMD`"
41 if [ "$FORCE" = "1" -o "$LATEST" != "$CURRENT" ]; then
42 echo "last revision: $LATEST" >>$BUILDLOG
43 echo "new revision: $CURRENT" >>$BUILDLOG
44 echo "FORCE: $FORCE" >>$BUILDLOG
45 RC="0"
46 else
47 echo "No changes to build, and FORCE not given." >>$BUILDLOG
48 fi
49 return $RC
50 }
51
52 doEnv() {
53 for var in `env | grep GNUSTEP | sed "s/=.*//"`; do
54 unset $var
55 done
56 }
57
58 doChlog() {
59 cp debian/changelog ${CHLOGBKP}
60 debchange -v ${BASEVERSION}-${REPOVERSION} "${CHANGELOG}" || return 1
61 }
62
63 doBuild() {
64 ARGS=""
65 if [ -n "${WM_GPG_KEY}" ]; then
66 ARGS="-k${WM_GPG_KEY}"
67 fi
68 fakeroot dpkg-buildpackage $ARGS >>${BUILDLOG} 2>&1
69 }
70
71 install -d `dirname $BUILDLOG`
72 >$BUILDLOG
73 trap 'cleanup; exit 2' 2
74 trap 'cleanup; exit 2' 9
75 trap 'cleanup; exit 2' 15
76
77 test -d debian || errorExit "This script must be called from the toplevel source dir, ./debian must exist."
78
79 RC=0
80 if doPull ; then
81 doEnv
82 doChlog || errorExit "Error adding new changelog entry."
83 doBuild || errorExit "Error during build of .deb package."
84 else
85 RC=1
86 fi
87
88 cleanup
89 exit $RC