diff options
Diffstat (limited to 'scripts/install/create_sim.sh')
-rwxr-xr-x | scripts/install/create_sim.sh | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/scripts/install/create_sim.sh b/scripts/install/create_sim.sh new file mode 100755 index 0000000..0681067 --- /dev/null +++ b/scripts/install/create_sim.sh | |||
@@ -0,0 +1,96 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | source common.sh | ||
4 | getPrgDir | ||
5 | |||
6 | NAME=$1 | ||
7 | LOCATION=$2 | ||
8 | URL=$3 | ||
9 | IP=$4 | ||
10 | SIZE=$5 | ||
11 | |||
12 | OSPATH="/opt/opensim" | ||
13 | cd $OSPATH/config | ||
14 | |||
15 | k=0 | ||
16 | for i in $(seq -w 1 99) | ||
17 | do | ||
18 | j=$(num2name "$i") | ||
19 | if [ -e "$j" ] | ||
20 | then | ||
21 | k=$i | ||
22 | fi | ||
23 | done | ||
24 | |||
25 | if [ "x$NAME" = "x" ] | ||
26 | then | ||
27 | NAME="No name sim $RANDOM" # Should be unique per grid. | ||
28 | echo "WARNING setting the sim name to [$NAME], this may not be what you want." | ||
29 | fi | ||
30 | # Sanitize the name. Not removing [ or ], couldn't get that to work, only important for Windows. | ||
31 | sim=$(sanitize $NAME) | ||
32 | |||
33 | if [ "x$LOCATION" = "x" ] | ||
34 | then | ||
35 | LOCATION="$RANDOM,$RANDOM" # again UNIQUE (i.e. ONLY ONE) per grid in THIS case! | ||
36 | echo "WARNING setting the Location to $LOCATION, this may not be what you want." | ||
37 | fi | ||
38 | |||
39 | if [ "x$IP" = "x" ] | ||
40 | then | ||
41 | # 0.0.0.0 will work for a single sim per physical machine, otherwise we need the real internal IP. | ||
42 | IP="0.0.0.0" | ||
43 | echo "WARNING setting the InternalAddress to $IP, this may not be what you want." | ||
44 | # echo " 0.0.0.0 will work for a single sim per physical machine, otherwise we need the real internal IP." | ||
45 | # According to the OpenSim docs, 0.0.0.0 means to listen on all NICs the machine has, which should work fine. | ||
46 | fi | ||
47 | |||
48 | if [ "x$URL" = "x" ] | ||
49 | then | ||
50 | # Here we make use of an external IP finding service. Careful, it may move. | ||
51 | # URL=$(wget -q http://automation.whatismyip.com/n09230945.asp -O -) # URL is best (without the HTTP://), but IP (e.g. 88.109.81.55) works too. | ||
52 | URL="SYSTEMIP" | ||
53 | echo "WARNING setting the ExternalHostName to $URL, this may not be what you want." | ||
54 | fi | ||
55 | |||
56 | if [ "x$SIZE" = "x" ] | ||
57 | then | ||
58 | SIZE="256" | ||
59 | fi | ||
60 | |||
61 | # Wow, the hoops we have to jump through to avoid octal. | ||
62 | if [ 9 -gt $k ]; then | ||
63 | NUM=$(printf '0%1s' $(( 10#$k + 1 )) ) | ||
64 | else | ||
65 | NUM=$(printf '%2s' $(( 10#$k + 1 )) ) | ||
66 | fi | ||
67 | |||
68 | PORT=$(( 9005 + (10#$k * 5) )) # 9002 is used for HTTP/UDP so START with port 9003! CAUTION Diva/D2 starts at port 9000. | ||
69 | UUID=$(uuidgen) | ||
70 | |||
71 | echo "Creating sim$NUM on port $PORT @ $LOCATION - $NAME." | ||
72 | |||
73 | cp -r sim_skeleton sim$NUM | ||
74 | |||
75 | cd sim$NUM | ||
76 | mv My_sim.xml ${sim}.xml | ||
77 | sed -i "s@SIM_NAME@$NAME@g" ${sim}.xml | ||
78 | sed -i "s@SIM_UUID@$UUID@g" ${sim}.xml | ||
79 | sed -i "s@SIM_POS@$LOCATION@g" ${sim}.xml | ||
80 | sed -i "s@SIM_IP@$IP@g" ${sim}.xml | ||
81 | sed -i "s@SIM_INT_PORT@$(( $PORT + 1 ))@g" ${sim}.xml | ||
82 | sed -i "s@SIM_URL@$URL@g" ${sim}.xml | ||
83 | sed -i "s@SIM_SIZE@$SIZE@g" ${sim}.xml | ||
84 | |||
85 | ln -s ../../current/scripts/common.sh common.sh | ||
86 | ln -s ../../current/scripts/start-sim start-sim | ||
87 | cp -P start-sim backup-sim | ||
88 | cp -P start-sim stop-sim | ||
89 | |||
90 | sed -i "s@SIM_NUMBER@$NUM@g" ThisSim.ini | ||
91 | sed -i "s@SIM_PORT@$PORT@g" ThisSim.ini | ||
92 | |||
93 | sed -i "s@SIM_NUMBER@$NUM@g" opensim-monit.conf | ||
94 | |||
95 | sudo chown -R opensim:opensim .. | ||
96 | sudo chmod -R g+w .. | ||