clockwerk-tools – Rev 47

Subversion Repositories:
Rev:
#!/bin/bash
###########################################################################
##  Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3      ##
##  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  ##
##  rights of fair usage, the disclaimer and warranty conditions.        ##
###########################################################################

dialog --msgbox "This tool will upgrade the Clockwerk machine." 10 70

# Clockwerk upgrade
if [ -f lib/install-packages.txt ] && [ -f lib/uninstall-packages.txt ]; then
  dialog --yesno "By selecting yes here, the Clockwerk will install or remove packages essential for OpenSim from the virtual machine. You should say yes here unless you have made major changes to the Clockwerk machine. Would you like to process the list of packages to install or remove?" 10 70
  if [ $? == "0" ]; then
    # Update repositories
    aptitude -y update
    aptitude -y upgrade
    # Remove packages
    cat lib/uninstall-packages.txt | while read p; do 
        PACKAGE=`dpkg -l | grep "$p" | head -1 | awk '{ print $2 }'`
        if [ "$PACKAGE" == "$p" ]; then 
          aptitude -y purge $p
        fi
    done
    # Install packages
    cat lib/install-packages.txt | while read i; do
        PACKAGE=`dpkg -l | grep "$i" | head -1 | awk '{ print $2 }'`
        if [ "$PACKAGE" != "$i" ]; then
          aptitude -y purge $i
          aptitude -y install $i
        fi 
    done
  fi
fi

# Update system files
dialog --yesno "This part of the upgrade process updates the Clockwerk system files with updated versions from the official repository. Unless you have heavily modified the Clockwerk machine, you should say yes here. Would you like to update the Clockwerk system files?" 10 70
if [ $? == "0" ]; then
  cp -Rap lib/fs/* /
  kill -s HUP `pidof cron`
fi

# OpenSim upgrade
pushd ./
cd ../
echo "[Clockwerk] Updating sources..."
rm -rf clockwerk-opensim
rm -rf /srv/clockwerk/clockwerk-opensim
svn co --config-option servers:global:http-timeout=300 http://svn.was.fm/clockwerk-opensim
cd clockwerk-opensim
svn update --accept base
dialog --yesno "By selecting yes here, the OpenSim sources will be updated from the development repository, compiled and added to the current OpenSim working directory. Selecting yes here will not affect any modifications you may have done to OpenSim's ini files. Upgrade the OpenSim binaries to the lastest development version?" 10 70
if [ $? == "0" ]; then
        echo "[Clockwerk] Cleaning..."
        yes | ./runprebuild.sh clean
        echo "[Clockwerk] Prebuild..."
        ./runprebuild.sh
        echo "[Clockwerk] Build..."
        nant
        if [ ! -d /srv/opensim ]; then 
                mkdir -p /srv/opensim
        fi
        echo "[Clockwerk] Copying files..."
        mkdir -p /srv/opensim
        find bin/ -name \*.ini -o -name \*.config -o -name assets -o -name assetcache -exec rm -rf '{}' \;
        cp -Ra bin/* /srv/opensim/
        echo "[Clockwerk] Changing ownership..."
        chown -R opensim:opensim /srv/opensim/
fi
if [ -d ../clockwerk-opensim-config/ ]; then
        cd ../clockwerk-opensim-config/
        svn update
        dialog --yesno "This option will update OpenSim's configuration files EXCEPT Regions.ini which will not be overwritten. It is useful to synchronize OpenSim's configuration files with new options from the development branch. If you have made changes to OpenSim's ini files, a resonable answer will be no. However, at some point you should make a backup and sync with the development version. Update the configuration files now?" 12 70
        if [ $? == "0" ]; then
                if [ ! -d /srv/opensim ]; then
                        mkdir -p /srv/opensim
                fi
                echo "[Clockwerk] Updating configuration..."
                cp -Ra * /srv/opensim/
                echo "[Clockwerk] Changing ownership..."
                chown -R opensim:opensim /srv/opensim/
                mysql -u debian-sys-maint -pvu9VYfFIcb0qcRVC -D opensim -e "delete from assets where id='00000000-0000-1111-9999-000000000010'"
                mysql -u debian-sys-maint -pvu9VYfFIcb0qcRVC -D opensim -e "delete from assets where id='00000000-0000-1111-9999-000000000011'"
                mysql -u debian-sys-maint -pvu9VYfFIcb0qcRVC -D opensim -e "delete from assets where id='00000000-0000-1111-9999-000000000012'"
        fi
fi
if [ -d ../clockwerk-www/ ]; then
        cd ../clockwerk-www/
        svn update
        dialog --yesno "This option will update the Clockwerk's OpenSim website pages. These pages are the ones that you see when logging-in to the Clockwerk and allow the web-based management of the Clockwerk. If you have made changes to the pages located in /var/www, you should make a backup and say yes. Do you want to upgrade the Clockwerk website pages?" 10 70
        if [ $? == "0" ]; then
                echo "[Clockwerk] Updating website..."
                find /var/www/ -name \*.php -o -name \*.js -o -name \*.css -exec rm -rf '{}' \;
                cp -R * /var/www/
                echo "[Clockwerk] Changing permissions..."
                chown -R www-data:www-data /var/www
                service apache2 restart
        fi
fi
if [ -d ../clockwerk-guacamole ]; then
        cd ../clockwerk-guacamole/
        svn update
        echo "[Clockwerk] Updating guacamole..."
        rm -rf /var/lib/tomcat6/webapps/guacamole/*
        cp -R * /var/lib/tomcat6/webapps/guacamole/
        chown -R tomcat6:tomcat6 /var/lib/tomcat6/webapps/guacamole
        service tomcat6 restart
fi
popd
dialog --yesno "The Clockwerk uses a few shell scripts that manage the virtual machine. These tools can be found in the clockwerk-tools/lib directory and when you run this script they are updated and copied into the filesystem. A safe answer would be yes since they make-up for the core functionality of the Clockwerk. Do you want to deploy the Clockwerk tools?" 10 70
if [ $? == "0" ]; then 
        echo "[Clockwerk] Deploying tools..."
        if [ -x lib/osstrap ]; then
                cp lib/osstrap /etc/init.d/osstrap
        fi
        if [ -x lib/iardumper ]; then
                cp lib/iardumper /etc/cron.daily/iardumper
        fi
fi
if [ -x lib/firewall ]; then 
        dialog --yesno "Apply the latest firewall changes? The firewall rules can be found in the opensim-tools/lib/firewall file and consist of a rudiementary set of protections for the Clockwerk. If you have made changes to ports and are now managing the firewall by yourself, the safe choice is no. Otherwise, please select yes." 10 70
        if [ $? == "0" ]; then
                echo "[Clockwerk] Applying firewall..."
                lib/firewall
        fi
fi
dialog --yesno "It is recommended to restart the OpenSim instance now. You can switch to the first console using CTRL+ALT+F1 and restart OpenSim yourself, or answer yes here. Restart OpenSim?" 10 70
if [ $? == "0" ]; then
        echo "[Clockwerk] Restarting OpenSim."
        kill -s HUP `pidof mono`
fi
echo "[Clockwerk] Done."
dialog --msgbox "Upgrade process is now complete. Have a nice day." 10 70