#!/bin/bash # Copyright (c) 2003 Vinai Kopp # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # configuration section # the path to the diff file PATCHFILE=/path/to/exim-tls-to-exim-tls-mysql.diff # directory to build the new deb in # all temporary files will be deleted when finished TMPDIR="/tmp" # your name and email # escape any special characters - it is used in a perl regex MAINT="Your Name " # you probably don't need to change any of the rest # in this directory the new deb will be placed DESTDIR=$(pwd) # in these three files the current status of the build process is kept # they are read by the script on the server STATUSFILE=$DESTDIR/status LOGFILE=$DESTDIR/log RESFILE=$DESTDIR/res # end config # internaly used variables DIR="" VERSION="" SEQ=0 PATH=/bin:/usr/bin:/usr/local/bin export PATH # # functions # cleanup() { if [ -d $TMPDIR ]; then rm -rf $TMPDIR fi } log() { echo -e "$(date)\t $1" >> $LOGFILE } set-status() { echo $1 > $STATUSFILE } # # start of script # if [ "$UID" == "0" ]; then echo "Don't run this script as root!" >&2 set-status "error" exit 1 fi if [ -f $LOGFILE ]; then rm $LOGFILE; fi log "starting..." set-status "preparing" while [ -e "$TMPDIR/rebuild-exim-$SEQ" ]; do SEQ=$((SEQ +1)) done TMPDIR="$TMPDIR/rebuild-exim-$SEQ" mkdir -p $TMPDIR cd $TMPDIR log "updating file list" sudo /usr/bin/apt-get update log "downloading sources to directory is $TMPDIR" apt-get source exim-tls for i in exim-tls*; do if [ -f $i ]; then if echo $i | egrep -qs 'exim-tls_.+.orig.tar.gz'; then mmv 'exim-tls_*.orig.tar.gz' 'exim-tls-mysql_#1.orig.tag.gz' fi elif [ -d $i ]; then if echo $i | egrep -qs 'exim-tls-.*'; then VERSION=$(echo $i | cut -d '-' -f 3); DIR="exim-tls-mysql-${VERSION}" mv $i $DIR fi fi done log "upstream version: $VERSION" if [ -z "$DIR" ]; then log "source directory $DIR not found!" set-status "error" cleanup exit 1 fi cd $DIR log "patching exim source package." patch -p1 < $PATCHFILE if [ $? -gt 1 ]; then log "exim-tls-to-exim-tls-mysql.diff patch failed" set-status error cleanup exit 1 fi log "patching changelog" perl -pi -e 'if (!$a && /^exim-tls /) { $a++; s/^exim-tls /exim-tls-mysql /; } elsif (1 == $a && /^ -- .+<[^@]+@[^>]+>/) {$a++;s/-- .+<[^@]+@[^>]+>/-- '$MAINT'/; }' debian/changelog log "starting build of exim-tls-mysql" set-status "building" dpkg-buildpackage -rfakeroot -us -uc cd .. DEB=$(ls *.deb 2>/dev/null) if [ ! -f $DEB ]; then log "Can't fin deb $DEB" set-status "error" cleanup exit 1 fi mv $DEB $DESTDIR log "created $DESTDIR/$DEB" cd $DESTDIR log "Removing temporary files" cleanup set-status "ok" echo -n "$DEB" > $RESFILE log "done" exit 0