source: scripts/autobuild.bash @ 2273

Revision 2273, 7.9 KB checked in by alanbach-guest, 6 years ago (diff)

implemented platform-indep builds, svn update and core functions

  • 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: svn-buildpackage, pbuilder, awk, reprepro, sed
4# Coyright 2007 Alan Baghumian / GNU/GPL
5#
6# Created: 2007-10-20 15:10 +330 GMT
7# Updated: 2007-10-22 08:55 +330 GMT
8#
9# TODO:
10# 1) Queue support to automate build process
11# 2) bz2 packages?
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# Define some colors
22GREEN="[1;32m"
23YELLOW="[1;33m"
24BLUE="[1;34m"
25MAGENTA="[1;35m"
26CYAN="[1;36m"
27WHITE="[1;37m"
28RED="[1;31m"
29NORMAL="[0;39m"
30
31# Define core functions
32
33# Reverts /etc/pbuilderrc base.tgz changes
34revert_pbrc()
35{
36sed -i s/base-$PXBUILDARCH.tgz/base.tgz/g /etc/pbuilderrc
37}
38
39# Fixes /etc/pbuilderrc base.tgz
40fix_pbrc()
41{
42sed -i s/base.tgz/base-$PXBUILDARCH.tgz/g /etc/pbuilderrc
43}
44
45# Builds or updates needed chroots
46handle_chroot()
47{
48if [ ! -f /var/cache/pbuilder/base-$PXBUILDARCH.tgz ]; then
49    echo "${GREEN}Creating ${YELLOW}$PXBUILDARCH${NORMAL} ${GREEN}chroot...${NORMAL}"
50    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 || echo "Build failed" >> $LOG_FILE && revert_pbrc && exit
51else
52    echo "${GREEN}Updating ${YELLOW}$PXBUILDARCH${NORMAL} ${GREEN}chroot...${NORMAL}"
53    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 || echo "Build failed" >> $LOG_FILE && revert_pbrc && exit
54fi
55}
56
57# Checking required inputs
58if [ -z "$1" ]; then
59    echo "${GREEN}Couldn't detect source package name, exiting...${NORMAL}"
60    exit
61fi
62
63if [ -z "$2" ]; then
64    echo "${GREEN}Couldn't detect distro name, exiting...${NORMAL}"
65    exit
66fi
67
68cd $LOCAL_REPO_PATH
69POOL=`find ./ -type d | grep $SRC_PKG_NAME | awk 'BEGIN{FS="/"}{print $3}'`
70
71cd $SVN_REPO_PATH
72COMPONENT=`find ./ -maxdepth 2 -type d | grep /$SRC_PKG_NAME | awk 'BEGIN{FS="/"}{print $2}'`
73
74if [ ! -z "$COMPONENT" ]; then
75    echo "${GREEN}Detected component: ${YELLOW}$COMPONENT${NORMAL}"
76else
77    echo "${GREEN}Couldn't detect component, exiting...${NORMAL}"
78    exit
79fi
80
81# Check if package exists on the SVN repo
82if [ -d $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME ]; then
83    cd $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME
84else
85    # Local working copy is out dated?
86    svn up &> /dev/null
87    if [ -d $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME ]; then
88         cd $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME
89    else
90         echo "${GREEN}SVN directory does not exists, exiting...${NORMAL}"
91         exit
92    fi
93fi
94
95if [ ! -f trunk/debian/watch ]; then
96    echo "${GREEN}Can't find watch file, exiting...${NORMAL}"
97    exit
98fi
99
100# FIXME
101chmod +x trunk/debian/rules
102rm trunk/debian/control* &> /dev/null
103
104# Update SVN to the latest version
105svn up &> /dev/null
106
107echo "${GREEN}Parsing changelog to get the latest prepared version...${NORMAL} "
108PKG_VERSION=`dpkg-parsechangelog -ltrunk/debian/changelog  | grep Version | awk 'BEGIN{FS=": "}{print $2}' | awk 'BEGIN{FS="-"}{print $1}' | awk 'BEGIN{FS=" "}{print $1}'`
109PKG_REVISION=`dpkg-parsechangelog -ltrunk/debian/changelog  | grep Version | awk 'BEGIN{FS=": "}{print $2}' | awk 'BEGIN{FS="-"}{print $2}'`
110echo "${YELLOW}$PKG_VERSION-$PKG_REVISION${NORMAL}"
111
112echo "${GREEN}Getting the latest upstream...${NORMAL}"
113UPSTREAM_VERSION=`uscan --report --dehs --check-dirname-level 0 trunk/ | grep upstream-version | awk 'BEGIN{FS=">"}{print $2}' | awk 'BEGIN{FS="<"}{print $1}'`
114UPSTREAM_TARBALL_URL=`uscan --report --dehs --check-dirname-level 0 trunk/ | grep upstream-url | awk 'BEGIN{FS=">"}{print $2}' | awk 'BEGIN{FS="<"}{print $1}'`
115echo "${YELLOW}$UPSTREAM_VERSION${NORMAL}"
116
117# Log filename
118LOG_FILE="$LOCAL_REPO_ROOT../buildlogs/$SRC_PKG_NAME$UNDERLINE$UPSTREAM_VERSION-$PKG_REVISION.log"
119LOG_PATH="$LOCAL_REPO_ROOT../buildlogs"
120
121# Clean up old logs
122rm $LOG_PATH/$SRC_PKG_NAME* &> /dev/null
123
124# clean up untarred packages
125rm -r $SRC_PKG_NAME-* &> /dev/null
126rm -r build-area/* &> /dev/null
127rm *.tar.gz &> /dev/null
128
129# try to get upstream tarball using uscan
130uscan --rename --no-dehs --check-dirname-level 0 trunk/ >> $LOG_FILE
131
132# if fails, try classic manual way
133if [ ! -f $SRC_PKG_NAME$UNDERLINE$UPSTREAM_VERSION.orig.tar.gz ]; then
134       wget -c $UPSTREAM_TARBALL_URL &> /dev/null || exit 1
135       mv `ls | grep tar.gz` $SRC_PKG_NAME$UNDERLINE$UPSTREAM_VERSION.orig.tar.gz -v >> $LOG_FILE
136fi
137
138echo "${GREEN}Copying orig tarball to the local apt repo...${NORMAL}"
139cp *.orig.tar.gz $LOCAL_REPO_PATH/$COMPONENT/$POOL/$SRC_PKG_NAME/ -v >> $LOG_FILE
140
141# Make tarballs
142mkdir -p tarballs &> /dev/null
143mkdir -p build-area &> /dev/null
144
145# Copy tarball
146cp *.orig.tar.gz tarballs/ -v >> $LOG_FILE
147
148# Clean up untarred packages
149rm -r $SRC_PKG_NAME-* &> /dev/null
150
151# Check if both tarballs exist
152if [ ! -f tarballs/$SRC_PKG_NAME$UNDERLINE$UPSTREAM_VERSION.orig.tar.gz ]; then
153     echo "${RED}Source tarball not found${NORMAL}" && echo "Build failed" >> $LOG_FILE && exit
154fi
155
156if [ ! -f $LOCAL_REPO_PATH/$COMPONENT/$POOL/$SRC_PKG_NAME/$SRC_PKG_NAME$UNDERLINE$UPSTREAM_VERSION.orig.tar.gz ]; then
157     echo "${RED}Source tarball not found on repo${NORMAL}" && echo "Build failed" >> $LOG_FILE && exit
158fi
159
160# Goto trunk to start build
161cd trunk/
162
163# Fixing /etc/pbuilderrc base.tgz
164PXBUILDARCH="amd64"
165fix_pbrc
166
167# Build amd64 chroot if needed
168handle_chroot
169
170# Build amd64 packages
171echo "${GREEN}Building ${YELLOW}amd64${NORMAL} ${GREEN}specific packages...${NORMAL}"
172svn-buildpackage --svn-builder="pdebuild --use-pdebuild-internal -- --logfile $LOG_FILE" || echo "Build failed" >> $LOG_FILE && revert_pbrc && exit
173
174# Revert /etc/pbuilderrc base.tgz changes
175revert_pbrc
176
177# Check if the result is platform independent and skip i386 build if needed
178ARCH_ALL_COUNT="$(ls ../build-area/ | grep -c _all.deb)"
179ARCH_I386_COUNT="$(ls ../build-area/ | grep -c _i386.deb)"
180ARCH_AMD64_COUNT="$(ls ../build-area/ | grep -c _amd64.deb)"
181
182if [ $ARCH_ALL_COUNT -gt 1 -a $ARCH_I386_COUNT -lt 1 -a $ARCH_AMD64_COUNT -lt 1 ]; then
183    echo "${GREEN}Build is platform independent, skipping ${YELLOW}i386${NORMAL} build...${NORMAL}"
184    ARCH_INDEP=1
185else
186    ARCH_INDEP=0
187    # Fixing /etc/pbuilderrc base.tgz
188    PXBUILDARCH="i386"
189    fix_pbrc
190
191    # Build i386 chroot if needed
192    handle_chroot
193
194    # Restore default controls
195    rm debian/control* &> /dev/null
196    svn up &> /dev/null
197
198    # Build i386 packages
199    echo "${GREEN}Building ${YELLOW}i386${NORMAL} ${GREEN}specific packages...${NORMAL}"
200    svn-buildpackage --svn-builder="pdebuild --use-pdebuild-internal --debbuildopts -B -- --logfile $LOG_FILE" || echo "Build failed" >> $LOG_FILE && revert_pbrc  && exit
201
202    # Revert /etc/pbuilderrc base.tgz changes
203    revert_pbrc
204fi
205
206cd ../build-area/
207
208if [ $ARCH_INDEP -eq 1 ]; then
209    echo "${GREEN}Generating ${YELLOW}multi_arch${NORMAL} ${GREEN}changes file and centralizing packages...${NORMAL}"
210
211    # Merging changes file for multiarch upload
212    AMD64_CHANGES=`ls | grep _amd64.changes`
213    I386_CHANGES=`ls | grep _i386.changes`
214    mergechanges -f $AMD64_CHANGES $I386_CHANGES >> $LOG_FILE
215
216    # Add package to the repo
217    cd $LOCAL_REPO_ROOT
218    reprepro -Vb . include $DIST_NAME $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME/build-area/`ls $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME/build-area/ | grep _multi.changes` >> $LOG_FILE
219else
220    # Add package to the repo
221    cd $LOCAL_REPO_ROOT
222    reprepro -Vb . include $DIST_NAME $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME/build-area/`ls $SVN_REPO_PATH/$COMPONENT/$SRC_PKG_NAME/build-area/ | grep _amd64.changes` >> $LOG_FILE
223fi
224
225sh ../../sign >> $LOG_FILE && cd
226
227echo "${GREEN}Finished.${NORMAL}"
228echo "Build OK" >> $LOG_FILE
229
230
Note: See TracBrowser for help on using the repository browser.