Prepare new Debian package to fix missing default webjumps
[conkeror/arlinius.git] / contrib / debian / nightlybuild.sh
blob97899cfa5113a9080387bc241f0fe195caea132d
1 #!/bin/sh
3 # Script for nightly builds of conkeror .debs
5 # Inspired by an idea of Nicholas A. Zigarovich <nick@servo.cc>
6 # Code by Axel Beckert <abe@deuxchevaux.org>
8 # Copyright (C) 2009, 2010 Axel Beckert <abe@deuxchevaux.org>
10 # Needs the following Debian packages and their dependencies installed
11 # (besides "required" packages like coreutils and conkeror build
12 # dependencies) to work: devscripts, git-core
14 # If you want to use all features of this script, you need also the
15 # following packages: gnupg, openssh-client, dctrl-tools, gzip, bzip2
17 # And on the machine hosting the APT repository, you'll need the
18 # package reprepro.
20 # If you do only binary rebuilds for other architectures, you need to
21 # have the nightly builds APT repository in your /etc/apt/sources.list
22 # because we fetch the source package with
25 # How to use:
27 # Create the file ~/.conkeror-nightlybuildrc and write at least two
28 # lines like the following into it:
30 # WORKDIR=/path/to/the/directory/where/the/builds/should/happen
31 # CONTACT=you@example.com
33 # Example ~/.conkeror-nightlybuildrc similar to the one used for the
34 # initial builds on http://noone.org/conkeror-nightly-debs/:
36 # # -*- sh -*-
37 # WORKDIR=$HOME/conkeror.nightly
38 # CONTACT=abe+conkeror-nightly@noone.org
39 # SIGNKEY=373B76B4
40 # UPLOAD=yes
41 # UPLOAD_SSH_KEY=~/.ssh/id_rsa.conkeror-nightly
42 # UPLOAD_SSH_HOST=noone.org
43 # UPLOAD_SSH_USER=abe
44 # UPLOAD_SSH_DIR=http/htdocs/conkeror-nightly
45 # USE_REPREPRO=yes
47 # Example ~/.conkeror-nightlybuildrc similar to the one used for
48 # binary-only builds of conkeror-spawn-process-helper on
49 # http://noone.org/conkeror-nightly-debs/:
51 # # -*- sh -*-
52 # WORKDIR=$HOME/conkeror.nightly
53 # CONTACT=abe+conkeror-nightly@noone.org
54 # SIGNKEY=373B76B4
55 # UPLOAD=yes
56 # UPLOAD_SSH_KEY=~/.ssh/id_rsa.conkeror-nightly
57 # UPLOAD_SSH_HOST=noone.org
58 # UPLOAD_SSH_USER=abe
59 # UPLOAD_SSH_DIR=http/htdocs/conkeror-nightly
60 # USE_REPREPRO=yes
61 # BINARY_ONLY_BUILD=yes
62 # SOURCES_LIST_URL=http://noone.org/conkeror-nightly-debs/dists/lenny/main/source/Sources.gz
64 # I think the remaining variable names are quite self-explaining. If
65 # not, look at this script's source code (you're doing that already
66 # ;-) and see where they're used. It's not too hard, the script is
67 # fairly small and straight forward. ;-)
69 # Bail out on any error.
70 set -e
72 # Check for the the config file and read it
73 RCFILE=$HOME/.conkeror-nightlybuildrc
74 if [ ! -s $RCFILE ]; then
75 echo "$RCFILE does not exist or is empty"
76 exit 1
78 . $RCFILE
80 # Check if a working directory is defined. Bail out if not.
81 if [ -z "$WORKDIR" ]; then
82 echo '$WORKDIR must be defined in '$RCFILE
83 exit 2
86 # Check if a contact is defined. Set a dummy value if not.
87 if [ -z "$CONTACT" ]; then
88 CONTACT=package-builder-has-not-set-contact-address@example.com
91 # Check if $WORKDIR exists, otherwise create it.
92 if [ ! -d "$WORKDIR" ]; then
93 mkdir -p "$WORKDIR"
96 # Define places and version number
97 MASTERDIR=$WORKDIR/MASTER
98 BUILDDIR=$WORKDIR/BUILD
99 UNIXTIME=`date +%s`
100 DATE=`date -R`
102 # Create build dir
103 mkdir -p $BUILDDIR
105 # Remove old builds
106 rm -rf $BUILDDIR/*
108 # If we just rebuild a nightly snapshot for a new architecture, we
109 # fetch the list of source packages, extract the file name of the
110 # conkeror package out of it and download the appropriate conkeror
111 # source package with dget.
112 if [ "$BINARY_ONLY_BUILD" = "yes" ]; then
113 SOURCESTMP=`mktemp`
115 # Download Sources file
116 SOURCEENC="${SOURCES_LIST_URL##*.}"
117 if [ -n "$SOURCEENC" ]; then
118 SOURCESTMPENC=`mktemp`
119 wget -O $SOURCESTMPENC "$SOURCES_LIST_URL";
120 if [ "$SOURCEENC" = "gz" ]; then
121 zcat $SOURCESTMPENC > $SOURCESTMP
122 elif [ "$SOURCEENC" = "bz2" ]; then
123 bzcat $SOURCESTMPENC > $SOURCESTMP
124 else
125 echo Unsupported suffix $SOURCEENC in "$SOURCES_LIST_URL" 1>&2
126 exit 1;
128 rm -vf $SOURCESTMPENC
129 else
130 wget -O $SOURCESTMP "$SOURCES_LIST_URL";
133 # Find package in Sources file
134 INFOTMP=`mktemp`
135 grep-dctrl -S conkeror $SOURCESTMP | sort-dctrl -k Version:v - | \
136 grep-dctrl -s Checksums-Sha256,Directory conkeror - > $INFOTMP
137 rm -vf $SOURCESTMP
139 # Calculate source package URL
140 BASE_URL="`echo \"$SOURCES_LIST_URL\" | sed -e 's:/dists/.*$::'`"
141 POOL_DIR="`grep '^Directory:' $INFOTMP | awk '{print $2}'`"
142 DSC="${BASE_URL}/${POOL_DIR}/`grep '\.dsc$' $INFOTMP | awk '{print $3}'`"
144 # Download source package
145 cd "$BUILDDIR"
146 dget -u "$DSC"
148 # Determine the correct version
149 RELEASE="`gpg < \"${DSC##*/}\" 2>&1 | grep-dctrl -s Version conkeror - | \
150 awk '{print $2}'`"
151 VERSION="`echo \"$RELEASE\" | sed -e 's/-.*$//'`"
152 DATEDIR="$BUILDDIR/conkeror-$VERSION"
154 WHATTOBUILD=-B
155 else
156 # Check if MASTER directory exists, if not, create it (untested code!)
157 cd $WORKDIR
158 if [ ! -d $MASTERDIR ]; then
159 git clone git://repo.or.cz/conkeror.git $MASTERDIR
162 # Update master copy
163 cd $MASTERDIR
164 git pull
166 # Determine the correct version
167 VERSION=`grep ^Version= $MASTERDIR/application.ini | \
168 sed -e 's/^Version=//'`+git`date +%y%m%d`
169 RELEASE="$VERSION-~nightlybuild$UNIXTIME"
170 DATEDIR="$BUILDDIR/conkeror-$VERSION"
172 # Copy tree into build environment
173 cp -priv $MASTERDIR $DATEDIR
175 # Build orig.tar.gz
176 cd $BUILDDIR
177 tar cvzf conkeror_$VERSION.orig.tar.gz --exclude=.git conkeror-$VERSION
179 # Add an appropriate changelog entry
180 cd $DATEDIR/debian
181 mv changelog changelog.tmp
183 echo "conkeror ($RELEASE) UNRELEASED; urgency=low
185 * Automatically built package based on the state of
186 http://repo.or.cz/w/conkeror.git at $DATE
188 -- Conkeror Nightly Build <$CONTACT> $DATE
189 " > changelog
190 cat changelog.tmp >> changelog
191 rm changelog.tmp
194 # Set the right options for debuild (signed vs unsigned packages)
195 DEBUILDOPTIONS='-uc -us'
196 if [ ! -z "$SIGNKEY" ]; then
197 DEBUILDOPTIONS="-k$SIGNKEY"
200 # Build the package
201 cd $DATEDIR
202 debuild $DEBUILDOPTIONS $WHATTOBUILD -i'(?:^|/).*~$|(?:^|/)\.#.*$|(?:^|/)\..*\.swp$|(?:^|/),,.*(?:$|/.*$)|(?:^|/)(?:DEADJOE|\.cvsignore|\.arch-inventory|\.bzrignore|\.gitignore|\.hgignore)$|(?:^|/)(?:CVS|RCS|\.deps|\{arch\}|\.arch-ids|\.svn|\.hg|_darcs|\.git|\.shelf|_MTN|\.bzr(?:\.backup|tags)|update\.sh)(?:$|/.*$)'
204 # Upload the files
205 cd ..
207 if [ "$UPLOAD" = "yes" ]; then
208 if [ "$BINARY_ONLY_BUILD" = "yes" ]; then
209 scp -i $UPLOAD_SSH_KEY -p *build *deb *changes \
210 $UPLOAD_SSH_USER@$UPLOAD_SSH_HOST:$UPLOAD_SSH_DIR
211 if [ "$USE_REPREPRO" = "yes" ]; then
212 ssh -i $UPLOAD_SSH_KEY $UPLOAD_SSH_USER@$UPLOAD_SSH_HOST \
213 "cd $UPLOAD_SSH_DIR; reprepro -v includedeb lenny" *.deb "; reprepro -v includedeb sid" *.deb ";"
215 else
216 scp -i $UPLOAD_SSH_KEY -p *build *deb *changes *dsc *gz \
217 $UPLOAD_SSH_USER@$UPLOAD_SSH_HOST:$UPLOAD_SSH_DIR
219 if [ "$USE_REPREPRO" = "yes" ]; then
220 ssh -i $UPLOAD_SSH_KEY $UPLOAD_SSH_USER@$UPLOAD_SSH_HOST \
221 "cd $UPLOAD_SSH_DIR; reprepro -v includedeb lenny" *.deb "; reprepro -v includedeb sid" *.deb "; reprepro -v includedsc lenny " *.dsc "; reprepro -v includedsc sid " *.dsc ";"