#!/bin/bash USER=$(whoami) console_name="OpenSim_console" screen_session=opensim/${console_name} screen_check="screen -ls opensim/" osversion="current" bindir=/opt/opensim/${osversion}/bin quiet="" if [ "$1" = "-q" ] then quiet="true" shift 1 fi if [ "x$1" = "x" ]; then pathname=$(pwd) tgt=$(basename $pathname) elif [ -d "./$1" ]; then tgt=$1 elif [ -d "./sim$1" ]; then tgt=sim$1 fi if [ "x$tgt" = "x" ]; then echo "usage:" echo " $ $(basename $0) " echo "where is one of: " robust sim[0-9][0-9] exit 1 fi if [ $USER = "opensim" ] then SUDO="" else SUDO="sudo -Hu opensim" fi # Would be nice if this worked. export MONO_PATH=${bindir} # Then we would not have to do this, and subsequently write all over the damn bin directory. cd ${bindir} if ($screen_check | grep -q ${console_name}); then true else $SUDO screen -d -m -S ${console_name} fi if [ "x$tgt" = "xrobust" ]; then exe="Robust" else exe="OpenSim" fi inidir=/opt/opensim/config/${tgt} # Grab the first line of the sim.ini file, it should be the sim name in square brackets. title=$(head -n 1 ${inidir}/Regions/sim.ini ) # Strip off spaces at either end. shopt -s extglob title=${title##*( )} title=${title%%*( )} shopt -u extglob # Strip off the square brackets at either end. title=${title:1:$(( ${#title} - 2 ))} case $(basename $0) in "start-sim") cmd="/usr/bin/mono ${bindir}/${exe}.exe -inidirectory=${inidir} -logconfig=${inidir}/${exe}.exe.config" # Check if it's already running. if [ ! -e /var/run/opensim/${tgt}.pid ] then $SUDO screen -r ${screen_session} -p "-" -X screen -t "[${title}]" ${cmd} fi ;& "sim-console") if [ "x$quiet" = "x" ] then screen -r ${screen_session} -p "[${title}]" -A fi ;; "backup-sim") # Substitute underscores for spaces in the title, then add the full date and time to create the OAR file name. cmd="save oar ${inidir}/../../backups/${title// /_}-$(date '+%F_%T').oar" $SUDO screen -r opensim/OpenSim_console -p "[${title}]" -X stuff "${cmd}$(/bin/echo -ne '\015')" ;; "stop-sim") $SUDO screen -r opensim/OpenSim_console -p "[${title}]" -X stuff "shutdown$(/bin/echo -ne '\015')" ;; esac