#!/bin/bash # Update SVN on base virtual machine # # Example usage: # vn-svnupdate # # Approach: # 1. svn update on host # 2. Start base VM # 3. Login to base VM # 4. svn update # 5. poweroff # 6. Delete base snapshot if exists # # For more info see: http://sandilands.info/sgordon/virtnet # # $Revision: 21 $ # $Author: sgordon $ # $Date: 2013-09-20 15:12:13 +0700 (Fri, 20 Sep 2013) $ # $URL: https://sandilands.info/svn/virtnet/bin/host/vn-newnode $ # Internet access is required echo "vn: Internet access is required to update the host and base virtual machine." echo "vn: Ensure you have internet access before proceeding." echo "vn: Are you ready to proceed? y/n" read proceed if [ "${proceed}" != "y" ]; then echo "vn: Exiting vn-updatebase as user is not ready to proceed."; exit 1; fi # Script parameters # Path for virtnet directory on host, e.g. /home/user/svn/virtnet/ virtnethostpath="`dirname $BASH_SOURCE`/../../" # Path for virtnet directory on guest, e.g. /home/network/virtnet virtnetpath="/home/network/virtnet" # Update svn on host echo "vn: Getting current SVN info on host ..." svn info ${virtnethostpath} 2> /dev/null svnpathwrong=$? if [ "${svnpathwrong}" != "0" ]; then echo "vn: Either svn is misconfigured/not installed on the host or not installed in" echo "vn: ${virtnethostpath}." echo "vn: If the path is wrong, try to edit this script (vn-svnupdate) and change " echo "vn: the parameter virtnethostpath." exit 1; fi echo "vn: About to update SVN on host ..." svn update ${virtnethostpath} echo "vn: Take note of the revision number in the above line that says: " echo "vn: 'Updated to revision X' or 'At revision X.'" #svn info ${virtnethostpath} # Check if base exists echo "vn: Checking that base VM exists; starting if not already running ..." VBoxManage list vms | grep "\"base\"" > /dev/null basenotexist=$? if [ "${basenotexist}" != "0" ]; then echo "vn: base virtual machine does not exist. See http://sandilands.info/sgordon/virtnet" echo "vn: for installing the base virtual machine." exit 1; fi # Start base if not already running VBoxManage list runningvms | grep "\"base\"" > /dev/null isrunning=$? if [ "${isrunning}" = "1" ]; then VBoxManage startvm --type headless base fi echo "vn: About to login to base VM and update SVN (may take a few minutes) ..." # Login to base and perform operations ssh -o "StrictHostKeyChecking no" -l network -p 2201 -i ${virtnethostpath}/data/defaults/home/network/.ssh/id_rsa localhost 'svn cleanup '${virtnetpath} ssh -o "StrictHostKeyChecking no" -l network -p 2201 -i ${virtnethostpath}/data/defaults/home/network/.ssh/id_rsa localhost 'svn update '${virtnetpath} echo "vn: You should see 'Updated to revision Y' or 'At revision Y.' " echo "vn: Compare the revision number Y to the revision X above. They should be the same." # Poweroff base VBoxManage controlvm base poweroff echo "vn: base has now been updated and turned off." echo "vn: Deleting the base snapshot (it will be auto-created when running vn-createtopology)" # Delete the base snapshot of it exists VBoxManage snapshot base list 2> /dev/null snmatch=$? if [ "${snmatch}" = "0" ]; then # Has snapshots # Delete snapshot VBoxManage snapshot base delete base fi echo "vn: Update is finished."