Here’s the script I have made to update the server edition to the latest edition on my linux server. It needs some work before it’s actually good to distribute as it needs some tweaking to handle any errors that may arise (like download failure), but I thought someone might make use of it.
This script assumes the following:
- Manager is the only process using mono on the server.
- You save the files in /var/www
- Manager starts using the user www-data
- Manager starts at port 8080 (use nginx to proxy pass to it and use https)
Here it is:
#!/bin/bash
# manager-updater.sh ver 0.01
# Author: linuxawy - ahmed@linuxawy.org
# This script is free to use and distribute under GPLv2 or later
# This script has absolutely no warranty, use it at your own risk
#
# Script to update manager to the latest version
# -----------------------------------------------
# This script assumes the following:
# * Manager is the only process using mono on the server.
# * You save the files in /var/www
# * manager starts using the user www-data
# * manager starts at port 8080 (use nginx to proxy pass to it and use https)
###############################################
# This script is not safe yet to run via cron #
###############################################
PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin
File=`curl -s http://www.manager.io/download.json | sed 's/\,/\n/g' | grep tar | awk -F '"' {'print $4'}`
Dir="manager-`echo $File | awk -F/ {'print $5'}`"
PID=`ps aux|grep mono | egrep -v "grep|su|sh" | awk {'print $2'}`
cd /var/www
if [ -d "$Dir" ]; then
echo "you are already on the latest version."
exit 0;
else
echo "New version available ($Dir), attempting to download it ..."
mkdir $Dir
fi
cd $Dir
wget $File 2>&1 >>/dev/null
tar xzf ManagerServer.tar.gz
rm ManagerServer.tar.gz
cd ..
echo "New version downloaded, killing old manager ..."
kill $PID
tail -f /dev/null --pid $PID
rm manager.io
ln -s $Dir manager.io
# note to self: a nice point to do data backup
echo "starting new instance ..."
su www-data -c "cd /var/www/manager.io && /usr/bin/mono ManagerServer.exe -port 8080" >>/dev/null 2>&1 &
if [ $? -eq 0 ]; then
echo "done, enjoy!"
else
echo "something's wrong!"
echo "you are on your own now, call for help."
exit 1
fi