ak2766 icon

GNS3 Update Script - UPDATED

ak2766 | PRO | 04/07/15 03:03:01 AM UTC | 0 ⭐ | 475 👁️ | Never ⏰ | []
Bash |

7.29 KB

|

None

|

0 👍

/

0 👎

#!/bin/bash
# script to update GNS3 apps
apps=`cat <<EOF
gns3-gui
gns3-server
dynamips
vboxwrapper
iniparser
iouyap
EOF`
 
usage(){
    echo ""
    echo "This script updates GNS3 modules"
    echo ""
    echo " USAGE: $0 [-a] [-c] [-h] [-p /path/to/codebase] [module]"
    echo "   where:"
    echo "     [-h]       = displays this help message"
    echo "     [-a]       = update, compile and install all modules"
    echo "     [-c]       = recompile and install without updating git repo"
    echo "     [-p /path] = recompile and install from different location"
    echo "                  - most probably an older repo path"
    echo "     [module]   = only operate on this module"
    echo""
    exit 1
}
 
 
# Process commandline arguments
parseopts() {
    while getopts :achp: Option; do
        case $Option in
            a)
                # This is just a place holder for nothing
                all=1
                opts=1
                ;;
            c)
                recompile=1
                opts=1
                ;;
            p)
                gns3path="$OPTARG"
                opts=1
                shift
                ;;
            h|*)
                usage
                ;;
        esac
    done
}
 
gitclone(){
    # here we clone the application we are after
    case $1 in
        gns3-gui)
            git clone https://github.com/GNS3/gns3-gui
            ;;
        gns3-server)
            git clone https://github.com/GNS3/gns3-server
            ;;
        dynamips)
            git clone https://github.com/GNS3/dynamips
            ;;
        vboxwrapper)
            git clone https://github.com/GNS3/vboxwrapper
            ;;
        iniparser)
            git clone https://github.com/ndevilla/iniparser.git
            ;;
        iouyap)
            git clone https://github.com/GNS3/iouyap
            ;;
    esac
}
 
