#!/bin/sh
#
# build the system for SuSE 9.3 - OpenSuSE 10.1 systems
#
# author: Johannes Weberhofer, May - July 2006
# licensed under the GPL
#
# ####################################################################
# modify settings here
# please ensure, that the BUILD_RPMS environment variable is set to a
# valid (Open)SuSE installation repository
# This variable should be set to a directory where all (S)RPMs will be
# copied to
QMAILRPM=`dirname ~/qmailrpm`/`basename ~/qmailrpm`
# no changes should be done below this point
# ####################################################################
function ShowHelp() {
echo "usage: `basename $0` --dry-run --clean --all --help
[--i586|--x86_64]"
echo " --dry-run don't build"
echo " --clean delete all build directories"
echo " --all build all rpms even those which already
have been built"
echo " --help this help screen"
echo " --i586|--x86_64 the architecture to build for (default
for your system is: $ARCH"
echo ""
echo "Please do not forget to set 'BUILD_RPMS' to a valid (Open)SuSE
installation repository. "
echo "Current default is set to: $BUILD_RPMS"
echo ""
echo "Before starting the build process, download the SRPMs to the
current directory"
echo ""
echo "The resulting (S)RPMs will be copied to $QMAILRPM"
echo "If you like to set another directory, please edit `basename $0`"
echo "------------"
echo "(c) Johannes Weberhofer <[EMAIL PROTECTED]>, May - July 2006,
Version 1.1"
echo " licensed under the GPL"
echo "------------"
exit 1
}
DRYRUN=0
CLEAN=0
ALL=0
SHOWHELP=0
while [ $# -ge 1 ] ; do
case "$1" in
--dry-run)
DRYRUN=1
;;
--clean)
CLEAN=1
;;
--all)
ALL=1
;;
--i586)
ARCH=i586
;;
--x86_64)
ARCH=x86_64
;;
*)
SHOWHELP=1
;;
esac
shift
done
if test $SHOWHELP -eq 1 ; then
ShowHelp
exit 1
fi
# test, if build - packages are installed
rpm -qa | grep -q '^build-'
if test $? -ne 0 ; then
echo
echo "ERROR: To use this package, please install the <build> package"
echo
exit 1
fi
if test -z "$ARCH" ; then
ARCH=`grep '(' /etc/SuSE-release | sed -e 's/[^(]*(// ; s/)// ; s/\-/_/
; s/X/x/ '`
fi
# here are the default SuSE RPM's located
DEFAULTRPM="$BUILD_RPMS"
SUSERELEASE=`grep VERSION /etc/SuSE-release | sed 's/VERSION = //'`
if test "$ARCH" == "i586" ; then
TOASTERTYPE=''
TOASTERARCH=''
else
TOASTERTYPE='64'
TOASTERARCH=' x86_64'
fi
SUSETOASTERRELEASE=`echo "$SUSERELEASE" | tr -d '.'`
if test $SUSETOASTERRELEASE -lt 101 ; then
SUSETOASTERRELEASE=100
fi
if test ! -d "$QMAILRPM/SuSE-$SUSERELEASE" ; then
mkdir -p "$QMAILRPM/SuSE-$SUSERELEASE"
fi
# ####################################################################
# and now build the packages
BUILDPKGS="daemontools-toaster ucspi-tcp-toaster vpopmail-toaster
libdomainkeys qmail-toaster courier-authlib-toaster courier-imap-toaster
autorespond-toaster control-panel-toaster ezmlm-toaster
qmailadmin-toaster qmailmrtg-toaster maildrop-toaster isoqlog-toaster
vqadmin-toaster squirrelmail-toaster spamassassin-toaster clamav-toaster
ripmime-toaster simscan-toaster djbdns"
for PACKAGE in $BUILDPKGS ; do
DIR=`ls $PACKAGE-*.src.rpm | tail -n1 | sed -e 's/.src.rpm//'`
if test $ALL -eq 1 -o ! -e
"$QMAILRPM/SuSE-$SUSERELEASE/RPMS/$ARCH/$DIR.$ARCH.rpm" -a ! -e
"$QMAILRPM/SuSE-$SUSERELEASE/RPMS/noarch/$DIR.noarch.rpm" ; then
echo
echo -e "\033[40m\033[001;031mPackage :
\033[40m\033[001;033m$PACKAGE\033[0m"
echo -e "\033[40m\033[001;031mBuilding for: \033[40m\033[001;033mSuSE
$SUSERELEASE\033[0m"
echo -e "\033[40m\033[001;031mArchitecture:
\033[40m\033[001;033m$ARCH\033[0m"
echo
if test ! -d "$DIR" ; then
mkdir "$DIR"
else
rm -rf "$DIR/*"
fi
pushd "$DIR" 2>&1 > /dev/null
unrpm "../$DIR.src.rpm" 2>&1 > /dev/null
# do some package-related things
PKSUSE100=''
PKSUSE101=$PKSUSE100
case "$PACKAGE" in
libdomainkeys-toaster)
SEDS='s/ripMIME for qmail-toaster/DomainKey library/'
;;
vpopmail-toaster)
echo 'diff -u vpopmail-5.4.13.org/vmysql.c vpopmail-5.4.13/vmysql.c
--- vpopmail-5.4.13.org/vmysql.c 2004-12-16 23:57:34.000000000
+0800
+++ vpopmail-5.4.13/vmysql.c 2006-03-31 09:42:45.000000000 +0800
@@ -188,7 +188,7 @@
{
unsigned int timeout = 2;
- if ( update_open != 0 ) return(0);
+ if ( update_open && (mysql_ping(&mysql_update)==0) ) return(0);
update_open = 1;
verrori = load_connection_info();
@@ -238,7 +238,7 @@
int vauth_open_read()
{
/* if we are already connected, just return */
- if ( read_open != 0 ) return(0);
+ if ( read_open && (mysql_ping(&mysql_read)==0) ) return(0);
read_open = 1;
/* connect to mysql and set the database */' | bzip2 >
vmysql.patch.bz2
SEDS='s/^\(%define[\t ]*rpmrelease\).*/\1 2/ ;
s/^\(%define[\t ]*ostype SuSE
*10\.[0-9].*Linux\)/\1\nRequires:\tpwdutils/ ;
s/^\(Patch0:[\t ]*vpopmail-5.4.13.patch.bz2\)/\1\nPatch1:\t\tvmysql.patch.bz2/
;
s/^\(%patch0 -p0\)/\1\n%patch1 -p1/'
;;
qmail-toaster)
SEDS='s/^\(%define.*ostype SuSE
*10\.[0-9].*Linux\)/\1\nRequires:\tpwdutils/'
PKSUSE100='mysql-devel'
PKSUSE101=$PKSUSE100
;;
courier-authlib-toaster)
PKSUSE100='vpopmail-toaster, gcc-c++, libstdc++-devel, expect,
mysql-shared, mysql-devel'
PKSUSE101=$PKSUSE100
;;
courier-imap-toaster)
PKSUSE100='gcc-c++, libstdc++-devel, mysql-devel'
SEDS='/^BuildRequires:/ s/fileutils// ; /^Requires:/ s/fileutils// ;
/^BuildRequires:/ s/textutils// ; /^Requires:/ s/textutils//'
PKSUSE101=$PKSUSE100
;;
control-panel-toaster)
PKSUSE100='apache, libapr0, expat'
PKSUSE101='apache2, libapr1, expat'
SEDS='s/^\(Requires:.*apache2 >= 2.0.52, php5 >=
[0-9\.]*\)/Requires:\tapache2 >= 2.0.52, php >=
4.4.0\nBuildRequires:\tapache2, libapr-util1/ ; s/^\(Requires:.*apache2
>= 2.0.52, php4 >= [0-9\.]*\)/Requires:\tapache2 >= 2.0.52, php >=
4.4.0/'
;;
qmailmrtg-toaster)
PKSUSE100='mrtg'
PKSUSE101=$PKSUSE100
SEDS='s/^\(Requires:.*cron >= 4.1, apache2 >= 2.0.54, php4 >= 4.4.0,
mrtg\)/Requires:\tcron >= 4.1, apache2 >= 2.0.54, php >= 4.4.0/'
;;
maildrop-toaster)
PKSUSE100='gcc-c++, libstdc++-devel, pcre, pcre-devel, openldap2-client,
mrtg, net-tools, openssl, cyrus-sasl, vpopmail-toaster, qmail-toaster'
PKSUSE101=$PKSUSE100
;;
isoqlog-toaster)
#PKSUSE100='php5'
#PKSUSE101='php'
;;
squirrelmail-toaster)
SEDS='s/^\(Requires:.*apache2 >= 2.0.54, php4 >=
4.4.0\)/Requires:\tapache2 >= 2.0.54, php >= 4.4.0/'
;;
spamassassin-toaster)
SEDS='s/^\(BuildRequires:.*perl >= 5.8.7, perl(Digest::SHA1),
perl(HTML::Parser), openssl-devel\)/BuildRequires:\tperl >= 5.8.7,
perl-Digest-SHA1, perl-HTML-Parser, openssl-devel/ ;
s/^\(Requires:.*perl(Digest::SHA1), perl(HTML::Parser),
perl(Pod::Usage), procmail\)/Requires:\tperl-Digest-SHA1,
perl-HTML-Parser, procmail/'
;;
clamav-toaster)
PKSUSE100='qmail-toaster'
PKSUSE101=$PKSUSE100
SEDS='s/^\(%define.*ostype SuSE
*10\.[0-9].*Linux\)/\1\nRequires:\tpwdutils/ ;
s/^\(\/sbin\/service freshclam start.*\)/if test %{build_sus_100} -eq
0 -a %{build_sus_10064} -eq 0; then\n \1\nfi/'
;;
simscan-toaster)
PKSUSE100='perl-Digest-SHA1, perl-HTML-Parser, clamav-toaster,
spamassassin-toaster, ucspi-tcp-toaster'
PKSUSE101=$PKSUSE100
;;
djbdns)
SEDS='
s/chkconfig, initscripts, sh-utils, daemontools-toaster,
ucspi-tcp-toaster/daemontools-toaster, ucspi-tcp-toaster/ ;
s/\(Buildprereq: shadow-utils\)/#\1/
s/^\(# create log symlinks\)$/# touch logs\npushd
%{buildroot}\/var\/djbdns\nmkdir -p dnscachex\/log dnscache\/log
tinydns\/log axfrdns\/log\ntouch dnscachex\/log\/main
dnscache\/log\/main tinydns\/log\/main axfrdns\/log\/main\npopd\n\n\1/ ;
s/^\(\/var\/log\/djbdns\/axfrdns\)$/\1\n%config(noreplace)\/var\/djbdns\/tinydns\/log\/main\n%config(noreplace)\/var\/djbdns\/axfrdns\/log\/main/
;
s/^\(\/var\/log\/djbdns\/dnscachex\)$/\1\n%config(noreplace)\/var\/djbdns\/dnscachex\/log\/main/
;
s/^\(\/var\/log\/djbdns\/dnscache\)$/\1\n%config(noreplace)\/var\/djbdns\/dnscache\/log\/main/'
;;
esac
SPECFILE=`ls *.spec | tail -n1`
# SuSE seems to ignore the BuildPreReq lines.
# Therefore all BuildPreReq lines are renamed to BuildRequires
# The statements are identical, as said in
# http://www.redhat.com/archives/rpm-list/2003-June/msg00088.html
#
sed -i.orig -e 's/^BuildPreReq:/BuildRequires:/' $SPECFILE
# now do some changes for the suse distributions
if test -n "$SEDS" ; then
sed -i -e "$SEDS" $SPECFILE
fi
if test -n "$PKSUSE100" ; then
sed -i -e "s/^\(%define.*ostype SuSE
*10\.0.*Linux\)/\1\nBuildRequires:\t$PKSUSE100/" $SPECFILE
fi
if test -n "$PKSUSE101" ; then
sed -i -e "s/^\(%define.*ostype SuSE
*10\.1.*Linux\)/\1\nBuildRequires:\t$PKSUSE101/" $SPECFILE
fi
# SuSE before 10.1 did not include all packages to build the toaster
# packaged properly. Therefore they should be included for SuSE 10.0
# distributions.
sed -i -e 's/^\(%define.*ostype SuSE
*10\.0.*Linux\)/\1\nBuildRequires:\taaa_base, acl, attr, bash,
bind-utils, bison, bzip2, coreutils, cpio, cpp, cracklib, cvs,
cyrus-sasl, db, devs, diffutils, e2fsprogs, file, filesystem, fillup,
findutils, flex, gawk, gdbm-devel, glibc, glibc-devel, glibc-locale,
gpm, grep, groff, gzip, info, insserv, klogd, less, libacl, libattr,
libgcc, libnscd, libselinux, libstdc++, libxcrypt, libzio, m4, make,
man, mktemp, module-init-tools, ncurses, ncurses-devel, net-tools,
netcfg, openldap2-client, openssl, pam, pam-modules, patch, permissions,
popt, procinfo, procps, psmisc, pwdutils, rcs, readline, sed, strace,
syslogd, sysvinit, tar, tcpd, texinfo, timezone, unzip, util-linux, vim,
zlib, zlib-devel, autoconf, automake, binutils, gcc, gdbm, gettext,
libtool, perl, rpm, net-tools, openssl, cyrus-sasl, zlib-devel,
pwdutils/' $SPECFILE
diff -u $SPECFILE.orig $SPECFILE > ../$PACKAGE.diff
sed -i -e 's/\(^%define.*build_sus_'$SUSETOASTERRELEASE$TOASTERTYPE'
[^0]*\)\(0$\)/\1 1/' $SPECFILE
# for SuSE < 10.1 all occurences of "BuildRequires" are interpreted,
even when excluded by
# %if...%endif sections. "BuildRequires" does additionally NOT accept
version information.
# SuSE < 10.1 ignores the "BuildPreReq" sections, so all it's
information must be copied to
# "BuildRequires"
# begin speciallity for Suse < 10.1
if test $SUSETOASTERRELEASE -lt 101 ; then
# backup the full spec files
cp $SPECFILE complete-$SPECFILE
# read the required distibution statements
DISTSTATEMENT=`sed -n -e "/^%if
%{build_sus_$SUSETOASTERRELEASE$TOASTERTYPE}$/,/^%endif/p " $SPECFILE`
# remove all distibution statements
sed -i -e '/^%if %{build_[a-z]*_[0-9]*}$/,/^%endif/d' $SPECFILE
sed -i -e '/^%if %{default}$/,/^%endif/d' $SPECFILE
# split up and insert the current distributions statement on the proper
position
csplit --quiet $SPECFILE "/# Distro Statements/+1"
cat xx00 > $SPECFILE
echo -e "$DISTSTATEMENT" >> $SPECFILE
cat xx01 | sed -e '/./,$!d ; /^BuildRequires/
s/\(BuildRequires:\)\([a-z]\)/\1\t\2/' >> $SPECFILE
rm xx00 xx01
# re-format BuildRequires statements for the whole package (not for the
distibution)
sed -i -e '/^BuildRequires/ s/[<>=]\+ [0-9\.\-]\+//g ; /^BuildRequires/
s/,/ /g ; /^BuildRequires/ s/[ ]+/ /g ; /^BuildRequires/ s/ [ ]*/ /g'
$SPECFILE
fi
# end speciallity for Suse < 10.1
if test $DRYRUN -ne 1 ; then
build $SPECFILE --clean --arch=$ARCH \
--rpms
$DEFAULTRPM/:$QMAILRPM/SuSE-$SUSERELEASE/RPMS/$ARCH:$QMAILRPM/SuSE-$SUSERELEASE/RPMS/noarch
if test $? -ne 0 ; then
exit 1
fi
cp -a /var/tmp/build-root/usr/src/packages/*
"$QMAILRPM/SuSE-$SUSERELEASE/"
fi
popd 2>&1 > /dev/null
if test $DRYRUN -eq 0 -o $CLEAN -eq 1 ; then
rm -rf "$DIR"
fi
fi
done