source: scripts/autobuild.bash @ 2332

Revision 2332, 11.4 KB checked in by alanbach-guest, 7 years ago (diff)

Added --ignore=wrongdistribution for reprepro

  • Property svn:executable set to *
Line 
1#!/bin/bash
2# Helper bash script to build debian biarch i386 and amd64 packages from SVN
3# Requires: subversion, devcripts, svn-buildpackage, pbuilder, awk, reprepro, sed, gnupg
4# Coyright 2007 Alan Baghumian / GNU/GPL
5#
6# Created: 2007-10-20 15:10 +330 GMT
7# Updated: 2007-10-25 11:13 +330 GMT
8#
9# TODO:
10# 1) bz2 packages?
11# 2) Automated emails
12
13SVN_REPO_PATH="/svn/pkg-parsix/pkg/"
14LOCAL_REPO_PATH="/home/parsix/public_html/packages/pool"
15LOCAL_REPO_ROOT="/home/parsix/public_html/packages/"
16APT_MIRROR="ftp://ftp.de.debian.org/debian"
17SRC_PKG_NAME="$1"
18DIST_NAME="$2"
19UNDERLINE=$'\137' # 137 is octal ASCII code for '_'
20
21# Security?
22GPG_KEY="26DB05E5"
23GPG_PASS="blahblah!"
24
25# Define some colors
26GREEN="[1;32m"
27YELLOW="[1;33m"
28BLUE="[1;34m"
29MAGENTA="[1;35m"
30CYAN="[1;36m"
31WHITE="[1;37m"
32RED="[1;31m"
33NORMAL="[0;39m"
34
35# Define core functions
36
37# Reverts /etc/pbuilderrc base.tgz changes
38revert_pbrc()
39{
40sed -i s/base-$PXBUILDARCH.tgz/base.tgz/g /etc/pbuilderrc
41}
42
43# Fixes /etc/pbuilderrc base.tgz
44fix_pbrc()
45{
46sed -i s/base.tgz/base-$PXBUILDARCH.tgz/g /etc/pbuilderrc
47}
48
49# Builds or updates needed chroots
50handle_chroot()
51{
52if [ ! -f /var/cache/pbuilder/base-$PXBUILDARCH.tgz ]; then
53    echo "${GREEN}Creating ${YELLOW}$PXBUILDARCH${NORMAL} ${GREEN}chroot...${NORMAL}"
54    pbuilder --create --distribution lenny --override-config --debootstrap debootstrap --debootstrapopts --arch --debootstrapopts $PXBUILDARCH --logfile $LOG_FILE --mirror $APT_MIRROR --othermirror "deb http://parsix.org/packages ramon main contrib non-free" &> /dev/null || exit
55else
56    echo "${GREEN}Updating ${YELLOW}$PXBUILDARCH${NORMAL} ${GREEN}chroot...${NORMAL}"
57    pbuilder --update --distribution lenny --override-config --debootstrap debootstrap --debootstrapopts --arch --debootstrapopts $PXBUILDARCH --logfile $LOG_FILE --mirror $APT_MIRROR --othermirror "deb http://parsix.org/packages ramon main contrib non-free" &> /dev/null || exit
58fi
59}
60
61# This takes three arguments: the name of the file to sign, the key
62# or maintainer name to use and password. Based On Debian's debsign
63signfile () {
64    signcommand="gpg"
65    signinterface="gpg"
66    if [ $signinterface = gpg ]
67    then
68        gpgversion=`gpg --version | head -n 1 | cut -d' ' -f3`
69        gpgmajorversion=`echo $gpgversion | cut -d. -f1`
70        gpgminorversion=`echo $gpgversion | cut -d. -f2`
71        if [ $gpgmajorversion -gt 1 -o $gpgminorversion -ge 4 ]
72        then
73                (cat "$1" ; echo "") | \
74                    $signcommand --passphrase "$3" --local-user "$2" --clearsign \
75                    --list-options no-show-policy-urls \
76                    --armor --textmode --output - - > "$1.asc" || exit
77        else
78                (cat "$1" ; echo "") | \
79                    $signcommand --passphrase "$3" --local-user "$2" --clearsign \
80                        --no-show-policy-url \
81                        --armor --textmode --output - - > "$1.asc" || exit
82        fi
83    else
84        $signcommand -u "$2" +clearsig=on -fast < "$1" > "$1.asc"
85    fi
86
87    echo
88    PRECIOUS_FILES=$(($PRECIOUS_FILES + 1))
89    mv -f -- "$1.asc" "$1"
90}
91
92# Checking required inputs
93if [ -z "$1" ]; then
94    echo "${GREEN}Couldn't detect source package name, exiting...${NORMAL}"
95    exit
96fi
97
98if [ -z "$2" ]; then
99    echo "${GREEN}Couldn't detect distro name, exiting...${NORMAL}"
100    exit
101fi
102
103cd $LOCAL_REPO_PATH
104POOL=`find ./ -type d | grep $SRC_PKG_NAME | awk 'BEGIN{FS="/"}{print $3}'`
105
106cd $SVN_REPO_PATH
107COMPONENT=`find ./ -maxdepth 2 -type d | grep /$SRC_PKG_NAME$ | awk 'BEGIN{FS="/"}{print $2}'`
108
109if [ ! -z "$COMPONENT" ]; then
110    echo "${GREEN}Detected component: ${YELLOW}$COMPONENT${NORMAL}"
111else
112    echo "${GREEN}Couldn't detect component, exiting...${NORMAL}"
113    exit
114fi
115
116# Check if package exists on the SVN repo
117if [ -d $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME ]; then
118    cd $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME
119else
120    # Local working copy is out dated?
121    svn up &> /dev/null
122    if [ -d $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME ]; then
123         cd $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME
124    else
125         echo "${GREEN}SVN directory does not exists, exiting...${NORMAL}"
126         exit
127    fi
128fi
129
130if [ ! -f trunk/debian/watch ]; then
131    echo "${GREEN}Can't find watch file, exiting...${NORMAL}"
132    exit
133fi
134
135# Update SVN to the latest version
136rm trunk/debian/control* &> /dev/null
137svn up &> /dev/null
138
139echo "${GREEN}Parsing changelog to get the latest prepared version...${NORMAL} "
140PKG_VERSION=`dpkg-parsechangelog -ltrunk/debian/changelog  | grep Version | awk 'BEGIN{FS=": "}{print $2}' | awk 'BEGIN{FS="-"}{print $1}' | awk 'BEGIN{FS=" "}{print $1}'`
141PKG_REVISION=`dpkg-parsechangelog -ltrunk/debian/changelog  | grep Version | awk 'BEGIN{FS=": "}{print $2}' | awk 'BEGIN{FS="-"}{print $2}'`
142echo "${YELLOW}$PKG_VERSION-$PKG_REVISION${NORMAL}"
143
144echo "${GREEN}Getting the latest upstream version...${NORMAL}"
145UPSTREAM_VERSION=`uscan --report --dehs --check-dirname-level 0 trunk/ | grep upstream-version | awk 'BEGIN{FS=">"}{print $2}' | awk 'BEGIN{FS="<"}{print $1}'`
146UPSTREAM_TARBALL_URL=`uscan --report --dehs --check-dirname-level 0 trunk/ | grep upstream-url | awk 'BEGIN{FS=">"}{print $2}' | awk 'BEGIN{FS="<"}{print $1}'`
147
148if [ ! -z `echo "$PKG_VERSION" | awk 'BEGIN{FS=":"}{print $2}'` ]; then
149   PKG_VERSION=`echo "$PKG_VERSION" | awk 'BEGIN{FS=":"}{print $2}'`
150fi
151
152if [ ! "$UPSTREAM_VERSION" = "$PKG_VERSION" ]; then
153   UPSTREAM_VERSION="$PKG_VERSION"
154   echo "${YELLOW}Prepared $UPSTREAM_VERSION${NORMAL}"
155else
156   echo "${YELLOW}$UPSTREAM_VERSION${NORMAL}"
157fi
158
159# Log filename
160LOG_FILE="$LOCAL_REPO_ROOT../buildlogs/$SRC_PKG_NAME$UNDERLINE$UPSTREAM_VERSION-$PKG_REVISION.log"
161LOG_PATH="$LOCAL_REPO_ROOT../buildlogs"
162
163# Clean up old logs
164rm $LOG_PATH/$SRC_PKG_NAME* &> /dev/null
165
166# clean up untarred packages
167rm -r $SRC_PKG_NAME-* &> /dev/null
168rm -r build-area/* &> /dev/null
169rm *.tar.gz &> /dev/null
170
171# Make tarballs
172mkdir -p tarballs &> /dev/null
173mkdir -p build-area &> /dev/null
174
175if [ -f $LOCAL_REPO_PATH/$COMPONENT/$POOL/$SRC_PKG_NAME/$SRC_PKG_NAME$UNDERLINE$UPSTREAM_VERSION.orig.tar.gz ]; then
176    echo "${GREEN}Copying orig tarball to the tarballs directory...${NORMAL}"
177    cp $LOCAL_REPO_PATH/$COMPONENT/$POOL/$SRC_PKG_NAME/$SRC_PKG_NAME$UNDERLINE$UPSTREAM_VERSION.orig.tar.gz tarballs/ -v >> $LOG_FILE
178else
179    # try to get upstream tarball using uscan
180    uscan --rename --no-dehs --check-dirname-level 0 trunk/ >> $LOG_FILE
181
182    # if fails, try classic manual way
183    if [ ! -f $SRC_PKG_NAME$UNDERLINE$UPSTREAM_VERSION.orig.tar.gz ]; then
184       wget -c $UPSTREAM_TARBALL_URL &> /dev/null
185       FRESH_TARBALL=`ls | grep .tar.gz$`
186
187       if [ ! -z "$FRESH_TARBALL" ]; then
188          mv $FRESH_TARBALL $SRC_PKG_NAME$UNDERLINE$UPSTREAM_VERSION.orig.tar.gz -v >> $LOG_FILE
189       else
190          echo "${GREEN}Can't find fresh tarball file, exiting...${NORMAL}"
191          echo "Can't find fresh tarball file, exiting..." >> $LOG_FILE
192          exit
193       fi
194    fi
195
196    echo "${GREEN}Copying orig tarball to the local apt repo...${NORMAL}"
197    cp *.orig.tar.gz $LOCAL_REPO_PATH/$COMPONENT/$POOL/$SRC_PKG_NAME/ -v >> $LOG_FILE
198
199    # Copy tarball
200    cp *.orig.tar.gz tarballs/ -v >> $LOG_FILE
201
202    # Clean up untarred packages
203    rm -r $SRC_PKG_NAME-* &> /dev/null
204fi
205
206# Check if both tarballs exist
207if [ ! -f tarballs/$SRC_PKG_NAME$UNDERLINE$UPSTREAM_VERSION.orig.tar.gz ]; then
208     echo "${RED}Source tarball not found${NORMAL}" && exit
209fi
210
211if [ ! -f $LOCAL_REPO_PATH/$COMPONENT/$POOL/$SRC_PKG_NAME/$SRC_PKG_NAME$UNDERLINE$UPSTREAM_VERSION.orig.tar.gz ]; then
212     echo "${RED}Source tarball not found on repo${NORMAL}" && exit
213fi
214
215# Goto trunk to start build
216cd trunk/
217
218# Fixing /etc/pbuilderrc base.tgz
219PXBUILDARCH="amd64"
220fix_pbrc
221
222# Build amd64 chroot if needed
223handle_chroot
224
225# Build amd64 packages
226echo "${GREEN}Building ${YELLOW}amd64${NORMAL} ${GREEN}specific packages...${NORMAL}"
227svn-buildpackage --svn-noninteractive --svn-builder="pdebuild --use-pdebuild-internal -- --logfile $LOG_FILE" || exit
228
229# Revert /etc/pbuilderrc base.tgz changes
230revert_pbrc
231
232# Check if the result is platform independent and skip i386 build if needed
233ARCH_ALL_COUNT="$(ls ../build-area/ | grep -c _all.deb)"
234ARCH_I386_COUNT="$(ls ../build-area/ | grep -c _i386.deb)"
235ARCH_AMD64_COUNT="$(ls ../build-area/ | grep -c _amd64.deb)"
236
237if [ $ARCH_ALL_COUNT -gt 0 -a $ARCH_I386_COUNT -lt 1 -a $ARCH_AMD64_COUNT -lt 1 ]; then
238    echo "${GREEN}Build is platform independent, skipping ${YELLOW}i386${NORMAL} ${GREEN}build...${NORMAL}"
239    ARCH_INDEP=1
240else
241    ARCH_INDEP=0
242    # Fixing /etc/pbuilderrc base.tgz
243    PXBUILDARCH="i386"
244    fix_pbrc
245
246    # Build i386 chroot if needed
247    handle_chroot
248
249    # Restore default controls
250    rm debian/control* &> /dev/null
251    svn up &> /dev/null
252
253    # Build i386 packages
254    echo "${GREEN}Building ${YELLOW}i386${NORMAL} ${GREEN}specific packages...${NORMAL}"
255    svn-buildpackage --svn-noninteractive --svn-builder="pdebuild --use-pdebuild-internal --debbuildopts -B -- --logfile $LOG_FILE" || exit
256
257    # Revert /etc/pbuilderrc base.tgz changes
258    revert_pbrc
259fi
260
261cd ../build-area/
262
263if [ $ARCH_INDEP -eq 0 ]; then
264    echo "${GREEN}Signing and adding ${YELLOW}multi_arch${NORMAL} ${GREEN}packages to the APT repository...${NORMAL}"
265
266    # Merging changes file for multiarch upload
267    AMD64_CHANGES=`ls | grep _amd64.changes`
268    I386_CHANGES=`ls | grep _i386.changes`
269    mergechanges -f $AMD64_CHANGES $I386_CHANGES >> $LOG_FILE
270
271    CHANGES_FILE=`ls | grep _multi.changes$`
272    DSC_FILE=`ls | grep .dsc$`
273
274    if [ -z "$CHANGES_FILE" ]; then
275        echo "${GREEN}No ${YELLOW}changes${NORMAL} ${GREEN}file?${NORMAL}"
276        echo "No changes file" >> $LOG_FILE
277        echo "Build failed" >> $LOG_FILE
278        exit
279    fi
280
281    DSC_OLDMD5SUM=`md5sum $DSC_FILE | awk '{print $1}'`
282    DSC_OLDSIZE=`ls -l $DSC_FILE | awk '{print $5}'`
283
284    # Sign dsc file
285    signfile "$DSC_FILE" "$GPG_KEY" "$GPG_PASS"
286   
287    DSC_MD5SUM=`md5sum $DSC_FILE | awk '{print $1}'`
288    DSC_SIZE=`ls -l $DSC_FILE | awk '{print $5}'`
289
290    sed -i s/"$DSC_OLDMD5SUM"/"$DSC_MD5SUM"/g $CHANGES_FILE || exit
291    sed -i s/"$DSC_OLDSIZE"/"$DSC_SIZE"/g $CHANGES_FILE || exit
292
293    # Sign changes file
294    signfile "$CHANGES_FILE" "$GPG_KEY" "$GPG_PASS"
295
296    # Add package to the repo
297    cd $LOCAL_REPO_ROOT
298    reprepro -Vb --ignore=wrongdistribution . include $DIST_NAME $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME/build-area/$CHANGES_FILE >> $LOG_FILE
299else
300    echo "${GREEN}Signing and adding ${YELLOW}plat_indep${NORMAL} ${GREEN}packages to the APT repository...${NORMAL}"
301
302    CHANGES_FILE=`ls | grep _amd64.changes$`
303 
304    if [ -z "$CHANGES_FILE" ]; then
305        CHANGES_FILE=`ls | grep _i386.changes$`
306    fi
307
308    if [ -z "$CHANGES_FILE" ]; then
309        echo "${GREEN}No ${YELLOW}changes${NORMAL} ${GREEN}file?${NORMAL}"
310        echo "No changes file" >> $LOG_FILE
311        echo "Build failed" >> $LOG_FILE
312        exit
313    fi
314 
315    DSC_FILE=`ls | grep .dsc$`
316
317    DSC_OLDMD5SUM=`md5sum $DSC_FILE | awk '{print $1}'`
318    DSC_OLDSIZE=`ls -l $DSC_FILE | awk '{print $5}'`
319
320    # Sign dsc file
321    signfile "$DSC_FILE" "$GPG_KEY" "$GPG_PASS"
322 
323    DSC_MD5SUM=`md5sum $DSC_FILE | awk '{print $1}'`
324    DSC_SIZE=`ls -l $DSC_FILE | awk '{print $5}' `
325 
326    sed -i s/"$DSC_OLDMD5SUM"/"$DSC_MD5SUM"/g $CHANGES_FILE || exit
327    sed -i s/"$DSC_OLDSIZE"/"$DSC_SIZE"/g $CHANGES_FILE || exit
328
329    # Sign changes file
330    signfile "$CHANGES_FILE" "$GPG_KEY" "$GPG_PASS"
331 
332    # Add package to the repo
333    cd $LOCAL_REPO_ROOT
334    reprepro -Vb --ignore=wrongdistribution . include $DIST_NAME $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME/build-area/$CHANGES_FILE >> $LOG_FILE
335fi
336
337# Sign release files
338sh ../../sign >> $LOG_FILE && cd
339
340echo "${GREEN}Finished.${NORMAL}"
341echo "Build OK" >> $LOG_FILE
342
Note: See TracBrowser for help on using the repository browser.