aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts/install/create_sim.sh
blob: b940315a5fb16664260c55faaa7bfd831d01bf7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash

source ../common.sh
getPrgDir

NAME=$1
LOCATION=$2
SIZE=$3

cd ${OS_PATH}/config

k=0
for i in $(seq -w 1 99)
do
    if [ -e "sim$i" ]
    then
	k=$i
    fi
done

if [ "x${NAME}" = "x" ]
then
    NAME="No name sim $RANDOM"	# Should be unique per grid.
    echo "WARNING setting the sim name to [${NAME}], this may not be what you want."
fi
# Sanitize the name.  Not removing [ or ], couldn't get that to work, only important for Windows.
sim=$(sanitize ${NAME})

if [ "x${LOCATION}" = "x" ]
then
    LOCATION="$RANDOM,$RANDOM"	# again UNIQUE (i.e. ONLY ONE) per grid in THIS case!
    echo "WARNING setting the Location to ${LOCATION}, this may not be what you want."
fi

if [ "x${SIZE}" = "x" ]
then
    SIZE="256"
fi

# Wow, the hoops we have to jump through to avoid octal.
if [ 9 -gt $k ]; then
    NUM=$(printf '0%1s' $(( 10#$k + 1 )) )
else
    NUM=$(printf '%2s' $(( 10#$k + 1 )) )
fi

PORT=$(( 9005 + (10#$k * 2) ))	# 9002 is used for HTTP/UDP so START with port 9003! CAUTION Diva/D2 starts at port 9000.
UUID=$(uuidgen)

echo "Creating sim${NUM} on port ${PORT} @ ${LOCATION} - ${NAME}."

cp -r sim_skeleton sim${NUM}

cd sim${NUM}
sed -i "s@SIM_NAME@${NAME}@g" ThisSim.ini
sed -i "s@SIM_UUID@${UUID}@g" ThisSim.ini
sed -i "s@SIM_POS@${LOCATION}@g" ThisSim.ini
sed -i "s@SIM_INT_PORT@$(( ${PORT} + 1 ))@g" ThisSim.ini
sed -i "s@SIM_SIZE@${SIZE}@g" ThisSim.ini

ln -s ../../current/scripts/common.sh common.sh
ln -s ../../current/scripts/start-sim start-sim
cp -P start-sim backup-sim
cp -P start-sim stop-sim

sed -i "s@SIM_NUMBER@${NUM}@g" ThisSim.ini
sed -i "s@SIM_PORT@${PORT}@g" ThisSim.ini

sed -i "s@OS_PATH@${OS_PATH}@g" opensim-monit.conf
sed -i "s@SIM_NUMBER@${NUM}@g" opensim-monit.conf

mv ThisSim.ini $(sanitize "${NAME}").ini

sudo chown -R ${OS_USER}:${OS_USER} ..
sudo chmod -R g+w ..