#!/bin/bash # # Copyright (C) 2006-2009 Eric Shubert # # Build the binary rpms for qmail toaster # # This script is invoked by qtp-newmodel. # It is run in a sandbox (aka chroot jail), # so the packages aren't installed on the 'live' system. # This is done so that qmailtoaster can be kept running # during this (lengthly) processing, and to identify any potential # problems that need fixing before upgrading a 'live' system. # ################################################################### # change log # 07/28/10 shubes - changed ARCH to QTARCH to be consistent w/ qtp-newmodel # - pick up variables from qtp-whatami instead of arglist # - added qtp-whatami, qtp-config outputs to log file # - created q51 function to eliminate some redundancy # 06/28/10 shubes - increated number of lines of log shown to 40 # 08/21/09 shubes - added tail of log to terminal output when build fails # 08/18/09 shubes - removed stop freshclam - package no longer starts it # 08/13/09 shubes - fixed bug, allowing packages to be rebuilt # 07/15/09 shubes - added --replacepkgs for rebuilding installed packages # 07/23/08 shubes - stop freshclam after installing clamav-toaster # 01/13/07 shubes - added RPMBUILD_OPT_DIR for package specific options, # replacing hard-coded spambox option # 01/03/07 shubes - fixed spambox option by adding eval to rpmbuild # - added RPMBUILD_OPTIONS variable # 12/21/06 shubes - added spambox option for qmailtoaster-admin pkg # 11/03/06 shubes - added qtp-config to get $SANDBOX, $UPGRADE_DIR # 10/20/06 shubes - split out qtp-remove-pkgs into separate script # - added qtp-convert # - umount /proc before mounting, just in case # 08/22/06 shubes - renamed for qt-plus # 07/15/06 shubes - remove horde-toaster # 07/14/06 shubes - remove courier-imap-toaster-doc ################################################################### ## check and set up the environment # a1_initialization(){ . qtp-whatami >> $logfile . qtp-config >> $logfile # Make sure we're running in the sandbox if [ ! -f /boot/.`basename $SANDBOX` ]; then echo "Error: This script needs to be run in a sandbox (chroot) environment" echo "Please run the qtp-newmodel script instead" exit 1 fi QMT_PACKAGES=$(cat $CURRENT_PACKAGES) if [ -z "${QMT_PACKAGES}" ] ; then echo "$me Error - package list not found" exit 1 fi umount /proc 2>/dev/null mount -t proc none /proc } ################################################################### ## build and install each package (in the sandbox) # a5_build_install_package(){ QMT_PKGVER=${QMT_PKG%.src.rpm} QMT_PKGNAME=${QMT_PKGVER%-[^-]*-[^-]*} echo "Building ${QMT_PKGVER} ..." | tee -a $logfile echo $QMT_PKGNAME | grep -q toaster rc=$? if [ $rc = "0" ]; then buildparm="--with $BUILD_DIST" updateparm="" else buildparm="" updateparm="--replacefiles --replacepkgs" fi if [ -f "$RPMBUILD_OPT_DIR/$QMT_PKGNAME" ]; then buildparm="$buildparm `cat $RPMBUILD_OPT_DIR/$QMT_PKGNAME`" fi rpmfile=$BUILD_DIR/RPMS/$QTARCH/$QMT_PKGVER.$QTARCH.rpm if [ ! -f "$rpmfile" ]; then rpmfile=$BUILD_DIR/RPMS/noarch/$QMT_PKGVER.noarch.rpm if [ ! -f $rpmfile ]; then rpmfile="" fi fi if [ -z "$rpmfile" ]; then b54_build_package else echo "$rpmfile already exists," | tee -a $logfile echo "$QMT_PKGVER not rebuilt" | tee -a $logfile fi b56_install_packages } ################################################################### ## build the binary rpm in the sandbox # b54_build_package(){ eval rpmbuild --rebuild $RPMBUILD_OPTIONS $buildparm --target=$QTARCH \ $UPGRADE_DIR/SRPMS/${QMT_PKG} >>$logfile 2>&1 rc=$? if [ $rc != "0" ]; then echo "$me - rpmbuild failed for $QMT_PKGVER" q51_log_and_exit fi } ################################################################### ## install the package in the sandbox # b56_install_packages(){ echo "Installing ${QMT_PKGVER} in the sandbox ..." | tee -a $logfile rpmfile=$BUILD_DIR/RPMS/$QTARCH/$QMT_PKGVER.$QTARCH.rpm if [ -f $rpmfile ]; then thisarch=$QTARCH else rpmfile=$BUILD_DIR/RPMS/noarch/$QMT_PKGVER.noarch.rpm if [ -f $rpmfile ]; then thisarch=noarch else echo "$me - binary rpm not found for $QMT_PKGVER" echo "$me - Script Error - aborting." umount /proc exit 1 fi fi # install any sub-packages that were generated # note, version-release and arch *must* match install_pkgs=$rpmfile thisver=${QMT_PKGVER#${QMT_PKGNAME}} for thisrpm in `ls $BUILD_DIR/RPMS/$thisarch/*$thisver*`; do if [ "$thisrpm" != "$rpmfile" ]; then install_pkgs="$install_pkgs $thisrpm" fi done rpm -Uvh --replacefiles --replacepkgs $updateparm $install_pkgs >>$logfile 2>&1 rc=$? if [ $rc != "0" ]; then rm $install_pkgs echo "$me - rpm -Uvh failed for $QMT_PKGVER" q51_log_and_exit fi } ################################################################### ## show a tail of the log, then exit with non-zero return code # q51_log_and_exit(){ echo "$me - here are the last 40 messages from the log:" tail -n40 $logfile echo "" echo "" echo "$me - see $SANDBOX$UPGRADE_DIR/log/build-recent.log for more details" umount /proc exit $rc } ################################################################### ## main script execution begins here # me=${0##*/} myver=v0.3.7 echo "$me $myver" export CURRENT_PACKAGES=$1 export logfile=$2 a1_initialization qtp-remove-pkgs for QMT_PKG in ${QMT_PACKAGES}; do a5_build_install_package done qtp-convert umount /proc exit 0