Skip to end of metadata
Go to start of metadata

Symptom:

using the Men & Mice compiled Unbound packages from http://support.menandmice.com/download/unbound/ it is possible to have multiple versions of Unbound installed concurrently. This eases the testing of new versions and also a quick roll-back if needed to an previous version.

The Men & Mice compiled Unbound binaries install to /usr/local/unbound-<version>, however the binaries are compiled to run from /usr/local/unbound. A symbolic link must be set from the current version installation directory to /usr/local/unbound.

The script below automates the linking, it also provides a quick way to switch back to previous used version of Unbound.

Usage:

download the script, make it executable (chmod +x switchunbound) and move it to a place where it can be found in the search path.
# switchunbound
Usage: /usr/local/bin/switchunbound {switch <version>|revert|list}
executing the script without any arguments will print the possible arguments.
# switchunbound list
/usr/local/unbound-1.4.6
/usr/local/unbound-1.4.7-svn
/usr/local/unbound-old
The argument list will list all available Unbound versions under /usr/local
# switchunbound switch unbound-1.4.7-svn
Switch to unbound-1.4.7-svn
the argument "switch" together with a version number will switch to that Unbound version
# switchunbound revert
will revert back to the previous active version of unbound

Caution:

The script will NOT start or stop the Unbound process, it will only switch the symbolic link. After switching the link, the Unbound process must be stopped and re-started to enable the new version.

Solution



#!/bin/sh
# Copyright (c) 2005-2010 Men & Mice

LOCATION=/usr/local

##################### End of program specific definitions #####################


# List available Unbound versions
doList() {
    ls -d1 $LOCATION/unbound-*
}

# switch to a new Unbound version
doSwitch() {
    echo "Switch to $VERS"
        if [ -d $LOCATION/$VERS ] ; then
        if [ -L $LOCATION/unbound ] ; then
                rm $LOCATION/unbound-old
                  mv $LOCATION/unbound $LOCATION/unbound-old
        fi
        ln -s $LOCATION/$VERS $LOCATION/unbound
    else
        if [ -d $LOCATION/unbound-$VERS ] ; then
            if [ -L $LOCATION/unbound ] ; then
                                rm $LOCATION/unbound-old
                mv  $LOCATION/unbound $LOCATION/unbound-old
            fi
            ln -s $LOCATION/unbound-$VERS $LOCATION/unbound
        else
            echo "Cannot find Unbound Version $VERS!"   
        fi   
    fi

}

# revert to previous Unbound Version
doRevert() {
    if [ -L $LOCATION/unbound-old ] ; then
        mv $LOCATION/unbound $LOCATION/unbound-tmp
        mv $LOCATION/unbound-old $LOCATION/unbound
                mv $LOCATION/unbound-tmp $LOCATION/unbound-old
    else
        echo "no saved previous version of Unbound found"   
    fi
}


RETVAL=0
VERS="$2"

case "$1" in
    list)
        doList
        ;;
    switch)
        doSwitch
        ;;
    revert)
        doRevert
        ;;
    *)
        echo "Usage: $0 {switch <version>|revert|list}"
        exit 1
esac


exit $RETVAL