Debian package: Declare compliance with Debian Policy 4.3.0
[conkeror.git] / contrib / debian / nightlybuild.sh
blob50d61e8e850bfcdd15f8db0659a8ed837f538f28
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-2011, 2014 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
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. Configure all distributions with "AlsoAcceptFor:
19 # UNRELEASED experimental unstable sid".
21 # If you do only binary rebuilds for other architectures, you do _not_
22 # need to have the nightly builds APT repository in your
23 # /etc/apt/sources.list since we fetch the Sources list manually,
24 # parse it with grep-dctrl and fetch the source package with dget.
27 # How to use:
29 # Create the file ~/.conkeror-nightlybuildrc and write at least two
30 # lines like the following into it:
32 # WORKDIR=/path/to/the/directory/where/the/builds/should/happen
33 # CONTACT=you@example.com
35 # Example ~/.conkeror-nightlybuildrc similar to the one used for the
36 # initial builds on http://noone.org/conkeror-nightly-debs/:
38 # # -*- sh -*-
39 # WORKDIR=$HOME/conkeror.nightly
40 # CONTACT=abe+conkeror-nightly@noone.org
41 # SIGNKEY=373B76B4
42 # UPLOAD=yes
43 # UPLOAD_SSH_KEY=~/.ssh/id_rsa.conkeror-nightly
44 # UPLOAD_SSH_HOST=noone.org
45 # UPLOAD_SSH_USER=abe
46 # UPLOAD_SSH_DIR=http/htdocs/conkeror-nightly
47 # USE_REPREPRO=yes
49 # Example ~/.conkeror-nightlybuildrc similar to the one used for
50 # binary-only builds of conkeror-spawn-process-helper on
51 # http://noone.org/conkeror-nightly-debs/:
53 # # -*- sh -*-
54 # WORKDIR=$HOME/conkeror.nightly
55 # CONTACT=abe+conkeror-nightly@noone.org
56 # SIGNKEY=373B76B4
57 # UPLOAD=yes
58 # UPLOAD_SSH_KEY=~/.ssh/id_rsa.conkeror-nightly
59 # UPLOAD_SSH_HOST=noone.org
60 # UPLOAD_SSH_USER=abe
61 # UPLOAD_SSH_DIR=http/htdocs/conkeror-nightly
62 # USE_REPREPRO=yes
63 # REPREPRO_DISTS="lenny squeeze sid"
64 # BINARY_ONLY_BUILD=yes
65 # SOURCES_LIST_URL=http://noone.org/conkeror-nightly-debs/dists/lenny/main/source/Sources.gz
67 # I think the remaining variable names are quite self-explaining. If
68 # not, look at this script's source code (you're doing that already
69 # ;-) and see where they're used. It's not too hard, the script is
70 # fairly small and straight forward. ;-)
72 # Bail out on any error.
73 set -e
75 # Check for the the config file and read it
76 RCFILE=$HOME/.conkeror-nightlybuildrc
77 if [ ! -s $RCFILE ]; then
78 echo "$RCFILE does not exist or is empty"
79 exit 1
81 . $RCFILE
83 # Check if a working directory is defined. Bail out if not.
84 if [ -z "$WORKDIR" ]; then
85 echo '$WORKDIR must be defined in '$RCFILE
86 exit 2
89 # Check if a contact is defined. Set a dummy value if not.
90 if [ -z "$CONTACT" ]; then
91 CONTACT=package-builder-has-not-set-contact-address@example.com
94 # Check if $WORKDIR exists, otherwise create it.
95 if [ ! -d "$WORKDIR" ]; then
96 mkdir -p "$WORKDIR"
99 # Define places and version number
100 MASTERDIR=$WORKDIR/MASTER
101 BUILDDIR=$WORKDIR/BUILD
102 DATE=`date -R`
103 ZULUTIME=`date -u +%y%m%d+%H%M`
105 # Create build dir
106 mkdir -p $BUILDDIR
108 # Remove old builds
109 rm -rf $BUILDDIR/*
111 # If we just rebuild a nightly snapshot for a new architecture, we
112 # fetch the list of source packages, extract the file name of the
113 # conkeror package out of it and download the appropriate conkeror
114 # source package with dget.
115 if [ "$BINARY_ONLY_BUILD" = "yes" ]; then
116 SOURCESTMP=`mktemp`
118 # Download Sources file
119 SOURCEENC="${SOURCES_LIST_URL##*.}"
120 if [ -n "$SOURCEENC" ]; then
121 SOURCESTMPENC=`mktemp`
122 wget -O $SOURCESTMPENC "$SOURCES_LIST_URL";
123 if [ "$SOURCEENC" = "gz" ]; then
124 zcat $SOURCESTMPENC > $SOURCESTMP
125 elif [ "$SOURCEENC" = "bz2" ]; then
126 bzcat $SOURCESTMPENC > $SOURCESTMP
127 else
128 echo Unsupported suffix $SOURCEENC in "$SOURCES_LIST_URL" 1>&2
129 exit 1;
131 rm -vf $SOURCESTMPENC
132 else
133 wget -O $SOURCESTMP "$SOURCES_LIST_URL";
136 # Find package in Sources file
137 INFOTMP=`mktemp`
138 grep-dctrl -S conkeror $SOURCESTMP | sort-dctrl -k Version:v - | \
139 grep-dctrl -s Checksums-Sha256,Directory conkeror - > $INFOTMP
140 rm -vf $SOURCESTMP
142 # Calculate source package URL
143 BASE_URL="`echo \"$SOURCES_LIST_URL\" | sed -e 's:/dists/.*$::'`"
144 POOL_DIR="`grep '^Directory:' $INFOTMP | awk '{print $2}'`"
145 DSC="${BASE_URL}/${POOL_DIR}/`grep '\.dsc$' $INFOTMP | awk '{print $3}'`"
147 # Download source package
148 cd "$BUILDDIR"
149 dget -u "$DSC"
151 # Determine the correct version
152 RELEASE="`gpg < \"${DSC##*/}\" 2>&1 | grep-dctrl -s Version conkeror - | \
153 awk '{print $2}'`"
154 VERSION="`echo \"$RELEASE\" | sed -e 's/-.*$//'`"
155 DATEDIR="$BUILDDIR/conkeror-$VERSION"
157 WHATTOBUILD=-B
158 else
159 # Check if MASTER directory exists, if not, create it (untested code!)
160 cd $WORKDIR
161 if [ ! -d $MASTERDIR ]; then
162 git clone git://repo.or.cz/conkeror.git $MASTERDIR
165 # Set the right options for debuild (signed vs unsigned packages)
166 DEBUILDOPTIONS='-uc -us'
167 if [ ! -z "$SIGNKEY" ]; then
168 DEBUILDOPTIONS="-k$SIGNKEY"
171 # Update master copy
172 cd $MASTERDIR
173 PULLOUTPUT=`git pull`
174 echo "$PULLOUTPUT"
175 # Only build if something changed
176 if echo "$PULLOUTPUT" | fgrep -q 'Already up-to-date.'; then
177 exit 0
179 git gc
181 # Determine the correct version
182 VERSION=`grep ^Version= $MASTERDIR/application.ini | \
183 sed -e 's/^Version=//;s/\(pre\)\([0-9]\)/~~\1-\2/;s/\(pre[^-]\)/~~\1/;s/\(rc\|b\|a\)/~\1/'`+git$ZULUTIME
184 RELEASE="$VERSION-~nightly1"
185 DATEDIR="$BUILDDIR/conkeror-$VERSION"
187 # Copy tree into build environment
188 cp -priv $MASTERDIR $DATEDIR
190 # Build orig.tar.gz
191 cd $BUILDDIR
192 tar cvzf conkeror_$VERSION.orig.tar.gz --exclude=.git conkeror-$VERSION
194 # Add an appropriate changelog entry
195 cd $DATEDIR/debian
196 mv changelog changelog.tmp
198 echo "conkeror ($RELEASE) UNRELEASED; urgency=low
200 * Automatically built package based on the state of
201 http://repo.or.cz/w/conkeror.git at $DATE
203 -- Conkeror Nightly Build <$CONTACT> $DATE
204 " > changelog
205 cat changelog.tmp >> changelog
206 rm changelog.tmp
209 # Set the right options for debuild (signed vs unsigned packages)
210 DEBUILDOPTIONS='-uc -us'
211 if [ ! -z "$SIGNKEY" ]; then
212 DEBUILDOPTIONS="-k$SIGNKEY"
215 # Build the package
216 cd $DATEDIR
217 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)(?:$|/.*$)'
219 # Upload the files
220 cd ..
222 if [ "$UPLOAD" = "yes" ]; then
223 if [ "$BINARY_ONLY_BUILD" = "yes" ]; then
224 scp -i $UPLOAD_SSH_KEY -p *build *deb *changes \
225 $UPLOAD_SSH_USER@$UPLOAD_SSH_HOST:$UPLOAD_SSH_DIR
226 if [ "$USE_REPREPRO" = "yes" ]; then
227 ssh -i $UPLOAD_SSH_KEY $UPLOAD_SSH_USER@$UPLOAD_SSH_HOST \
228 "cd $UPLOAD_SSH_DIR; for i in $REPREPRO_DISTS; do reprepro -v includedeb" '$i' *.deb "; done"
230 else
231 scp -i $UPLOAD_SSH_KEY -p *build *deb *changes *dsc *gz *xz \
232 $UPLOAD_SSH_USER@$UPLOAD_SSH_HOST:$UPLOAD_SSH_DIR
234 if [ "$USE_REPREPRO" = "yes" ]; then
235 ssh -i $UPLOAD_SSH_KEY $UPLOAD_SSH_USER@$UPLOAD_SSH_HOST \
236 "cd $UPLOAD_SSH_DIR; for i in $REPREPRO_DISTS; do reprepro -v include" '$i' *.changes "; done"