Esniper Update Script

Andrew
2007-05-05
2013-05-13
  • Andrew
    Andrew
    2007-05-05

    Hi,

    Thought this might be usefull; you can run this from cron as root :)

    #
    # eSniper update script
    #
    # run this from cron to determine if there is a newer version of Esniper
    #
    #

    echo
    echo "eSniper Update Tool                   v1.0"
    echo "=========================================="
    echo

    # source files are downloaded here
    cd /var/esniper

    echo "Checking For New Version..."
    echo

    # file containg current installed esniper version
    VERSIONFILE="/var/esniper/esniper-installed.txt"

    # Sysadmins
    SYSADMIN="admin@address.com"

    # Latest version
    #
    wget -q -O /var/esniper/esniper-latest.txt http://esniper.sourceforge.net/version.txt

    LATESTVERSION=`cat esniper-latest.txt | sed 's/\./-/g'`
    CURRENTVERSION=`cat $VERSIONFILE`

    # where to log output
    LOGFILE="/var/log/esniper-install.log"

    echo "Current Version = [$CURRENTVERSION]"
    echo "Latest  Version = [$LATESTVERSION]"

    echo

    # check if a new version has been released
    if [ $LATESTVERSION = $CURRENTVERSION ]
    then
            echo "eSniper up to date !!"
            exit
    fi

    echo "Updating Esniper to latest version..."

    # make dir to store new version in
    mkdir esniper-$LATESTVERSION
    cd esniper-$LATESTVERSION

    # download latest version
    wget -q http://prdownloads.sourceforge.net/esniper/esniper-$LATESTVERSION.tgz?download

    if [ $? -eq 0 ]
    then
            echo "Downloaded version $LATESTVERSION OK..."
    else
            echo -e "\n\r\n\rCould not download latest version of Esniper!\r\n\r\n" |
            mail -s "[Server Update]   Esniper Update to [$LATESTVERSION] FAILED!! " $SYSADMIN
            exit 1
    fi

    echo -en "Unpacking Source Files..."

    # unpack source files
    tar -xzf esniper-$LATESTVERSION.tgz

    if [ $? -eq 0 ]
    then
            echo "OK!"
    else
            echo -e "\n\r\n\rCould not unpack latest version of Esniper!\r\n\r\n" |
            mail -s "[Server Update]   Esniper Update to [$LATESTVERSION] FAILED!! " $SYSADMIN
            exit 1
    fi

    cd esniper-$LATESTVERSION

    echo "Building and Installing Version $LATESTVERSION "
    # build and install
    ./configure   2>&1  1>$LOGFILE  &&
    make          2>&1 1>>$LOGFILE  &&
    make install  2>&1 1>>$LOGFILE

    if [ $? -eq 0 ]
    then
            echo "Sucessfully Updated!"

            # email sysadmin the results
            cat $LOGFILE |
            mail -s "[Server Update]   Esniper Updated From [$CURRENTVERSION] To [$LATESTVERSION] " $SYSADMIN

    else
            echo "Failed during update!!"

            cat $LOGFILE |
            mail -s "[Server Update]   Esniper Update to [$LATESTVERSION] FAILED!! " $SYSADMIN

    fi

    # update installed version file
    echo $LATESTVERSION >$VERSIONFILE

     
    • Scott Nicol
      Scott Nicol
      2007-05-05

      Nice script.  Run as root?  I'll have to make a note to put something special in the configure script ;-)