opensim-tools – Rev 21

Subversion Repositories:
Rev:
#! /bin/bash
### BEGIN INIT INFO
# Provides:          skeleton
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO

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

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="OpenSim Bootstrap for Spectacled Owl"

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

do_start()
{
    if [ `hostname` == "SpectacledOwl" ]; then
        EXTERNAL_ADDRESS=`ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1 ; exit }'`
        GRID_NAME="SpectacledOwl"
    else
        EXTERNAL_ADDRESS=`hostname`
        GRID_NAME=`echo $EXTERNAL_ADDRESS | awk 'BEGIN { FS = "." } ; { print $1 }'`
    fi

    DAEMON_DIR='/home/opensim/os'
    REGION_DIR='/home/opensim/os/Regions'
    CONFIG_DIR='/home/opensim/os/config-include'

    echo "[OpenSim BootStrap] BootStrapping... Please wait..."

    if [ -z $EXTERNAL_ADDRESS ]; then
        echo "[OpenSim BootStrap ERROR] : Could not find an external address."
        exit
    fi
 
    if [ ! -d $DAEMON_DIR ] || [ ! -d $REGION_DIR ] || [ ! -d $CONFIG_DIR ]; then
       echo "[OpenSIm BootStrap ERROR] : Daemon directory not found."
       exit
    fi
 
    if [ ! -f $CONFIG_DIR/StandaloneCommon.ini ]; then
       echo "[OpenSim BootStrap ERROR] : Configuration files could not be found."
       exit
    fi
 
    # BootStrap OpenSim
    sed -i "s/ExternalHostNameForLSL *=.*/ExternalHostNameForLSL = \"$EXTERNAL_ADDRESS\"/g" \
        $DAEMON_DIR/OpenSim.ini;
 
    # Bootstrap region addresses.
    sed -i "s/ExternalHostName *=.*/ExternalHostName = $EXTERNAL_ADDRESS/g" \
        $REGION_DIR/Regions.ini;
 
    # Bootstrap configuration addresses.
    sed -i "s/HomeURI *=.*/HomeURI = \"http:\/\/$EXTERNAL_ADDRESS:9000\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/Gatekeeper *=.*/Gatekeeper = \"http:\/\/$EXTERNAL_ADDRESS:9000\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/GatekeeperURI *=.*/GatekeeperURI = \"http:\/\/$EXTERNAL_ADDRESS:9000\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/SRV_HomeURI *=.*/SRV_HomeURI = \"http:\/\/$EXTERNAL_ADDRESS:9000\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/SRV_InventoryServerURI *=.*/SRV_InventoryServerURI = \"http:\/\/$EXTERNAL_ADDRESS:9000\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/SRV_AssetServerURI *=.*/SRV_AssetServerURI = \"http:\/\/$EXTERNAL_ADDRESS:9000\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/SRV_ProfileServerURI *=.*/SRV_ProfileServerURI = \"http:\/\/$EXTERNAL_ADDRESS:9000\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/SRV_GroupsServerURI *=.*/SRV_GroupsServerURI = \"http:\/\/$EXTERNAL_ADDRESS:9000\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini
    sed -i "s/FriendsServerURI *=.*/FriendsServerURI = \"http:\/\/$EXTERNAL_ADDRESS:9000\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/IMServerURI *=.*/IMServerURI = \"http:\/\/$EXTERNAL_ADDRESS:9000\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/MapTileURL *=.*/MapTileURL = \"http:\/\/$EXTERNAL_ADDRESS:9000\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/ExternalName *=.*/ExternalName = \"http:\/\/$EXTERNAL_ADDRESS:9000\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/login *=.*/login = \"http:\/\/$EXTERNAL_ADDRESS:9000\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/gridname *=.*/gridname = \"$GRID_NAME\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/gridnick *=.*/gridnick = \"$GRID_NAME\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/welcome *=.*/welcome = \"http:\/\/$EXTERNAL_ADDRESS\/welcome\.php\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/register *=.*/register = \"http:\/\/$EXTERNAL_ADDRESS\/register\.php\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
    sed -i "s/about *=.*/about = \"http:\/\/$EXTERNAL_ADDRESS\/about\.php\"/g" \
        $CONFIG_DIR/StandaloneCommon.ini;
        
    echo "[OpenSim BootStrap] Bootstrap successful."
}

case "$1" in
  start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        do_start
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  stop)
        # Nothing to stop here.
        ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop}" >&2
        exit 3
        ;;
esac

: