#!/bin/bash # # Compare installed versions with latest release # # Erik A. Espinoza # Eric 'shubes' # Jake Vickers # ################################################################### # Change Log # 07/15/2009 shubes: added qtp-whatami so $BUILD_DIR is available # 05/04/2009 shubes: added current version to message # Thanks to Kent Busbee for this enhancement # 04/05/2008 shubes: replaced reorg fix with call to qtp-get-pkg-list # 10/25/2007 Jake : Fixed a bug in the reorganization portion of the script # 06/25/2007 Jake : Added scripting to reorganize the current.txt file that # was being downloaded so that it's in the correct installation # order, instead of alphabetical order. # 03/09/2007 shubes: removed QMT_QMTVER which was moved into compare function # 03/06/2007 shubes: fixed version checking for stock zlib # 01/09/2007 shubes: added logic for >< version comparison # added option to check development # 09/06/2006 shubes: Eliminated variables, renamed for qtp package # 06/13/2006 shubes: Restructured for maintainability by Eric 'shubes' # 07/29/2005 espinoza: Bugfix - Changed QMAD to QMAL for qmail-toaster detection # 07/27/2005 espinoza: Initial Release ################################################################### ## initialization # If server list is unavailable, notify the user # a1_initialization(){ . qtp-whatami -s . qtp-config -s if [ "$usedevel" ]; then devlist=`wget -q -O - ${QMT_DEV}/info/current.txt` fi pkglist=$(qtp-get-pkg-list ${QMT_WEB}/info/current.txt) if [ -z "$pkglist" ]; then message="Package List Unavailable" q01_error_exit fi } ################################################################### ## put list of upgrades available in templist # a3_check_each_package(){ QMT_PKGNAME=${QMT_PKG%-[^-]*-[^-]*.src.rpm} if [ ! -z "$devlist" ] \ && [ "$QMT_PKG" == "$QMT_PKGNAME" ]; then b32_get_stable_package fi QMT_PKGVER=${QMT_PKG%.src.rpm} QMT_PKGNAME=${QMT_PKGVER%-[^-]*-[^-]*} QMT_VERSION=${QMT_PKGVER#${QMT_PKGNAME}-} installed_pkgver=`rpm -q ${QMT_PKGNAME}` if [ $? == "0" ] \ && [ "$installed_pkgver" != $QMT_PKGVER ]; then x01_compare_versions if [ "$?" == "0" ]; then echo -e " available: $QMT_PKGVER\n(installed: $installed_pkgver)" >>$templist fi fi } ################################################################### ## use stable package version # b32_get_stable_package(){ QMT_PKG="" for pkg in $pkglist; do if [ "$QMT_PKGNAME" == ${pkg%-[^-]*-[^-]*.src.rpm} ]; then QMT_PKG=$pkg break fi done if [ -z "$QMT_PKG" ]; then message="$me - program bug - stable package $QMT_PKGNAME not found" q01_error_exit fi } ################################################################### ## Notify user of new packages # a5_notify_user(){ if [ "$SEND_EMAIL_TO" ]; then if [ -f $templist ]; then mail -s "New Qmail-Toaster Packages Available" $SEND_EMAIL_TO <$templist fi else if [ -f $templist ]; then echo "New Qmail-Toaster Packages Available:" cat $templist else echo "No New Qmail-Toaster Packages Available" fi fi } ################################################################### ## send an error message and exit # q01_error_exit(){ if [ "$SEND_MAIL_TO" ]; then echo "$message" | mail -s "$me Error" $SEND_EMAIL_TO else echo "$message" fi exit 1 } ################################################################### ## main script execution begins here # me=${0##*/} myver=v0.4.1 usedevel="" while (( "$#" )); do case $1 in "-h" | "-help" ) echo "$me $myver usage: $me [-d] [mailto]" exit 1 ;; "-d" | "-dev" | "-devel" | "-develop" ) usedevel=y ;; * ) SEND_EMAIL_TO=$1 ;; esac shift done # set a temp file and make sure it's deleted when we're done templist=$(tempfile 2>/dev/null) || templist=/tmp/$me.$$ trap "rm -f $templist" 0 1 2 5 15 a1_initialization for QMT_PKG in ${devlist:-${pkglist}}; do a3_check_each_package done a5_notify_user exit 0