if [ $# -eq 0 ]; then
    usage
fi
all=0
recompile=0
gns3path=""
opts=0
parseopts $*
if [ ${opts} -ne 0 ]; then
    shift
fi
gns3path=${gns3path:-/opt/codebase}
if ! [[ "${gns3path}" =~ "/opt/codebase" ]]; then
    shift
fi
cd ${gns3path}
 
if [ ${all} -eq 1 ] && [ $# -eq 1 ]; then
    echo "You cannot have both [-a] and [module]"
    echo "exiting..."
    exit 1
fi
 
# if user supplied a variable at command line, then only update that component
if [ ${all} -eq 0 ]; then
    matchfound=0
    if [ $# -eq 1 ]; then
        for app in ${apps}; do
            if [[ "${app}" =~ "$1" ]]; then
                matchfound=1
            fi
        done
        if [ ${matchfound} -ne 1 ]; then
            echo "The supplied component does not exist..."
            exit 1
        else
            apps=$1
        fi
    fi
fi
 
for app in ${apps}; do
    clone=0
    pull=0
    gitlog="/tmp/gitpull-${app}.log"
    if [ ${recompile} -ne 1 ]; then
        if [ ! -d ${app} ]; then
            clone=1
            gitclone ${app} >${gitlog} 2>&1
            retval=$?
            gitstat=$(egrep 'Checking connectivity... done.' ${gitlog} | wc -l)
            pushd ${app} >/dev/null 2>&1
        else
            pull=1
            pushd ${app} >/dev/null 2>&1
            git pull >${gitlog} 2>&1
            retval=$?
            gitstat=$(egrep 'up-to-date' ${gitlog} | wc -l)
        fi
    else
        if [ ! -d ${app} ]; then
            echo "Skipping ${app} as there is no local repo..."
        else
            pushd ${app} >/dev/null 2>&1
        fi
        # we are only running this to recompile the current source tree
        gitstat=1
        retval=0
    fi
    if [ ${gitstat} -ne 0 ] && [ ${recompile} -eq 0 ]; then
        echo "${app} up-to-date..."
        popd >/dev/null 2>&1
        continue
    else
        echo "Compiling and installing ${app}..."
    fi
    if [ ${retval} -ne 0 ]; then
        echo "###############################################################"
        if [ ${clone} -eq 1 ]; then
            echo "# Errors encountered while cloning git repo for ${app}"
        elif [ ${pull} -eq 1 ]; then
            echo "# Errors encountered while updating git repo for ${app}"
        fi
        echo "###############################################################"
        popd >/dev/null 2>&1
        continue
    else
        tmstmp="build-$(date '+%Y%m%d-%H%M%S')"
        movealong=0
        case ${app} in
            vboxwrapper)
                retval=1
                while [ ${retval} -ne 0 ]; do
                    echo "### PYTHON2 ###" > ${tmstmp}.log
                    sudo python2 setup.py install >> ${tmstmp}.log 2>&1
                    retval=$?
                    if [ ${retval} -ne 0 ]; then
                        popd >/dev/null 2>&1
                        echo "Failed python2 setup.py install for ${app}..."
                        movealong=1
                        break
                    fi
                done
        if [ ${movealong} -eq 1 ]; then
                    popd >/dev/null 2>&1
                    continue
                fi
                ;;
            dynamips)
                [ -d build ] || mkdir build
                retval=1
                while [ ${retval} -ne 0 ]; do
                    echo "### CMAKE ###" > ${tmstmp}.log
                    pushd build >/dev/null 2>&1
                    /bin/rm -rf *
                    cmake .. >> ${tmstmp}.log 2>&1
                    retval=$?
                    if [ ${retval} -ne 0 ]; then
                        popd >/dev/null 2>&1
                        echo "Running cmake on Dynamips"
                        echo "Failed cmake 5 times - intervention required..."
                        movealong=1
                        break
                    fi
                done
                if [ ${movealong} -eq 1 ]; then
                    popd >/dev/null 2>&1
                    continue
                fi
                retval=1
                while [ ${retval} -ne 0 ]; do
                    echo "### MAKE ###" >> ${tmstmp}.log
                    make >> ${tmstmp}.log 2>&1
                    retval=$?
                    if [ ${retval} -ne 0 ]; then
                        echo "Failed make for ${app}..."
                        movealong=1
                        break
                    fi
                done
                if [ ${movealong} -eq 1 ]; then
                    popd >/dev/null 2>&1
                    continue
                fi
                retval=1
                while [ ${retval} -ne 0 ]; do
                    echo "### MAKE INSTALL ###" >> ${tmstmp}.log
                    sudo make install >> ${tmstmp}.log 2>&1
                    retval=$?
                    if [ ${retval} -ne 0 ]; then
                        echo "Failed make install for ${app}..."
                        movealong=1
                        break
                    else
                        sudo /sbin/setcap cap_net_raw,cap_net_admin=eip /usr/local/bin/dynamips
                    fi
                done
                if [ ${movealong} -eq 1 ]; then
                    popd >/dev/null 2>&1
                    continue
                fi
                popd >/dev/null 2>&1
                ;;
            iniparser)
                retval=1
                while [ ${retval} -ne 0 ]; do
                    echo "### CLEAN ###" > ${tmstmp}.log
                    make clean >> ${tmstmp}.log 2>&1
                    echo "### MAKE ###" >> ${tmstmp}.log
                    make >> ${tmstmp}.log 2>&1
                    retval=$?
                    if [ ${retval} -ne 0 ]; then
                        echo "Failed make install for ${app}..."
                        movealong=1
                        break
                    fi
                done
                if [ ${movealong} -eq 1 ]; then
                    popd >/dev/null 2>&1
                    continue
                fi
                sudo cp -f libiniparser.* /usr/lib/
                sudo cp -f src/iniparser.h /usr/local/include
                sudo cp -f src/dictionary.h /usr/local/include
                ;;
            iouyap)
                retval=1
                while [ ${retval} -ne 0 ]; do
                    echo "### MAKE ###" > ${tmstmp}.log
                    make clean >> ${tmstmp}.log 2>&1
                    echo "### MAKE ###" >> ${tmstmp}.log
                    make >> ${tmstmp}.log 2>&1
                    retval=$?
                    if [ ${retval} -ne 0 ]; then
                        echo "Failed make for ${app}..."
                        movealong=1
                        break
                    fi
                done
                if [ ${movealong} -eq 1 ]; then
                    popd >/dev/null 2>&1
                    continue
                fi
                echo "### INSTALL ###" >> ${tmstmp}.log
                sudo make install >> ${tmstmp}.log 2>&1
                retval=$?
                if [ ${retval} -ne 0 ]; then
                    echo "Failed make install for ${app}..."
                    movealong=1
                fi
                if [ ${movealong} -eq 1 ]; then
                    popd >/dev/null 2>&1
                    continue
                else
                    chmod 755 iouyap
                    sudo /bin/mv -f iouyap /usr/local/bin/
                fi
                ;;
            gns3-gui|gns3-server)
                retval=1
                while [ ${retval} -ne 0 ]; do
                    echo "### PYTHON3 - ${app} ###" > ${tmstmp}.log
                    sudo python3 setup.py install >> ${tmstmp}.log 2>&1
                    retval=$?
                    if [ ${retval} -ne 0 ]; then
                        echo "Failed python3 setup.py install for ${app}..."
                        movealong=1
                        break
                    fi
                done
                if [ ${movealong} -eq 1 ]; then
                    popd >/dev/null 2>&1
                    continue
                fi
                ;;
        esac
    fi
    popd >/dev/null 2>&1
done

Comments