#!/bin/bash # # Copyright (C) 2006-2012 Eric Shubert # # *******************USE AT YOUR OWN RISK************************ # # The Orignal Script was upgrade.sh, written by Jake Vickers . # # Erik Espinoza's current-download-script # and parts of the current-install-script written by # Nick Hemmesch were added to it. # # Backup and restore of control files was added by Devendra Meena # . # I am not sure which files get replaced by the new installation, # so I just backed up all that I thought were relevant (-DM) # # Substantially restructured by Eric 'shubes', allowing packages to be # compiled before qmail is stopped, minimizing down time and allowing # for build problems to be resolved without impacting the running environment. # Also added various checks, made it rerunable and platform independent. # # The primary input is a list of packages (in no particular sequence). # # *** Dependencies *** # Input: # .) http://www.qmailtoaster.com/info/current.txt # .) http://devel.qmailtoaster.com/info/current.txt # Sub scripts: # .) qtp-build-rpms # .) qtp-build-sandbox # .) qtp-build-unionfs # .) qtp-config # .) qtp-convert # .) qtp-dependencies # .) qtp-get-pkg-list # .) qtp-mount-sandbox # .) qtp-remove-pkgs # .) qtp-umount-sandbox # .) qtp-whatami # # Future Enhancements # .) allow for customization of packages (e.g. chkuser) # .) integrate qtp-backup, qtp-restore into process # .) improve control file restore processing # .) add support for upgrading djbdns # .) set up djbdns or bind localcache configuration # ################################################################### # # Note: If you're modifying (adding) control files to be backed up, # you need to change the logic in 2 places: # .) a7_backups() # .) b85_restores() # ################################################################### # # change log # # 02/09/12 shubes - changed mirrors from .net to .com # 04/09/11 Jake - added a sleep between downloads to be courteous to mirrors # 07/29/10 shubes - created qtp-dependencies processing as separate script # 07/28/10 shubes - don't pass qtp-whatami variables to qtp-build-rpms # 06/18/10 shubes - added perl-Crypt-OpenSSL-Bignum to dependencies # 05/02/10 shubes - changed URL for mirrors # 10/01/09 shubes - added queue_repair.py to ensure queues are kosher # 08/18/09 shubes - don't bother with freshclam any more - # package modified to not do freshclam in sandbox # 08/14/09 shubes - changed $UNIONROOT to $OVERLAY # 08/05/09 shubes - remove binary rpms when installed package selected # 07/31/09 shubes - removed squirrelmail-toaster from vpopmail-dependents # 07/30/09 shubes - added squirrelmail-toaster to vpopmail-dependent packages # 07/19/09 shubes - force rebuild of dependent packages when vpopmail is upgraded # 07/18/09 shubes - added capability to rebuild installed packages # 07/15/09 shubes - don't try to stop freshclam if it's not installed yet # 07/08/09 shubes - modified to only enable rpmforge if it's repo is installed # 04/09/09 shubes - added ncurses-devel dependency for clamav 0.95.1 # 04/04/09 shubes - changed perl dependencies from packages to modules # Thanks to Steve Huff for this tip! # 04/03/09 shubes - removed errant perl dependency packages which are # included in the base perl package # 02/03/09 Jake - changed some naming conventions, # - adjusted for new download paths # 10/03/08 shubes - added perl-LWP-User-Agent for arch x86_64 # 08/29/08 shubes - added rpmforge repo processing # 07/23/08 shubes - stop/start freshclam when processing clamav-toaster package # - fixed bug in 4/22/08 change # 04/25/08 shubes - removed djbdns from selection list # 04/23/08 shubes - moved dependencies code, needs to be done before # sandbox is mounted. # 04/22/08 shubes - add code to allow for .$QTARCH, extension in pkg name # 04/06/08 shubes - fix bug where reusing sandbox assumed unionfs # - remove union sandbox if type (kernel) changes # - don't umount a non-unionfs sandbox at cleanup # - made backups unique so they aren't overlayed # - commented out restore configs from backups # 03/03/08 shubes - added perl dependencies for spamassassin # 02/11/08 shubes - Commented out question/answer for devel site since # they're both the same for now. Left code in for future. # 01/21/08 Jake - Removed the subprocess for djbdns (commented out, someday we # should fix this, but I only use Bind so it's not a # priority for me). # - added some extra "echos" to the output # just to make some things easier to read. # - Changed default option to Y to remove the sandbox. # 01/07/08 shubes - changed $ARCH to $QTARCH to not conflict with makefiles # - fixed up dependency checking/installation a bit # - added unionfs capability, thanks to Justice London # - created qtp-get-pkg-list for sequencing current.txt # 10/25/07 Jake - Fixed a bug in the reorganization of the current.txt file # - and it now installs procmail if it isn't already to meet a # - spamassassin dependency. I added a routine to check for deps # - that will hopefully be utilized in the future. # 06/25/07 Jake - Added some scripting to reorganize the current.txt file # - to process the packages in the correct order # 03/10/07 shubes - removed processing for djbdns (doesn't work) # 03/09/07 shubes - changed default restore configuration to no # - changed backup/restore clamav to include entire directory # 03/06/07 shubes - moved version comparison into external function # 02/23/07 shubes - fixed another bug in zlib version comparison # - made libsrs2-toaster mandatory # 02/05/07 shubes - fixed bug in version comparison (zlib) # 01/12/07 shubes - fixed bug when re-using package selections # 01/10/07 shubes - fixed bug when package in devel not in stable is skipped # 01/08/07 shubes - fixed cleanup errors when sandbox removed # 01/07/07 shubes - incorporated development packages # 01/03/07 shubes - don't restore *.rpmnew config files # - restore passwd for control-panel-toaster # 11/06/06 shubes - commented out SA debug, as it *might* cause a problem # - added SA debug back in with sudo -u vopopmail -H # 11/03/06 shubes - removed QTP_RUN # - added qtp-config to set QMT_WEB, UPGRADE_DIR, SANDBOX # 10/20/06 shubes - split out qtp-remove-pkgs into separate script # - split out qtp-convert into separate script # - umount /proc from sandbox before removing it # 08/30/06 shubes - split out qtp-build-sandbox into separate script # 08/26/06 shubes - added /dev/random, /dev/urandom to sandbox # 08/25/06 shubes - fixed IFS bug # only create /home/vpopmail in sandbox if it exists # 08/23/06 shubes - fixed symlink target leading space bug # 08/22/06 shubes - added toaster.conf to backup/restore # added optional restore of configuration files # renamed/revamped for qtp # 08/21/06 shubes - add 64bit directories to sandbox # 08/20/06 shubes - only copy QTP_RUN to sandbox if not already there # 08/19/06 shubes - fixed to prohibit errant SANDBOX values # 07/31/06 shubes - fixed sandbox to handle filenames w/ spaces # 07/27/06 shubes - added /etc/courier to backups # 07/15/06 shubes - remove horde-toaster # 07/14/06 shubes - remove courier-imap-toaster-doc # ################################################################### ## check and set up the environment # a1_initialization(){ # Make sure we're root if [ "$UID" != "0" ]; then echo "Error: You are not root, please su -" exit 1 fi echo "$me $myver starting $(date)" b12_check_distro_arch . qtp-config -s mkdir -p $UPGRADE_DIR/SRPMS mkdir -p $UPGRADE_DIR/backup mkdir -p $UPGRADE_DIR/old-rpms mkdir -p $UPGRADE_DIR/log mkdir -p $BUILD_DIR/RPMS/$QTARCH mkdir -p $BUILD_DIR/RPMS/noarch SOURCE_DIR=$UPGRADE_DIR/SRPMS export CURRENT_PACKAGES=$SOURCE_DIR/current-newmodel.txt export logfile=$UPGRADE_DIR/log/build-$(date +%Y%m%d-%H%M%S).log touch $logfile rm -f $UPGRADE_DIR/log/build-recent.log ln -s $(basename $logfile) $UPGRADE_DIR/log/build-recent.log } ################################################################### ## set QTARCH, BUILD_DIST, and BUILD_DIR variables # b12_check_distro_arch(){ . qtp-whatami case $? in 0 ) echo echo "Let's get on with it!" ;; 1 ) echo echo "If your OS is not current, you should consider upgrading it." echo -n "Do you want to proceed at your own risk? (yes, no) y/[n] : " if [ "$background" ]; then echo echo "Running in background, replied 'yes'" REPLY=y else read REPLY fi case $REPLY in "y" | "yes" ) echo echo "Ok, here we go ..." ;; * ) echo echo "Ok, Exiting." exit 1 ;; esac ;; * ) exit 1 ;; esac } ################################################################### ## check to see if packages have already been selected or not # a2_get_packages_to_process(){ if [ -f "$CURRENT_PACKAGES" ]; then # srcpkg=$(head -n 1 $CURRENT_PACKAGES) # pkgver=${srcpkg%.src.rpm} # instver=$(rpm -q ${pkgver%-[^-]*-[^-]*}) # rc=$? # if [ "$rc" == 0 ] \ # && [ "$pkgver" == "$instver" ]; then # rm $CURRENT_PACKAGES # else echo echo "The following packages have already been selected:" cat $CURRENT_PACKAGES echo echo "Do you want to process this selection?" q01_ask_default_y # fi fi if [ ! -f "$CURRENT_PACKAGES" ] || [ $PROCEED == "n" ]; then b25_get_select_packages fi QMT_PACKAGES=$(cat $CURRENT_PACKAGES) } ################################################################### ## let the user select which packages to install # b25_get_select_packages(){ vpopmail_selected="" vpopmail_dependencies="\ qmail-toaster \ qmailadmin-toaster \ courier-authlib-toaster \ courier-imap-toaster " required_pkgs="\ daemontools-toaster \ libdomainkeys-toaster \ libsrs2-toaster \ qmail-toaster \ ucspi-tcp-toaster \ vpopmail-toaster \ " c251_get_package_lists c252_check_bind_vs_djbdns listfile=$SOURCE_DIR/newmodel-list-$(date +%Y%m%d-%H%M%S).txt echo echo echo "Qmailtoaster is an integrated distribution." echo "Packages are preconfigured for the whole distro." echo "As a result, a partial install might be misconfigured." echo "Upgrading all packages to their latest version is strongly recommended." echo "Now that you've been warned, we will proceed with package selection ..." echo for QMT_PKG in ${devlist:-${pkglist}}; do if [ ! -z "$devlist" ]; then c253_devel_or_stable fi if [ ! -z "$QMT_PKG" ]; then c255_check_each_package fi done if [ ! -f $listfile ]; then echo echo "Qmailtoaster packages are all current." echo "There is nothing more to do." exit 0 fi touch $CURRENT_PACKAGES diff -q $CURRENT_PACKAGES $listfile >/dev/null if [ $? != "0" ]; then rm $CURRENT_PACKAGES ln -s $(basename $listfile) $CURRENT_PACKAGES if [ -d ${SANDBOX}$SOURCE_DIR ]; then cp $listfile ${SANDBOX}$listfile rm ${SANDBOX}${CURRENT_PACKAGES} ln -s $(basename $listfile) ${SANDBOX}${CURRENT_PACKAGES} fi else rm $listfile fi } ################################################################### ## get current package list from the web # c251_get_package_lists(){ #echo #echo "Do you want to include development packages?" #echo "(This is *not* recommended for production servers)" #echo #q02_ask_default_n PROCEED=n usedevel=$PROCEED if [ "$usedevel" == "y" ]; then echo echo "Getting package lists ..." devlist=$(qtp-get-pkg-list ${QMT_DEV}/info/current.txt) if [ $? != "0" ]; then echo "$devlist" echo echo "Development List unavailable, continuing with stable list ..." devlist="" fi else echo echo "Getting package list ..." devlist="" fi pkglist=$(qtp-get-pkg-list ${QMT_WEB}/info/current.txt) if [ $? != "0" ]; then echo "$pkglist" echo "Package List unavailable, terminating" exit 1 fi } ################################################################### ## remove djbdns from package lists if bind is installed # do this whether bind is installed or not - it doesn't work # c252_check_bind_vs_djbdns(){ #rpm -q bind >/dev/null #rc=$? #if [ $rc == "0" ]; then pkglist=$(echo "$pkglist" | sed -e 's,djbdns-[^-]*-[^-]*.src.rpm$,,') devlist=$(echo "$devlist" | sed -e 's,djbdns-[^-]*-[^-]*.src.rpm$,,') devlist=$(echo "$devlist" | sed -e 's,djbdns$,,') #fi } ################################################################### ## check if development package is desired ## if not, get QMT_PKG from stable list # c253_devel_or_stable(){ QMT_PKGNAME=${QMT_PKG%-[^-]*-[^-]*.src.rpm} if [ "$QMT_PKG" == "$QMT_PKGNAME" ]; then PROCEED=n else echo echo "Do you want to select $QMT_PKG from Development?" echo q01_ask_default_y fi if [ $PROCEED == "n" ]; then QMT_PKG="" for pkg in $pkglist; do if [ "$QMT_PKGNAME" == ${pkg%-[^-]*-[^-]*.src.rpm} ]; then QMT_PKG=$pkg break fi done fi } ################################################################### ## check each package # c255_check_each_package(){ QMT_PKGVER=${QMT_PKG%.src.rpm} QMT_PKGNAME=${QMT_PKGVER%-[^-]*-[^-]*} QMT_VERSION=${QMT_PKGVER#${QMT_PKGNAME}-} installed_pkgverarch=$(rpm -q $QMT_PKGNAME) rc=$? installed_pkgver=${installed_pkgverarch%.$QTARCH} if [ "$installed_pkgverarch" == "$installed_pkgver" ]; then installed_pkgver=${installed_pkgverarch%.noarch} fi if [ $rc == "0" ]; then d2555_check_installed_package else echo $required_pkgs | grep -q $QMT_PKGNAME if [ $? == "0" ]; then echo echo "$QMT_PKGVER will be installed" echo $QMT_PKG >>$listfile else echo echo "$QMT_PKGNAME is not installed, would you like to install it?" q02_ask_default_n if [ $PROCEED == "y" ]; then echo $QMT_PKG >>$listfile fi fi fi } ################################################################### ## check each installed package # d2555_check_installed_package(){ vpopmail_dependent="" for vpop_dep_pkg in $vpopmail_dependencies; do if [ "$vpop_dep_pkg" == $QMT_PKGNAME ]; then vpopmail_dependent="y" fi done if [ -z "$vpopmail_selected" ] || \ [ -z "$vpopmail_dependent" ]; then if [ "$installed_pkgver" == ${QMT_PKGVER} ]; then echo echo "${QMT_PKGVER} is already installed, would you like to rebuild it?" q02_ask_default_n if [ $PROCEED == "y" ]; then e25555_select_package fi else x01_compare_versions if [ "$?" == "1" ]; then echo echo "Newer $installed_pkgver is already installed, $QMT_PKGVER bypassed" else echo echo "$installed_pkgver is installed." echo "Do you want to Upgrade $QMT_PKGNAME to version $QMT_VERSION" q01_ask_default_y if [ $PROCEED == "y" ]; then if [ $QMT_PKGNAME == "djbdns" ]; then echo "$me does not yet support $QMT_PKGNAME" echo "Please upgrade/install $QMT_PKGNAME manually" else e25555_select_package fi fi fi fi else echo "" echo "$QMT_PKGNAME is required to be rebuilt with vpopmail-toaster" e25555_select_package fi } ################################################################### ## add this package to the list of packages to rebuild/install # e25555_select_package(){ echo $QMT_PKG >>$listfile echo "$QMT_PKG selected for processing" if [ $QMT_PKGNAME == "vpopmail-toaster" ]; then vpopmail_selected="y" fi # remove binary rpm so the package gets rebuilt rm -f $BUILD_DIR/RPMS/$QTARCH/*${QMT_PKGVER#${QMT_PKGNAME}}* \ $BUILD_DIR/RPMS/noarch/*${QMT_PKGVER#${QMT_PKGNAME}}* } ################################################################### ## download source packages # a3_download_src_packages(){ echo echo "Getting source packages ...(this may take a while)" if [ "$background" ]; then get_quiet="-nv" else get_quiet="" fi for QMT_PKG in $QMT_PACKAGES; do QMT_PKGVER=${QMT_PKG%.src.rpm} QMT_PKGNAME=${QMT_PKGVER%-[^-]*-[^-]*} if [ -f $UPGRADE_DIR/SRPMS/$QMT_PKG ]; then echo "${QMT_PKG} is already downloaded, bypassed" else echo "Downloading $QMT_PKG" echo "$devlist" | grep -q $QMT_PKG if [ $? == "0" ]; then getfrom=${QMT_DEV}/download/develop else getfrom=http://mirrors.qmailtoaster.com fi wget $get_quiet -O $UPGRADE_DIR/SRPMS/$QMT_PKG \ $getfrom/$QMT_PKG if [ ! -s $UPGRADE_DIR/SRPMS/$QMT_PKG ]; then echo "Download of $getfrom/$QMT_PKG failed - Exiting." exit 1 else if [ -d ${SANDBOX}$UPGRADE_DIR ]; then rm -f ${SANDBOX}$UPGRADE_DIR/SRPMS/$QMT_PKG cp -p $UPGRADE_DIR/SRPMS/$QMT_PKG ${SANDBOX}$UPGRADE_DIR/SRPMS/$QMT_PKG fi fi sleep 5 fi done } ################################################################### ## install dependent packages that aren't already installed # a4_check_dependencies(){ qtp-dependencies rc=$? if [ "$rc" != "0" ]; then echo "$me - dependent packages processing failed, exiting" exit $rc fi } ################################################################### ## Build a sandbox (aka chroot jail) for building the binary rpms # a5_build_sandbox(){ # SBTYPE is the existing SB, if one exists # FSTYPE is the type of unionfs we're capable of using, if any SBTYPE="" FSTYPE="" SBFILE="$SANDBOX/boot/.${SANDBOX##*/}" b52_check_overlay_capable if [ -d "$SANDBOX" ]; then if [ ! -f "$SBFILE" ]; then echo echo "$SANDBOX exists, but apparently is not a sandbox" echo "Please use a different value for SANDBOX and try again" exit 1 else SBTYPE=$(cat $SBFILE) # check to be sure that the type of unionfs hasn't changed if [ "$SBTYPE" != "$FSTYPE" ] \ && [ "$SBTYPE" != "L" ] \ && [ "$SBTYPE" != "C" ]; then q03_remove-union-sandbox else b54_check_removal fi fi fi if [ ! -z "$FSTYPE" ] \ && [ "$SBTYPE" != "L" ] \ && [ "$SBTYPE" != "C" ]; then # mount an existing sandbox if appropriate if [ -d "$SANDBOX" ] && [ $FSTYPE == "$SBTYPE" ]; then qtp-mount-sandbox $background if [ $? != "0" ]; then echo echo "$me terminating." exit 1 fi else b56_check_union_fs fi fi if [ ! -d "$SANDBOX" ]; then qtp-build-sandbox $background rc=$? if [ "$rc" != "0" ]; then echo echo "$me - build sandbox failed, exiting" exit $rc fi fi SBTYPE=$(cat $SBFILE) } ################################################################### ## check to see if the running kernel can use FUSE for unionfs # b52_check_overlay_capable(){ kernelver=$(expr "$(uname -r)" : "\(^[0-9]*\+\.[0-9]*\+\.[0-9]*\)") kernelmajorver=${kernelver%.[^.]*} declare -i kernelminorver=${kernelver##[^.]*.} if [ "$kernelmajorver" == "2.6" ] \ && [ "$kernelminorver" -ge "9" ]; then FSTYPE=U fi } ################################################################### ## check to see if we should remove the existing sandbox # b54_check_removal(){ echo echo -n "Shall we build a new sandbox at $SANDBOX? [y]/n: " if [ "$background" ]; then echo "Running in background, replied 'yes'" REPLY=y else read REPLY fi case $REPLY in "n" | "no" ) : ;; * ) echo echo "Removing sandbox at $SANDBOX ..." case $SBTYPE in "L" | "C" ) rm -rf $SANDBOX ;; * ) q03_remove-union-sandbox ;; esac SBTYPE="" ;; esac } ################################################################### ## check to see if we'd like to use the union filesystem # b56_check_union_fs(){ echo echo -n "Would you like a unionfs/overlay sandbox? (recommended) [y]/n: " if [ "$background" ]; then echo "Running in background, replied 'yes'" REPLY=y else read REPLY fi case $REPLY in "n" | "no" ) : ;; * ) echo echo "Using FUSE union filesystem ..." qtp-mount-sandbox $background rc=$? if [ "$rc" != "0" ]; then echo echo "$me - qtp-mount-sandbox failed, exiting" exit $rc fi ;; esac } ################################################################### ## build the binary rpms # a6_build_binary_rpms(){ echo echo "Starting to build the binary rpms ...(pizza anyone?)" echo echo "If you want to view compile messages, you can open another terminal and:" echo "# tail -f ${SANDBOX}$(dirname $logfile)/build-recent.log" echo cp --remove-destination $logfile ${SANDBOX}$logfile rm -f ${SANDBOX}$UPGRADE_DIR/log/build-recent.log ln -s $(basename $logfile) ${SANDBOX}$UPGRADE_DIR/log/build-recent.log chroot $SANDBOX \ qtp-build-rpms \ $CURRENT_PACKAGES \ $logfile rc=$? cp -p ${SANDBOX}$logfile $logfile if [ $rc != "0" ]; then echo echo "Build failed, Exiting." exit $rc fi b67_copy_binary_rpms echo echo "Building of packages finished ..." } ################################################################### ## copy binary RPMS from the sandbox to their normal locations # b67_copy_binary_rpms(){ echo echo "Copying binary RPMS ..." rm -rf $UPGRADE_DIR/RPMS mkdir $UPGRADE_DIR/RPMS for QMT_PKG in $QMT_PACKAGES; do QMT_PKGVER=${QMT_PKG%.src.rpm} QMT_PKGNAME=${QMT_PKGVER%-[^-]*-[^-]*} rpmfile=${SANDBOX}$BUILD_DIR/RPMS/$QTARCH/$QMT_PKGVER.$QTARCH.rpm if [ ! -f $rpmfile ]; then rpmfile=${SANDBOX}$BUILD_DIR/RPMS/noarch/$QMT_PKGVER.noarch.rpm if [ ! -f $rpmfile ]; then echo "Error: binary rpm not found for $QMT_PKGVER" echo "Exiting." exit 1 fi fi # copy any sub-packages that were generated too # note, version-release and arch *must* match rpmdir=$(dirname $rpmfile) for thisrpm in $(ls $rpmdir/*${QMT_PKGVER#${QMT_PKGNAME}}*); do case "$SBTYPE" in # we need cparm so linked sandbox doesn't try to copy to itself "L" ) cparm="--remove-destination" ;; * ) cparm="" ;; esac cp -p $cparm $thisrpm ${thisrpm#${SANDBOX}} cp -p $thisrpm $UPGRADE_DIR/RPMS/. done done } ################################################################### ## backup processing # a7_backups(){ echo echo "Backing up control files and spamassassin configs ..." echo BACKUP_DIR=$UPGRADE_DIR/backups/backup-$(date +%Y%m%d-%H%M) mkdir -p $BACKUP_DIR b73_backupfiles /etc/courier courier b73_backupfiles /etc/mail/spamassassin spam b73_backupfiles /etc/tcprules.d tcprules b73_backupfiles /home/vpopmail/etc vpopmail b73_backupfiles /var/qmail/control control b73_backupfiles /var/lib/squirrelmail squirrelmail b73_backupfiles /var/spool/squirrelmail attach if [ -d "/var/qmail/users" ]; then echo "Backing up /var/qmail/users ..." mkdir -p $BACKUP_DIR/users cp -p /var/qmail/users/cdb $BACKUP_DIR/users/. cp -p /var/qmail/users/assign $BACKUP_DIR/users/. fi if [ -d "/usr/share/clamav" ]; then echo "Backing up /usr/share/clamav ..." mkdir -p $BACKUP_DIR/clamav cp -pR /usr/share/clamav/* $BACKUP_DIR/clamav/. cp -p /etc/freshclam.conf $BACKUP_DIR/clamav/. fi if [ -f "/etc/httpd/conf/toaster.conf" ]; then echo "Backing up /etc/httpd/conf/toaster.conf ..." mkdir -p $BACKUP_DIR/toaster cp -p /etc/httpd/conf/toaster.conf $BACKUP_DIR/toaster/. fi #echo #echo "Configuration files have been backed up to $BACKUP_DIR/" #echo -n "Should we restore them after the upgrade? (yes, no) y/[n]: " #if [ "$background" ]; then # echo "Running in background, replied 'no'" REPLY=n #else # read REPLY #fi case $REPLY in "y" | "yes" ) restore=y ;; * ) unset restore ;; esac } ################################################################### ## backup control files # b73_backupfiles(){ if [ -d "$1" ]; then echo "Backing up $1 ..." mkdir -p $BACKUP_DIR/$2 cp -pR $1/* $BACKUP_DIR/$2/. fi } ################################################################### ## do the actual live upgrade # a8_do_the_upgrade(){ if [ -f /usr/bin/qmailctl ]; then qmailctl stat | grep -q "smtp: up" if [ $? == "0" ]; then b81_stop_qmail fi fi b83_upgrade_packages qtp-convert #if [ -d "$UPGRADE_DIR/backup/control" ]; then # if [ "$restore" ]; then # b85_restores # else # echo # echo "Bypassing restore of previous config files" # fi b87_start_qmail echo "qmail went down $downtime" echo "qmail came back $uptime" #fi b89_cleanup } ################################################################### ## stop qmail processing # b81_stop_qmail(){ downtime=$(date) echo echo "Stopping qmail ..." qmailctl stop sleep 5 qmailctl stat } ################################################################### ## process the upgrade # b83_upgrade_packages(){ echo echo echo "Starting the install/upgrade ..." echo "" >>$logfile echo "" >>$logfile echo "Starting the Live upgrade now" >>$logfile qtp-remove-pkgs for ntpkg in "zlib djbdns"; do if [ -f "$UPGRADE_DIR/RPMS/${ntpkg}*.rpm" ]; then rpm -Uvh --replacefiles --replacepkgs \ $UPGRADE_DIR/RPMS/${ntpkg}*.rpm | tee -a $logfile 2>&1 rc=$? if [ $rc != "0" ]; then echo "$me - rpm -Uvh for $ntpkg failed - terminating" exit $rc fi mv $UPGRADE_DIR/RPMS/${ntpkg}*.rpm $UPGRADE_DIR/old-rpms/. fi done echo "Here goes 'rpm -Uvh' for the packages we're processing ..." rpm -Uvh --replacefiles --replacepkgs $UPGRADE_DIR/RPMS/*.rpm \ | tee -a $logfile 2>&1 rc=$? if [ $rc != "0" ]; then echo "$me - rpm -Uvh $UPGRADE_DIR/RPMS/*.rpm failed - terminating" exit $rc fi echo echo "Upgrade of packages finished ..." } ################################################################### ## restore control files # b85_restores(){ echo echo "Restoring previous config files ..." find $BACKUP_DIR/ -name "*.rpmnew" -exec rm -f {} \; cp -pRf $BACKUP_DIR/courier/* /etc/courier/. cp -pf $UPGRADE_DIR/backup/clamav/freshclam.conf /etc/. cp -pf $UPGRADE_DIR/backup/toaster/toaster.conf /etc/httpd/conf/. cp -pRf $UPGRADE_DIR/backup/spam/* /etc/mail/spamassassin/. mv /etc/tcprules.d/tcp.smtp /etc/tcprules.d/tcp.smtp.new cp -pf $UPGRADE_DIR/backup/tcprules/* /etc/tcprules.d/. cp -pRf $UPGRADE_DIR/backup/vpopmail/* /home/vpopmail/etc/. cp -pRf $UPGRADE_DIR/backup/clamav/*.cvd /usr/share/clamav/. cp -pRf $UPGRADE_DIR/backup/squirrelmail/* /var/lib/squirrelmail/. cp -pRf $UPGRADE_DIR/backup/control/* /var/qmail/control/. cp -pf $UPGRADE_DIR/backup/users/* /var/qmail/users/. cp -pRf $UPGRADE_DIR/backup/attach/* /var/spool/squirrelmail/. # restore passwords if control-panel-toaster was removed pwdir=/usr/share/toaster/include for pwfile in "$pwdir/admin.htpasswd $pwdir/admin.pass"; do if [ -f "$pwfile.rpmsave" ]; then mv $pwfile $pwfile.rpmnew mv $pwfile.rpmsave $pwfile fi done } ################################################################### ## start qmail processing # b87_start_qmail(){ echo echo echo "Repairing queues ..." queue_repair.py -r 2>&1 | tee -a $logfile echo echo "Starting qmail ..." qmailctl cdb qmailctl start sleep 2 qmailctl reload echo echo "Verifying spamassassin ..." sudo -u vpopmail -H spamassassin -D --lint 2>&1 | tee -a $logfile uptime=$(date) qmailctl stat } ################################################################### ## cleanup files # b89_cleanup(){ echo echo echo "We can remove the source rpms now." q02_ask_default_n if [ $PROCEED == "y" ]; then for QMT_PKG in $QMT_PACKAGES; do rm ${SANDBOX}$UPGRADE_DIR/SRPMS/$QMT_PKG \ $UPGRADE_DIR/SRPMS/$QMT_PKG done fi echo echo "We can remove the binary rpms from the build directory now." q01_ask_default_y if [ $PROCEED == "y" ]; then for QMT_PKG in $QMT_PACKAGES; do QMT_PKGVER=${QMT_PKG%.src.rpm} QMT_PKGNAME=${QMT_PKGVER%-[^-]*-[^-]*} rpmfile=${SANDBOX}$BUILD_DIR/RPMS/$QTARCH/$QMT_PKGVER.$QTARCH.rpm if [ ! -f $rpmfile ]; then rpmfile=${SANDBOX}$BUILD_DIR/RPMS/noarch/$QMT_PKGVER.noarch.rpm if [ ! -f $rpmfile ]; then echo "Error: binary rpm not found for $QMT_PKGVER" echo "Exiting." fi fi rpmdir=$(dirname $rpmfile) for thisrpm in $(ls $rpmdir/*${QMT_PKGVER#${QMT_PKGNAME}}*); do rm $thisrpm ${thisrpm#${SANDBOX}} done done fi echo echo "We can remove the sandbox now." q01_ask_default_y if [ $PROCEED == "y" ]; then echo "Removing sandbox at $SANDBOX ..." case $(cat $SBFILE) in "L" | "C" ) rm -rf $SANDBOX ;; * ) q03_remove-union-sandbox ;; esac fi mv -f $UPGRADE_DIR/RPMS/* $UPGRADE_DIR/old-rpms/. rmdir $UPGRADE_DIR/RPMS rm $CURRENT_PACKAGES } ################################################################### # Ask to proceed, skip or exit; default y # q01_ask_default_y(){ echo -n "Shall we continue? (yes, no|skip, batch, quit) [y] / n|s / b / q : " if [ "$background" ]; then echo "Running in background, replied 'yes'" REPLY=y else read REPLY fi case $REPLY in "" | "y" | "yes" ) PROCEED=y ;; "n" | "no" | "s" | "skip" ) PROCEED=n ;; "b" ) PROCEED=y background="-b" ;; * ) echo "Exiting." exit 0 ;; esac } ################################################################### # Ask to proceed, skip or exit; default n # q02_ask_default_n(){ echo -n "Shall we continue? (yes, no|skip, batch, quit) y / [n]|s / b / q : " if [ "$background" ]; then echo "Running in background, replied 'no'" REPLY=n else read REPLY fi case $REPLY in "y" | "yes" ) PROCEED=y ;; "" | "n" | "no" | "s" | "skip" ) PROCEED=n ;; "b" ) PROCEED=n background="-b" ;; * ) echo "Exiting." exit 0 ;; esac } ################################################################### ## unmount and remove a union filesystem sandbox # q03_remove-union-sandbox(){ qtp-umount-sandbox if [ $? != "0" ]; then echo echo "$me terminating." exit 1 fi rm -rf $SANDBOX \ $OVERLAY } ################################################################### ## main script execution begins here # me=${0##*/} myver=v0.3.18 if [ ! -z "$1" ]; then case $1 in -b ) background=$1 ;; * ) echo "$me usage: $me [-b]" exit 1 ;; esac fi a1_initialization a2_get_packages_to_process a3_download_src_packages a4_check_dependencies a5_build_sandbox a6_build_binary_rpms a7_backups echo echo echo "The major portion of the install/upgrade process is now complete." echo "You may rerun this script later and simply process the update." echo echo "We are ready to do the update now. qmail will be stopped." q01_ask_default_y if [ $PROCEED == "y" ]; then a8_do_the_upgrade echo echo "All Done :) " else echo echo "Exiting upgrade for now, qmail left alone." fi echo echo "$me ending $(date)" exit 0