#!/bin/bash## for usage, run without arguments## see ../README for setup instructions.## Original code by Dave Coyle (http://coyled.com)# Tweaks by Gwyneth Llewelyn (http://gwynethllewelyn.net/)# Requires bash 4# The original script assumed that you‘d be running one sim per instance,# and launch a different script per sim.# These changes assume you have multiple instances with multiple sims,# and that instance names are launched all from the same place with# an unique identification for each# List of valid instances. Make sure you add all of your instances heredeclare-Ainstancesforindexin<Region1><Region2><Regionx>doinstances[$index]=1doneshow_help(){echo"Input: opensim {start|stop|open|restart|console} "echo-n" for following Regions: "echo${!instances[*]}}# Change <opensim_user> with your valid opensim usercheck_user(){if[$USER!='<opensim_user>'];thenecho"Only <opensim_user> is allowed to use the script"exit1fi}setup(){if[!$1];thenshow_helpexit1elseSIM=$1fi# Change the directories inline with your installation directories# The pid_dir must be set to the value, you used in OpenSim.exe.config# within your regions pathif[[${instances[$SIM]}]];thenMONO="mono"OPENSIM_DIR="/put/your/opensim_dir/here"PID="$OPENSIM_DIR/put/your/pid_dir/here${SIM}/${SIM}.pid"SCREEN="screen"GRID_DIR="./<grid_dir>"# set GRID_DIR to the subdirectory where your individual# instance configuration iselseecho"Region ${SIM}is unknown. Exit."exit1;fi}do_start(){if[!$1];thenshow_helpexit1elseSIM=$1fisetup$SIMcheck_usercd${OPENSIM_DIR}/bin&&$SCREEN-S$SIM-d-m-l$MONOOpenSim.exe-hypergrid=true-inidirectory="$GRID_DIR/$SIM"-logconfig="$GRID_DIR/$SIM/OpenSim.exe.config"}do_kill(){if[!$1];thenshow_helpexit1elseSIM=$1fisetup$SIMcheck_userif[-f$PID];thenkill-9`cat $PID`elseecho"Region ${SIM}PID not found."exit1fi}do_console(){if[!$1];thenshow_helpexit1fisetup$1cd${OPENSIM_DIR}/bin&&$SCREEN-S$SIM-d-m-l$MONOOpenSim.exe-hypergrid=true-inidirectory="$GRID_DIR/$SIM"-logconfig="$GRID_DIR/$SIM/OpenSim.exe.config"}do_open(){if[!$1];thenshow_helpexit1elseSIM=$1fisetup$SIMcheck_userif[-f$PID];thenscreen-r$SIMelseecho"Region ${SIM}PID not found."exit1fi}case"$1"instart)do_start$2;;stop)do_kill$2;;open) do_open$2;;kill)do_kill$2;;restart)do_kill$2do_start$2;;console)do_console$2;;*)show_helpexit
;;
esac