ak2766

GNS3 Update Script - UPDATED

Apr 6th, 2015
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.29 KB | None | 0 0
  1. #!/bin/bash
  2. # script to update GNS3 apps
  3. apps=`cat <<EOF
  4. gns3-gui
  5. gns3-server
  6. dynamips
  7. vboxwrapper
  8. iniparser
  9. iouyap
  10. EOF`
  11.  
  12. usage(){
  13.     echo ""
  14.     echo "This script updates GNS3 modules"
  15.     echo ""
  16.     echo " USAGE: $0 [-a] [-c] [-h] [-p /path/to/codebase] [module]"
  17.     echo "   where:"
  18.     echo "     [-h]       = displays this help message"
  19.     echo "     [-a]       = update, compile and install all modules"
  20.     echo "     [-c]       = recompile and install without updating git repo"
  21.     echo "     [-p /path] = recompile and install from different location"
  22.     echo "                  - most probably an older repo path"
  23.     echo "     [module]   = only operate on this module"
  24.     echo""
  25.     exit 1
  26. }
  27.  
  28.  
  29. # Process commandline arguments
  30. parseopts() {
  31.     while getopts :achp: Option; do
  32.         case $Option in
  33.             a)
  34.                 # This is just a place holder for nothing
  35.                 all=1
  36.                 opts=1
  37.                 ;;
  38.             c)
  39.                 recompile=1
  40.                 opts=1
  41.                 ;;
  42.             p)
  43.                 gns3path="$OPTARG"
  44.                 opts=1
  45.                 shift
  46.                 ;;
  47.             h|*)
  48.                 usage
  49.                 ;;
  50.         esac
  51.     done
  52. }
  53.  
  54. gitclone(){
  55.     # here we clone the application we are after
  56.     case $1 in
  57.         gns3-gui)
  58.             git clone https://github.com/GNS3/gns3-gui
  59.             ;;
  60.         gns3-server)
  61.             git clone https://github.com/GNS3/gns3-server
  62.             ;;
  63.         dynamips)
  64.             git clone https://github.com/GNS3/dynamips
  65.             ;;
  66.         vboxwrapper)
  67.             git clone https://github.com/GNS3/vboxwrapper
  68.             ;;
  69.         iniparser)
  70.             git clone https://github.com/ndevilla/iniparser.git
  71.             ;;
  72.         iouyap)
  73.             git clone https://github.com/GNS3/iouyap
  74.             ;;
  75.     esac
  76. }
  77.  
  78. if [ $# -eq 0 ]; then
  79.     usage
  80. fi
  81. all=0
  82. recompile=0
  83. gns3path=""
  84. opts=0
  85. parseopts $*
  86. if [ ${opts} -ne 0 ]; then
  87.     shift
  88. fi
  89. gns3path=${gns3path:-/opt/codebase}
  90. if ! [[ "${gns3path}" =~ "/opt/codebase" ]]; then
  91.     shift
  92. fi
  93. cd ${gns3path}
  94.  
  95. if [ ${all} -eq 1 ] && [ $# -eq 1 ]; then
  96.     echo "You cannot have both [-a] and [module]"
  97.     echo "exiting..."
  98.     exit 1
  99. fi
  100.  
  101. # if user supplied a variable at command line, then only update that component
  102. if [ ${all} -eq 0 ]; then
  103.     matchfound=0
  104.     if [ $# -eq 1 ]; then
  105.         for app in ${apps}; do
  106.             if [[ "${app}" =~ "$1" ]]; then
  107.                 matchfound=1
  108.             fi
  109.         done
  110.         if [ ${matchfound} -ne 1 ]; then
  111.             echo "The supplied component does not exist..."
  112.             exit 1
  113.         else
  114.             apps=$1
  115.         fi
  116.     fi
  117. fi
  118.  
  119. for app in ${apps}; do
  120.     clone=0
  121.     pull=0
  122.     gitlog="/tmp/gitpull-${app}.log"
  123.     if [ ${recompile} -ne 1 ]; then
  124.         if [ ! -d ${app} ]; then
  125.             clone=1
  126.             gitclone ${app} >${gitlog} 2>&1
  127.             retval=$?
  128.             gitstat=$(egrep 'Checking connectivity... done.' ${gitlog} | wc -l)
  129.             pushd ${app} >/dev/null 2>&1
  130.         else
  131.             pull=1
  132.             pushd ${app} >/dev/null 2>&1
  133.             git pull >${gitlog} 2>&1
  134.             retval=$?
  135.             gitstat=$(egrep 'up-to-date' ${gitlog} | wc -l)
  136.         fi
  137.     else
  138.         if [ ! -d ${app} ]; then
  139.             echo "Skipping ${app} as there is no local repo..."
  140.         else
  141.             pushd ${app} >/dev/null 2>&1
  142.         fi
  143.         # we are only running this to recompile the current source tree
  144.         gitstat=1
  145.         retval=0
  146.     fi
  147.     if [ ${gitstat} -ne 0 ] && [ ${recompile} -eq 0 ]; then
  148.         echo "${app} up-to-date..."
  149.         popd >/dev/null 2>&1
  150.         continue
  151.     else
  152.         echo "Compiling and installing ${app}..."
  153.     fi
  154.     if [ ${retval} -ne 0 ]; then
  155.         echo "###############################################################"
  156.         if [ ${clone} -eq 1 ]; then
  157.             echo "# Errors encountered while cloning git repo for ${app}"
  158.         elif [ ${pull} -eq 1 ]; then
  159.             echo "# Errors encountered while updating git repo for ${app}"
  160.         fi
  161.         echo "###############################################################"
  162.         popd >/dev/null 2>&1
  163.         continue
  164.     else
  165.         tmstmp="build-$(date '+%Y%m%d-%H%M%S')"
  166.         movealong=0
  167.         case ${app} in
  168.             vboxwrapper)
  169.                 retval=1
  170.                 while [ ${retval} -ne 0 ]; do
  171.                     echo "### PYTHON2 ###" > ${tmstmp}.log
  172.                     sudo python2 setup.py install >> ${tmstmp}.log 2>&1
  173.                     retval=$?
  174.                     if [ ${retval} -ne 0 ]; then
  175.                         popd >/dev/null 2>&1
  176.                         echo "Failed python2 setup.py install for ${app}..."
  177.                         movealong=1
  178.                         break
  179.                     fi
  180.                 done
  181.         if [ ${movealong} -eq 1 ]; then
  182.                     popd >/dev/null 2>&1
  183.                     continue
  184.                 fi
  185.                 ;;
  186.             dynamips)
  187.                 [ -d build ] || mkdir build
  188.                 retval=1
  189.                 while [ ${retval} -ne 0 ]; do
  190.                     echo "### CMAKE ###" > ${tmstmp}.log
  191.                     pushd build >/dev/null 2>&1
  192.                     /bin/rm -rf *
  193.                     cmake .. >> ${tmstmp}.log 2>&1
  194.                     retval=$?
  195.                     if [ ${retval} -ne 0 ]; then
  196.                         popd >/dev/null 2>&1
  197.                         echo "Running cmake on Dynamips"
  198.                         echo "Failed cmake 5 times - intervention required..."
  199.                         movealong=1
  200.                         break
  201.                     fi
  202.                 done
  203.                 if [ ${movealong} -eq 1 ]; then
  204.                     popd >/dev/null 2>&1
  205.                     continue
  206.                 fi
  207.                 retval=1
  208.                 while [ ${retval} -ne 0 ]; do
  209.                     echo "### MAKE ###" >> ${tmstmp}.log
  210.                     make >> ${tmstmp}.log 2>&1
  211.                     retval=$?
  212.                     if [ ${retval} -ne 0 ]; then
  213.                         echo "Failed make for ${app}..."
  214.                         movealong=1
  215.                         break
  216.                     fi
  217.                 done
  218.                 if [ ${movealong} -eq 1 ]; then
  219.                     popd >/dev/null 2>&1
  220.                     continue
  221.                 fi
  222.                 retval=1
  223.                 while [ ${retval} -ne 0 ]; do
  224.                     echo "### MAKE INSTALL ###" >> ${tmstmp}.log
  225.                     sudo make install >> ${tmstmp}.log 2>&1
  226.                     retval=$?
  227.                     if [ ${retval} -ne 0 ]; then
  228.                         echo "Failed make install for ${app}..."
  229.                         movealong=1
  230.                         break
  231.                     else
  232.                         sudo /sbin/setcap cap_net_raw,cap_net_admin=eip /usr/local/bin/dynamips
  233.                     fi
  234.                 done
  235.                 if [ ${movealong} -eq 1 ]; then
  236.                     popd >/dev/null 2>&1
  237.                     continue
  238.                 fi
  239.                 popd >/dev/null 2>&1
  240.                 ;;
  241.             iniparser)
  242.                 retval=1
  243.                 while [ ${retval} -ne 0 ]; do
  244.                     echo "### CLEAN ###" > ${tmstmp}.log
  245.                     make clean >> ${tmstmp}.log 2>&1
  246.                     echo "### MAKE ###" >> ${tmstmp}.log
  247.                     make >> ${tmstmp}.log 2>&1
  248.                     retval=$?
  249.                     if [ ${retval} -ne 0 ]; then
  250.                         echo "Failed make install for ${app}..."
  251.                         movealong=1
  252.                         break
  253.                     fi
  254.                 done
  255.                 if [ ${movealong} -eq 1 ]; then
  256.                     popd >/dev/null 2>&1
  257.                     continue
  258.                 fi
  259.                 sudo cp -f libiniparser.* /usr/lib/
  260.                 sudo cp -f src/iniparser.h /usr/local/include
  261.                 sudo cp -f src/dictionary.h /usr/local/include
  262.                 ;;
  263.             iouyap)
  264.                 retval=1
  265.                 while [ ${retval} -ne 0 ]; do
  266.                     echo "### MAKE ###" > ${tmstmp}.log
  267.                     make clean >> ${tmstmp}.log 2>&1
  268.                     echo "### MAKE ###" >> ${tmstmp}.log
  269.                     make >> ${tmstmp}.log 2>&1
  270.                     retval=$?
  271.                     if [ ${retval} -ne 0 ]; then
  272.                         echo "Failed make for ${app}..."
  273.                         movealong=1
  274.                         break
  275.                     fi
  276.                 done
  277.                 if [ ${movealong} -eq 1 ]; then
  278.                     popd >/dev/null 2>&1
  279.                     continue
  280.                 fi
  281.                 echo "### INSTALL ###" >> ${tmstmp}.log
  282.                 sudo make install >> ${tmstmp}.log 2>&1
  283.                 retval=$?
  284.                 if [ ${retval} -ne 0 ]; then
  285.                     echo "Failed make install for ${app}..."
  286.                     movealong=1
  287.                 fi
  288.                 if [ ${movealong} -eq 1 ]; then
  289.                     popd >/dev/null 2>&1
  290.                     continue
  291.                 else
  292.                     chmod 755 iouyap
  293.                     sudo /bin/mv -f iouyap /usr/local/bin/
  294.                 fi
  295.                 ;;
  296.             gns3-gui|gns3-server)
  297.                 retval=1
  298.                 while [ ${retval} -ne 0 ]; do
  299.                     echo "### PYTHON3 - ${app} ###" > ${tmstmp}.log
  300.                     sudo python3 setup.py install >> ${tmstmp}.log 2>&1
  301.                     retval=$?
  302.                     if [ ${retval} -ne 0 ]; then
  303.                         echo "Failed python3 setup.py install for ${app}..."
  304.                         movealong=1
  305.                         break
  306.                     fi
  307.                 done
  308.                 if [ ${movealong} -eq 1 ]; then
  309.                     popd >/dev/null 2>&1
  310.                     continue
  311.                 fi
  312.                 ;;
  313.         esac
  314.     fi
  315.     popd >/dev/null 2>&1
  316. done
Advertisement
Add Comment
Please, Sign In to add comment