#!/bin/bash # # Copyright (C) 2006-2008 Eric Shubert # # Remove troublesome and obsolete packages when upgrading # # This script is invoked by qtp-newmodel and qtp-build-rpms. # Some packages need to be removed before upgrading as a one-time measure: # .) courier-imap-toaster-doc is obsolete # .) horde-toaster is obsolete # .) libdomainkeys was changed to libdomainkeys-toaster # .) control-panel-toaster needs to be removed if courier-imap-toaster # is less than version 4, due to the addition of courier-auth-toaster # .) send-emails-toaster is a sub-package to control-panel-toaster, # so it should be removed too to avoid problems with restarting # # note, it'd be nice to identify specific version/releases here # # Future Enhancements # .) only remove packages when absolutely necessary # (control-panel-toaster) # ################################################################### # change log # 04/20/08 shubes - modified clamav for versions <1.3.17 # 04/05/08 shubes - removed spamassassin-toaster, as that .spec file is fixed # (as of spamassassin-toaster-3.1.4-1.3.14) # 03/21/07 shubes - check if package is installed before comparing # 03/09/07 shubes - added clamav if version <1.3.11 # 10/20/06 shubes - created, consolidating logic from calling programs. ################################################################### ## check and set up the environment # a1_initialization(){ UPDT_PACKAGES=$(cat $CURRENT_PACKAGES) if [ -z "${UPDT_PACKAGES}" ] ; then echo "$me Error - package list not found" exit 1 fi # if running in sandbox, indicate so in message sandbox_msg="" if [ -f /boot/.$(basename $SANDBOX) ]; then sandbox_msg="from sandbox (not for real)" fi . qtp-config -s } ################################################################### ## create list of obsolete packages ## any toaster-debuginfo packages are obsolete too # a3_obsolete_packages(){ removepkgs="\ courier-imap-toaster-doc \ horde-toaster \ libdomainkeys \ spamassassin \ spamassassin-tools \ " for dbg_pkg in $(rpm -qa | grep toaster-debuginfo); do removepkgs="$removepkgs $dbg_pkg" done } ################################################################### ## remove packages only if they're being installed # a5_problem_packages(){ # any version of these packages will be removed remove_list="\ control-panel \ " # only packages <= the specific version will be removed remove_older="\ clamav-toaster-0.92.1-1.3.17 \ " for UPDT_PKG in $UPDT_PACKAGES; do UPDT_PKGNAME=${UPDT_PKG%-[^-]*-[^-]*.src.rpm} UPDT_NAME=${UPDT_PKGNAME%-toaster} b52_remove_any_version b54_remove_older_version done } ################################################################### ## add package to list if installed, regardless of version # b52_remove_any_version(){ for remove_name in $remove_list; do if [ "$UPDT_NAME" == "$remove_name" ]; then if [ "$UPDT_NAME" == "control-panel" ]; then removepkgs="$removepkgs send-emails-toaster" fi removepkgs="$removepkgs $UPDT_PKGNAME" fi done } ################################################################### ## add package to list if installed verion is older than specified version # b54_remove_older_version(){ for remove_pkg in $remove_older; do remove_pkgname=${remove_pkg%-[^-]*-[^-]*} if [ "$UPDT_PKGNAME" == "$remove_pkgname" ]; then QMT_PKGVER=$(rpm -q $remove_pkgname) if [ $? == "0" ]; then QMT_PKGNAME=${QMT_PKGVER%-[^-]*-[^-]*} QMT_VERSION=${QMT_PKGVER#${QMT_PKGNAME}-} installed_pkgver=$remove_pkg x01_compare_versions if [ $? == "1" ]; then removepkgs="$removepkgs $UPDT_PKGNAME" fi fi fi done } ################################################################### ## remove packages in list if they're installed # a7_remove_packages(){ for pkg in $removepkgs; do rpm -q $pkg > /dev/null \ && rpm -e --nodeps $pkg >>logfile 2>&1 \ && echo "REMOVED $pkg $sandbox_msg" | tee -a $logfile done } ################################################################### ## main script execution begins here # me=$(basename $0) myver=v0.3.1 echo "$me $myver" a1_initialization a3_obsolete_packages a5_problem_packages a7_remove_packages exit 0