diff options
author | onefang | 2020-09-08 21:31:56 +1000 |
---|---|---|
committer | onefang | 2020-09-08 21:31:56 +1000 |
commit | f92e3e7c49fef4d136ddd7d2e7f817cb0b255f4b (patch) | |
tree | d78dfa6bf1f8aa4ae47423ddcd3c778be8811e57 /scripts | |
parent | Add examples directory. (diff) | |
download | opensim-SC-f92e3e7c49fef4d136ddd7d2e7f817cb0b255f4b.zip opensim-SC-f92e3e7c49fef4d136ddd7d2e7f817cb0b255f4b.tar.gz opensim-SC-f92e3e7c49fef4d136ddd7d2e7f817cb0b255f4b.tar.bz2 opensim-SC-f92e3e7c49fef4d136ddd7d2e7f817cb0b255f4b.tar.xz |
Add the old bash scripts.
Most of these will eventually be rewritten as C + Lua.
Diffstat (limited to '')
-rwxr-xr-x | scripts/backup-grid.sh | 5 | ||||
-rwxr-xr-x | scripts/backup-inventories.sh | 31 | ||||
l--------- | scripts/backup-inventory | 1 | ||||
-rwxr-xr-x | scripts/backup-sims.sh | 19 | ||||
-rwxr-xr-x | scripts/common.sh | 75 | ||||
-rwxr-xr-x | scripts/fix_some_assets.pl | 227 | ||||
-rwxr-xr-x | scripts/gitAR.sh | 108 | ||||
-rwxr-xr-x | scripts/install/create_sim.sh | 75 | ||||
-rwxr-xr-x | scripts/install/go_live.sh | 12 | ||||
-rw-r--r-- | scripts/install/group_migrate.sql | 48 | ||||
-rw-r--r-- | scripts/install/opensim.tmux.conf | 97 | ||||
-rwxr-xr-x | scripts/install/secure.sh | 26 | ||||
-rwxr-xr-x | scripts/show-console | 3 | ||||
-rwxr-xr-x | scripts/start-sim | 218 |
14 files changed, 945 insertions, 0 deletions
diff --git a/scripts/backup-grid.sh b/scripts/backup-grid.sh new file mode 100755 index 0000000..0b762b0 --- /dev/null +++ b/scripts/backup-grid.sh | |||
@@ -0,0 +1,5 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | ./backup-sims.sh | ||
4 | ./backup-inventories.sh | ||
5 | #./backup-assets.sh | ||
diff --git a/scripts/backup-inventories.sh b/scripts/backup-inventories.sh new file mode 100755 index 0000000..e4e7158 --- /dev/null +++ b/scripts/backup-inventories.sh | |||
@@ -0,0 +1,31 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | source common.sh | ||
4 | getPrgDir | ||
5 | |||
6 | # Get the database credentials. | ||
7 | declare -A creds | ||
8 | while read -d ';' p; do | ||
9 | k=$(echo ${p} | cut -d '=' -f 1) | ||
10 | v=$(echo ${p} | cut -d '=' -f 2) | ||
11 | creds[${k}]="${v}" | ||
12 | done < <(grep ConnectionString ${PRGDIR}/../../config/config.ini | cut -d '"' -f 2) | ||
13 | # The above seems the best way to get bash to let the creds assignments survive outside the loop. | ||
14 | |||
15 | # Only backup those that have not logged on since their last backup, but returning prims from sims will bypass this check. | ||
16 | timestamp=$(ls -o --time-style="+%s" ${PRGDIR}/../../backups/.keep | cut -d ' ' -f 5) | ||
17 | touch ${PRGDIR}/../../backups/.keep | ||
18 | # Well it was good in theory, but looks like they broke it in 8.2, no logging in or out updates to GridUser. | ||
19 | |||
20 | # Get the user names, and back 'em up. | ||
21 | mysql --host="${creds[Data Source]}" "${creds[Database]}" --user="${creds[User ID]}" --password="${creds[Password]}" \ | ||
22 | -e "select FirstName,LastName from UserAccounts,GridUser where UserAccounts.PrincipalID=LEFT(GridUser.UserID,36) and GridUser.Login>${timestamp};" -ss | while read user; do | ||
23 | # Replace tab with space | ||
24 | user=${user// / } | ||
25 | # Find out the size of the last backup, base our later sleep on that, but do it now before backup-inventory packs it away. | ||
26 | sizeSleep=`sleepPerSize i "${user}"` | ||
27 | ${PRGDIR}/backup-inventory "${user}" | ||
28 | # Sleep for a while, so that there is plenty of time to do the backup, | ||
29 | # and we are not keeping the computer very busy if there are lots of users. | ||
30 | sleep ${sizeSleep} | ||
31 | done | ||
diff --git a/scripts/backup-inventory b/scripts/backup-inventory new file mode 120000 index 0000000..d326a74 --- /dev/null +++ b/scripts/backup-inventory | |||
@@ -0,0 +1 @@ | |||
start-sim \ No newline at end of file | |||
diff --git a/scripts/backup-sims.sh b/scripts/backup-sims.sh new file mode 100755 index 0000000..06cb780 --- /dev/null +++ b/scripts/backup-sims.sh | |||
@@ -0,0 +1,19 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | source common.sh | ||
4 | getPrgDir | ||
5 | |||
6 | for i in $(seq -w 1 99) | ||
7 | do | ||
8 | if [ -e "${PRGDIR}/../../config/sim${i}" ] | ||
9 | then | ||
10 | pushd ${PRGDIR}/../../config/sim${i} >/dev/null | ||
11 | # Find out the size of the last backup, base our later sleep on that, but do it now before backup-sim packs it away. | ||
12 | sizeSleep=`sleepPerSize o "$(getSimName ${i})"` | ||
13 | ./backup-sim | ||
14 | # Sleep for a while, so that there is plenty of time to do the backup, | ||
15 | # and we are not keeping the computer very busy if there are lots of sims. | ||
16 | sleep ${sizeSleep} | ||
17 | popd > /dev/null | ||
18 | fi | ||
19 | done | ||
diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100755 index 0000000..75aebb0 --- /dev/null +++ b/scripts/common.sh | |||
@@ -0,0 +1,75 @@ | |||
1 | #!/bin/echo Don't run this file, it's for common functions." | ||
2 | |||
3 | OS_PATH="/opt/opensim_SC" | ||
4 | OS_USER="opensimsc" | ||
5 | |||
6 | # Figure out where we are, most of this mess is to troll through soft links. | ||
7 | # PRGDIR=$(getPrgDir) | ||
8 | getPrgDir() | ||
9 | { | ||
10 | PRG="$0" | ||
11 | while [ -h "${PRG}" ] ; do | ||
12 | ls=$(ls -ld "${PRG}") | ||
13 | link=`expr "${ls}" : '.*-> \(.*\)$'` | ||
14 | if expr "${link}" : '.*/.*' > /dev/null; then | ||
15 | PRG="${link}" | ||
16 | else | ||
17 | PRG=$(dirname "${PRG}")/"${link}" | ||
18 | fi | ||
19 | done | ||
20 | PRGDIR=$(dirname "${PRG}") | ||
21 | pushd ${PRGDIR} >/dev/null | ||
22 | export PRGDIR=$(pwd) | ||
23 | popd >/dev/null | ||
24 | } | ||
25 | |||
26 | |||
27 | # Convert number to sim name | ||
28 | # name=$(num2name 1) | ||
29 | num2name() | ||
30 | { | ||
31 | /usr/bin/printf 'sim%02d' "$1" | ||
32 | } | ||
33 | |||
34 | |||
35 | # Sanitize the name. Not removing [ or ], couldn't get that to work, only important for Windows. | ||
36 | # name=$(sanitize "the name") | ||
37 | sanitize() | ||
38 | { | ||
39 | echo "$1" | sed -e 's/[\\/:\*\?"<>\|@#$%&\x01-\x1F\x27\x40\x60\x7F. ]/_/g' -e 's/^$/NONAME/' | ||
40 | } | ||
41 | |||
42 | |||
43 | # Grab the first Section line of the sims .ini file, cut it down to the name. | ||
44 | # name=$(getSimName 1) | ||
45 | getSimName() | ||
46 | { | ||
47 | grep "RegionName" ${PRGDIR}/../../config/sim$1/*.ini | head -n 1 | cut -d '"' -f 2 | ||
48 | } | ||
49 | |||
50 | |||
51 | # Calculate size of the sleep @ one second per megabyte of combined I/OAR file sizes. | ||
52 | # sleepPerSize o "the name" | ||
53 | # sleepPerSize i "the name" | ||
54 | sleepPerSize() | ||
55 | { | ||
56 | type="$1" | ||
57 | name=$(sanitize "$2") | ||
58 | |||
59 | rm -f ${PRGDIR}/../../backups/${name}-sleepPerSize | ||
60 | for file in ${PRGDIR}/../../backups/${name}-*.${type}ar; do | ||
61 | if [ -f ${file} ]; then | ||
62 | # We only loop through them coz bash sucks, we can find the total size now and jump out of the loop. | ||
63 | echo $(du -c -BM ${PRGDIR}/../../backups/${name}-*.${type}ar | tail -n 1 | cut -f 1 | cut -d 'M' -f 1) | ||
64 | touch ${PRGDIR}/../../backups/${name}-sleepPerSize | ||
65 | break | ||
66 | fi | ||
67 | done | ||
68 | |||
69 | # Sleep 200 instead if we can't find any files. | ||
70 | if [ -f ${PRGDIR}/../../backups/${name}-sleepPerSize ]; then | ||
71 | rm -f ${PRGDIR}/../../backups/${name}-sleepPerSize | ||
72 | else | ||
73 | echo 200 | ||
74 | fi | ||
75 | } | ||
diff --git a/scripts/fix_some_assets.pl b/scripts/fix_some_assets.pl new file mode 100755 index 0000000..08fdcb2 --- /dev/null +++ b/scripts/fix_some_assets.pl | |||
@@ -0,0 +1,227 @@ | |||
1 | #!/usr/bin/perl | ||
2 | use strict; | ||
3 | use warnings; | ||
4 | |||
5 | |||
6 | # Took almost two and a half hours on IG. | ||
7 | |||
8 | |||
9 | =pod | ||
10 | # 7/30/2015 3:58PM | ||
11 | Rev B - cleanup | ||
12 | Rev C - added in missing UPDATE | ||
13 | |||
14 | quthor Jeff Kelley <opensim@pescadoo.net> | ||
15 | mods by Fred Beckhusen <fred@mitsi.com> aka Ferd Frederix | ||
16 | |||
17 | This version has minimum Perl module dependencies. | ||
18 | |||
19 | This script connects to an Opensim asset database and scans and fixed bug Mantis-7514 | ||
20 | The files that are fixed have multiple xmlns : in it, such as xmlns:xmlns: | ||
21 | |||
22 | http://opensimulator.org/mantis/view.php?id=7514 | ||
23 | |||
24 | ############################################################################ | ||
25 | # DO A BACKUP BEFORE YOU ATTEMPT THIS. DO A DRY RUN WITH UPDATE SET TO ZERO # | ||
26 | ############################################################################# | ||
27 | |||
28 | Set variable UPDATE to a 1 to write updates to the db. A 0 will show you what it would change and also save the bad | ||
29 | data to disk in a folder name 'corrupt' for you to examine. | ||
30 | |||
31 | For safety, we will never update a record unless the UPDATE flag is on. | ||
32 | |||
33 | ############################################################# | ||
34 | # DO NOT RUN THIS UNTIL YOU SET THE CONSTANTS BELOW # | ||
35 | ############################################################# | ||
36 | |||
37 | =cut | ||
38 | |||
39 | # these are typically found in StandaloneCommon.ini or GridCommon.ini | ||
40 | |||
41 | my $username = '*****'; | ||
42 | my $password = '*****'; | ||
43 | my $hostname = '*****'; # probably you use localhost for standalone, but it could be an IP address or a DNS name for a asset server. | ||
44 | my $robustDB = '*****'; # your MySQl DB name | ||
45 | |||
46 | # for safety, we will never update a record unless the UPDATE flag is on. | ||
47 | use constant LISTALL => 0; # show all assets as they are scanned | ||
48 | use constant UPDATE => 0; # set to 1 if you want to actually update the database | ||
49 | use constant MAX => 16000000; # max size of blob from your MySQL ini - see My.ini : max_allowed_packet = 16M, You may need to set this to 64 MB if you have large assets. My largest was over 10 MB..jeepers! | ||
50 | use constant GETMAX => 1; # set to 1 to query MAX object size (see above line) automatically - much slower to start, but less memory is used overall both at the server and at the client | ||
51 | use constant MANTIS7514 => '/tmp/fix_some_assets.ini'; # path to a temp file to keep track of each run. Delete the file to start at the beginning | ||
52 | |||
53 | # all these modules should already be in core. If not, run "cpan name_of_module', or just go get Strawberry Perl. | ||
54 | use v5.10; # so we can say, and not need to add a newline | ||
55 | use DBI; # database I/O | ||
56 | $|=1; #no buffering STDIO | ||
57 | |||
58 | my $counter = 0; # count of xmlmns corruption | ||
59 | my $havedone = 0; | ||
60 | my $OddCounter = 0; # other corrupt data | ||
61 | |||
62 | mkdir 'corrupt'; # save the data in this folder | ||
63 | |||
64 | my $dbh = DBI->connect( | ||
65 | "dbi:mysql:dbname=$robustDB;host=$hostname", | ||
66 | $username, $password,{RaiseError => 1 , LongReadLen => MAX, LongTruncOk => 0,AutoCommit => 1}, | ||
67 | ) or die $DBI::errstr; | ||
68 | |||
69 | # Get the largest blob in table data in the DB and set our size of memory buffers to that. | ||
70 | if (GETMAX) { | ||
71 | my $max_len = GetLenData (); | ||
72 | say "Largest object is $max_len bytes"; | ||
73 | $dbh->{LongReadLen} = $max_len; | ||
74 | } | ||
75 | |||
76 | my $todo; | ||
77 | my $objectsList = GetAssetList(); # get a hash of all objects | ||
78 | $todo = scalar @$objectsList if ref $objectsList; # count them | ||
79 | say "Found $todo objects"; | ||
80 | |||
81 | for (@$objectsList) { | ||
82 | my $obj_uuid = $_->{id}; | ||
83 | my $obj_name = $_->{name}; | ||
84 | my $obj_time = $_->{create_time}; | ||
85 | |||
86 | $havedone++; # keep track of how many done | ||
87 | |||
88 | my $obj_data = GetAssetData ($obj_uuid); # grab the blob | ||
89 | |||
90 | ValidateXML ($obj_data,$obj_uuid, $obj_name); # repair it and check it | ||
91 | |||
92 | #save where we are at so we can be stopped and run again some other rainy day | ||
93 | open(my $in_file, ">",MANTIS7514) || die 'Cannot save the last file date'; | ||
94 | print $in_file $obj_time; | ||
95 | close $in_file; | ||
96 | } | ||
97 | |||
98 | say "Found $counter corrupt xmlns objects"; | ||
99 | say "Found $OddCounter other possibly corrupted objects"; | ||
100 | say "Done!"; | ||
101 | |||
102 | |||
103 | sub GetAssetList { | ||
104 | |||
105 | my $answref; | ||
106 | |||
107 | my $time = 0; | ||
108 | # read the last run date from a file | ||
109 | if (open(my $in_file, "<",MANTIS7514)) | ||
110 | { | ||
111 | $time = <$in_file> || 0; | ||
112 | close $in_file; | ||
113 | } | ||
114 | my $query = "SELECT id,name, create_time FROM $robustDB.assets WHERE assetType=6 and create_time > $time order by create_time asc;"; | ||
115 | $answref = $dbh->selectall_arrayref ($query, { Slice => {} }); | ||
116 | |||
117 | return $answref; | ||
118 | } | ||
119 | |||
120 | sub GetAssetData { | ||
121 | my $uuid = shift; | ||
122 | my $query = "SELECT data FROM $robustDB.assets WHERE id='$uuid';"; | ||
123 | my $answr = $dbh->selectall_arrayref ($query, { Slice => {} }); | ||
124 | return @$answr[0]->{data}; | ||
125 | } | ||
126 | |||
127 | sub UpdateData { | ||
128 | return unless UPDATE; | ||
129 | my $uuid = shift; | ||
130 | my $data = shift; | ||
131 | |||
132 | my $sth = $dbh->prepare("UPDATE $robustDB.assets set data = ? WHERE id = ?;"); | ||
133 | $sth->execute($data, $uuid) or die $DBI::errstr;; | ||
134 | } | ||
135 | sub GetLenData { | ||
136 | my $len = $dbh->selectrow_array("SELECT MAX(OCTET_LENGTH(data)) FROM $robustDB.assets WHERE assetType=6;"); | ||
137 | } | ||
138 | |||
139 | |||
140 | sub ValidateXML { | ||
141 | my $data = shift; | ||
142 | my $obj_uuid = shift; | ||
143 | my $obj_name = shift || ''; | ||
144 | |||
145 | #### FORCES AN ERROR FOR DEBUG $data =~ s/xmlns:/xmlns:xmlns:/g; # the fix is in !!!!!!!!! | ||
146 | |||
147 | # Test for repeated xmlns, clever RegEx by Jeff Kelley. | ||
148 | my $corrupt = ($data =~ m/((xmlns:){2,}+)/g); | ||
149 | my $err = $1 || ''; | ||
150 | |||
151 | # show them where we are at, if enabled or corrupted. | ||
152 | printf "%d/%d | %s | %s | %s\n", $havedone, $todo, $corrupt ? 'Bad ' : 'Ok ', $obj_uuid, $obj_name if ($corrupt || LISTALL); | ||
153 | |||
154 | if ($corrupt) | ||
155 | { | ||
156 | $counter++; | ||
157 | |||
158 | print ("Found $err\n", 'red') ; | ||
159 | my $original = $data; # so we can save it to disk later, if need be. | ||
160 | |||
161 | $data =~ s/(xmlns:){2,}+/xmlns:/g; # the fix is in | ||
162 | |||
163 | UpdateData($obj_uuid,$data) if UPDATE; # we update if we are enabled and had an error Rev C | ||
164 | |||
165 | save({ | ||
166 | name => "$obj_uuid-$obj_name-before.txt", | ||
167 | uuid => $obj_uuid, | ||
168 | corrupt => $err, | ||
169 | data => $original, | ||
170 | type => 0, | ||
171 | }); | ||
172 | |||
173 | save({ | ||
174 | name => "$obj_uuid-$obj_name-after.txt", | ||
175 | uuid => $obj_uuid, | ||
176 | corrupt => $err, | ||
177 | data => $data, | ||
178 | type => 0, | ||
179 | }); | ||
180 | } | ||
181 | |||
182 | return $corrupt; # in case the caller wants to know | ||
183 | } | ||
184 | |||
185 | sub save { | ||
186 | my $c = shift; | ||
187 | |||
188 | $c->{name} =~ s/[^A-Za-z0-9\-\.]//g; # make a safe file name | ||
189 | |||
190 | # may have to force an UTF-16LE or UTF-BE encoding here but my tests show the data is always UTF-8 or ASCII. | ||
191 | |||
192 | if (open(my $out_file, "> :encoding(UTF-8)",'corrupt/' . $c->{name})) { | ||
193 | binmode ($out_file,":encoding(UTF-8)"); | ||
194 | |||
195 | $c->{data} =~ s/encoding="utf-8"/encoding="utf-16"/; # not right, but that's they way they coded the XML in the DB. | ||
196 | |||
197 | print $out_file $c->{data}; | ||
198 | print $out_file "\0"; # zero termination is in the OAR, lets put it back | ||
199 | } else { | ||
200 | say "Failed to open file"; | ||
201 | die; | ||
202 | } | ||
203 | |||
204 | } | ||
205 | |||
206 | __END__ | ||
207 | |||
208 | BSD License: | ||
209 | Copyright (c) 2015 | ||
210 | Redistribution and use in source and binary forms, with or without | ||
211 | modification, are permitted provided that the following conditions are met: | ||
212 | * Redistributions of source code must retain the above copyright notice, this | ||
213 | list of conditions and the following disclaimer. | ||
214 | * Redistributions in binary form must reproduce the above copyright notice, | ||
215 | this list of conditions and the following disclaimer in the documentation | ||
216 | and/or other materials provided with the distribution. | ||
217 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
218 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
219 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
220 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
221 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
222 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
223 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
224 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
225 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
226 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
227 | Space here is intentionally left blank for note taking | ||
diff --git a/scripts/gitAR.sh b/scripts/gitAR.sh new file mode 100755 index 0000000..d988077 --- /dev/null +++ b/scripts/gitAR.sh | |||
@@ -0,0 +1,108 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | # Work around OpenSims slow database corruption bug by using git to store all old backups. | ||
4 | # Try to squeeze every last byte out of the tarballs. Seems to cut the total storage size down to one third the size of just the raw I/OAR files. | ||
5 | # Saves even more if there's been no changes. | ||
6 | # On the other hand, these backup files will grow indefinately, the more changes, the faster it grows. I can live with that for more reliable backups that go back further. | ||
7 | # Tries to avoid loosing data if things go wrong. I think the main remaining problem would be running out of space, in which case you have bigger problems to deal with. | ||
8 | |||
9 | # Strategy - unpack the last one, unpack and commit any old I/OARs, pack up the result, delete it's working directory, THEN run the save i/oar. | ||
10 | # Avoids having to sync with OpenSim finishing the current I/OAR, and as a bonus, an easy to deliver latest I/OAR for people that want it. | ||
11 | |||
12 | # Not really meant to be called by users, so don't bother validating the input and such. | ||
13 | |||
14 | source common.sh | ||
15 | getPrgDir | ||
16 | |||
17 | type=$1 | ||
18 | title=$2 | ||
19 | date=$(date '+%F_%T') | ||
20 | |||
21 | # Convert the type to uppercase. | ||
22 | gar="_git$(echo -n ${type} | tr '[:lower:]' '[:upper:]')AR" | ||
23 | name=$(sanitize "${title}") | ||
24 | |||
25 | if [ -d ${PRGDIR}/../../backups/temp_backup${type}_${name} ]; then | ||
26 | echo "WARNING - Mess left over from last backup, not gonna run!" | ||
27 | mv ${PRGDIR}/../../backups/temp_backup${type}_${name}/*.oar ${PRGDIR}/../backups | ||
28 | exit 1 | ||
29 | fi | ||
30 | |||
31 | mkdir -p ${PRGDIR}/../../backups/temp_backup${type}_${name} | ||
32 | pushd ${PRGDIR}/../../backups/temp_backup${type}_${name} >/dev/null | ||
33 | if [ -f ../${name}${gar}.tar.xz ]; then | ||
34 | ionice -c3 nice -n 19 tar -xf ../${name}${gar}.tar.xz | ||
35 | else | ||
36 | mkdir -p ${name}${gar} | ||
37 | git init ${name}${gar} >log | ||
38 | fi | ||
39 | |||
40 | pushd ${name}${gar} >/dev/null | ||
41 | |||
42 | # Make sure stuff that's already compressed doesn't get compressed by git. | ||
43 | # Also tries to protect binaries from mangling. | ||
44 | cat >.gitattributes <<- zzzzEOFzzzz | ||
45 | *.bvh -delta -diff -text | ||
46 | *.jp2 -delta -diff -text | ||
47 | *.jpg -delta -diff -text | ||
48 | *.llmesh -delta -diff -text | ||
49 | *.ogg -delta -diff -text | ||
50 | *.png -delta -diff -text | ||
51 | *.r32 -delta -diff -text | ||
52 | *.tga -delta -diff -text | ||
53 | zzzzEOFzzzz | ||
54 | # Coz git insists. | ||
55 | git config user.email "opensim@$(hostname -A | cut -d ' ' -f 1)" | ||
56 | git config user.name "opensim" | ||
57 | |||
58 | # Git is such a pedantic bitch, let's just fucking ignore any errors it gives due to lack of anything to do. | ||
59 | # Even worse the OpenSim devs breaking logout tracking gives git plenty of nothing to do. lol | ||
60 | |||
61 | # Looping through them in case there's a bunch of I/OARs from previous versions of this script. | ||
62 | # Ignore files of zero size that OpenSim might create. | ||
63 | find ../.. -maxdepth 1 -type f -name "${name}-*.${type}ar" -size '+0c' | sort | while read file; do | ||
64 | # Deal with deletions in the inventory / sim, easy method, which becomes a nop for files that stay in the git add below. | ||
65 | git rm -fr * &>>../log #|| echo "ERROR - Could not clean git for ${file} !" >>../errors | ||
66 | if [ ! -f ../errors ]; then | ||
67 | ionice -c3 nice -n 19 tar -xzf "${file}" || echo "ERROR - Could not unpack ${file} !" >>../errors | ||
68 | fi | ||
69 | if [ ! -f ../errors ]; then | ||
70 | git add * &>>../log | ||
71 | git add */\* &>>../log #|| echo "ERROR - Could not add ${file} to git!" >>../errors | ||
72 | git add .gitattributes &>>../log | ||
73 | # Magic needed to figure out if there's anything to commit. | ||
74 | # After all the pain to get this to work, there's an ever changing timestamp in archive.xml that screws it up. | ||
75 | # Like this system didn't have enough timestamps in it already. lol | ||
76 | # TODO - I could sed out that timestamp, and put it back again based on the OAR file name when extracting. | ||
77 | # IARs don't seem to have the timestamp. | ||
78 | if t=$(git status --porcelain) && [ -z "${t}" ]; then | ||
79 | true | ||
80 | else | ||
81 | # Note this commit message has to be just the file name, as the ungitAR script uses it. | ||
82 | git commit -qm "$(basename ${file})" &>>../log || echo "ERROR - Could not commit ${file} !" >>../errors | ||
83 | fi | ||
84 | if [ ! -f ../errors ]; then | ||
85 | mv ${file} .. | ||
86 | fi | ||
87 | fi | ||
88 | if [ -f ../errors ]; then | ||
89 | exit 1 # Seems to only exit from this loop, not the script. Makes me want to rewrite this in a real language. lol | ||
90 | fi | ||
91 | done | ||
92 | |||
93 | #git gc --aggressive --prune=now # Takes a long time, doesn't gain much. Even worse, it increases the size of the resulting tarball. lol | ||
94 | |||
95 | popd >/dev/null | ||
96 | |||
97 | if [ ! -f errors ]; then | ||
98 | XZ_OPT="-9e" ionice -c3 nice -n 19 tar -c --xz ${name}${gar} -f ../${name}${gar}.tar.xz || echo "ERROR - Could not pack gitAR!" >>errors | ||
99 | fi | ||
100 | |||
101 | popd >/dev/null | ||
102 | |||
103 | if [ -f ${PRGDIR}/../../backups/temp_backup${type}_${name}/errors ]; then | ||
104 | echo "NOT cleaning up coz - " | ||
105 | cat ${PRGDIR}/../../backups/temp_backup${type}_${name}/errors | ||
106 | else | ||
107 | rm -fr ${PRGDIR}/../../backups/temp_backup${type}_${name} | ||
108 | fi | ||
diff --git a/scripts/install/create_sim.sh b/scripts/install/create_sim.sh new file mode 100755 index 0000000..b940315 --- /dev/null +++ b/scripts/install/create_sim.sh | |||
@@ -0,0 +1,75 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | source ../common.sh | ||
4 | getPrgDir | ||
5 | |||
6 | NAME=$1 | ||
7 | LOCATION=$2 | ||
8 | SIZE=$3 | ||
9 | |||
10 | cd ${OS_PATH}/config | ||
11 | |||
12 | k=0 | ||
13 | for i in $(seq -w 1 99) | ||
14 | do | ||
15 | if [ -e "sim$i" ] | ||
16 | then | ||
17 | k=$i | ||
18 | fi | ||
19 | done | ||
20 | |||
21 | if [ "x${NAME}" = "x" ] | ||
22 | then | ||
23 | NAME="No name sim $RANDOM" # Should be unique per grid. | ||
24 | echo "WARNING setting the sim name to [${NAME}], this may not be what you want." | ||
25 | fi | ||
26 | # Sanitize the name. Not removing [ or ], couldn't get that to work, only important for Windows. | ||
27 | sim=$(sanitize ${NAME}) | ||
28 | |||
29 | if [ "x${LOCATION}" = "x" ] | ||
30 | then | ||
31 | LOCATION="$RANDOM,$RANDOM" # again UNIQUE (i.e. ONLY ONE) per grid in THIS case! | ||
32 | echo "WARNING setting the Location to ${LOCATION}, this may not be what you want." | ||
33 | fi | ||
34 | |||
35 | if [ "x${SIZE}" = "x" ] | ||
36 | then | ||
37 | SIZE="256" | ||
38 | fi | ||
39 | |||
40 | # Wow, the hoops we have to jump through to avoid octal. | ||
41 | if [ 9 -gt $k ]; then | ||
42 | NUM=$(printf '0%1s' $(( 10#$k + 1 )) ) | ||
43 | else | ||
44 | NUM=$(printf '%2s' $(( 10#$k + 1 )) ) | ||
45 | fi | ||
46 | |||
47 | PORT=$(( 9005 + (10#$k * 2) )) # 9002 is used for HTTP/UDP so START with port 9003! CAUTION Diva/D2 starts at port 9000. | ||
48 | UUID=$(uuidgen) | ||
49 | |||
50 | echo "Creating sim${NUM} on port ${PORT} @ ${LOCATION} - ${NAME}." | ||
51 | |||
52 | cp -r sim_skeleton sim${NUM} | ||
53 | |||
54 | cd sim${NUM} | ||
55 | sed -i "s@SIM_NAME@${NAME}@g" ThisSim.ini | ||
56 | sed -i "s@SIM_UUID@${UUID}@g" ThisSim.ini | ||
57 | sed -i "s@SIM_POS@${LOCATION}@g" ThisSim.ini | ||
58 | sed -i "s@SIM_INT_PORT@$(( ${PORT} + 1 ))@g" ThisSim.ini | ||
59 | sed -i "s@SIM_SIZE@${SIZE}@g" ThisSim.ini | ||
60 | |||
61 | ln -s ../../current/scripts/common.sh common.sh | ||
62 | ln -s ../../current/scripts/start-sim start-sim | ||
63 | cp -P start-sim backup-sim | ||
64 | cp -P start-sim stop-sim | ||
65 | |||
66 | sed -i "s@SIM_NUMBER@${NUM}@g" ThisSim.ini | ||
67 | sed -i "s@SIM_PORT@${PORT}@g" ThisSim.ini | ||
68 | |||
69 | sed -i "s@OS_PATH@${OS_PATH}@g" opensim-monit.conf | ||
70 | sed -i "s@SIM_NUMBER@${NUM}@g" opensim-monit.conf | ||
71 | |||
72 | mv ThisSim.ini $(sanitize "${NAME}").ini | ||
73 | |||
74 | sudo chown -R ${OS_USER}:${OS_USER} .. | ||
75 | sudo chmod -R g+w .. | ||
diff --git a/scripts/install/go_live.sh b/scripts/install/go_live.sh new file mode 100755 index 0000000..c5ce90e --- /dev/null +++ b/scripts/install/go_live.sh | |||
@@ -0,0 +1,12 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | source common.sh | ||
4 | |||
5 | for i in $(seq 99) | ||
6 | do | ||
7 | j=$(printf "sim%02d" $i) | ||
8 | if [ -e "$OSPATH/config/$j" ] | ||
9 | then | ||
10 | sudo ln -s $OSPATH/config/$j/opensim-monit.conf /etc/monit/conf.d/$j.conf | ||
11 | fi | ||
12 | done | ||
diff --git a/scripts/install/group_migrate.sql b/scripts/install/group_migrate.sql new file mode 100644 index 0000000..6c15011 --- /dev/null +++ b/scripts/install/group_migrate.sql | |||
@@ -0,0 +1,48 @@ | |||
1 | INSERT INTO `griddy`.`os_groups_groups` | ||
2 | (GroupID, Name, Charter, InsigniaID, FounderID, MembershipFee, OpenEnrollment, ShowInList, | ||
3 | AllowPublish, MaturePublish, OwnerRoleID) | ||
4 | SELECT GroupID, Name, Charter, InsigniaID, FounderID, MemberShipFee, OpenEnrollment, ShowInList, AllowPublish, | ||
5 | MaturePublish, OwnerRoleID | ||
6 | FROM `griddy`.osgroup; | ||
7 | |||
8 | /*fill os_groups_invites in ROBUST database with values from osgroupinvite | ||
9 | or FlotSam osgroupinvite*/ | ||
10 | INSERT INTO `griddy`.`os_groups_invites` | ||
11 | (InviteID, GroupID, RoleID, PrincipalID, TMStamp) | ||
12 | SELECT InviteID, GroupID, RoleID, AgentID, TMStamp | ||
13 | FROM `griddy`.osgroupinvite; | ||
14 | |||
15 | /*fill os_groups_membership in ROBUST database with values from osgroupmembership | ||
16 | or FlotSam osgroupmembership*/ | ||
17 | INSERT INTO `griddy`.`os_groups_membership` | ||
18 | (GroupID, PrincipalID, SelectedRoleID, Contribution, ListInProfile, AcceptNotices) | ||
19 | SELECT GroupID, AgentID, SelectedRoleID, Contribution, ListInProfile, AcceptNotices | ||
20 | FROM `griddy`.osgroupmembership; | ||
21 | |||
22 | /*fill os_groups_notices in ROBUST database with values from osgroupnotice | ||
23 | or FlotSam osgroupnotice*/ | ||
24 | INSERT INTO `griddy`.`os_groups_notices` | ||
25 | (GroupID, NoticeID, TMStamp, FromName, Subject, Message) | ||
26 | SELECT GroupID, NoticeID, Timestamp, FromName, Subject, Message | ||
27 | FROM `griddy`.osgroupnotice; | ||
28 | |||
29 | /*fill os_groups_principals in ROBUST database with values from osagent | ||
30 | or FlotSam osagent*/ | ||
31 | INSERT INTO `griddy`.`os_groups_principals` | ||
32 | (PrincipalID, ActiveGroupID) | ||
33 | SELECT AgentID, ActiveGroupID | ||
34 | FROM `griddy`.osagent; | ||
35 | |||
36 | /*fill os_groups_rolemembership in ROBUST database with values from osrolemembership | ||
37 | or FlotSam osgrouprolemembership*/ | ||
38 | INSERT INTO `griddy`.os_groups_rolemembership | ||
39 | (GroupID, RoleID, PrincipalID) | ||
40 | SELECT GroupID, RoleID, AgentID | ||
41 | FROM `griddy`.osgrouprolemembership; | ||
42 | |||
43 | /*fill os_groups_roles in ROBUST database with values from osroles | ||
44 | or FlotSam osrole*/ | ||
45 | INSERT INTO `griddy`.os_groups_roles | ||
46 | (GroupID, RoleID, Name, Description, Title, Powers) | ||
47 | SELECT GroupID, RoleID, Name, Description, Title, Powers | ||
48 | FROM `griddy`.osrole; | ||
diff --git a/scripts/install/opensim.tmux.conf b/scripts/install/opensim.tmux.conf new file mode 100644 index 0000000..84e0c21 --- /dev/null +++ b/scripts/install/opensim.tmux.conf | |||
@@ -0,0 +1,97 @@ | |||
1 | # Tmux has a habit of changing what these options are for each version, so this is a bit of a mess. | ||
2 | |||
3 | # Screen compatibility, change the command key. And rebind the prefix sending command. | ||
4 | set-option -g prefix C-a | ||
5 | unbind-key C-b | ||
6 | bind-key C-a send-prefix | ||
7 | |||
8 | # r reloads the configuration, handy | ||
9 | bind r source-file ~/.tmux.conf | ||
10 | |||
11 | bind R clear-history | ||
12 | |||
13 | # More sane pane gain. B-) | ||
14 | unbind % # Remove default binding since we’re replacing them. | ||
15 | unbind '"' | ||
16 | bind | split-window -h | ||
17 | bind - split-window -v | ||
18 | |||
19 | # set-options -g global, -s server, -w window, otherwise a session option. | ||
20 | # -a appends a string to the existing option. | ||
21 | # -u unsets an option. | ||
22 | # -o prevents setting an aption if it is already set. | ||
23 | # -q shut up info messages. | ||
24 | |||
25 | # SESSION OPTIONS | ||
26 | |||
27 | set-option -g bell-action any | ||
28 | set-option -g bell-on-alert on | ||
29 | |||
30 | # Not actually documented what the limit is, but there is one. | ||
31 | set-option -g history-limit 100000 | ||
32 | |||
33 | # All this mouse stuff is unreliable in UTF8 mode. At least on roxterm. | ||
34 | # Also keep in mind the terminal specs mouse report limit of 256 characters, being less than my typical terminal width. | ||
35 | # Hmm, still wont pass mouse through like the docs say they will. | ||
36 | # Ah, mc needs "mc -x". Though once again, watch that right edge on huge terminals. | ||
37 | # These three wont work under Ubuntu 16.04. | ||
38 | ##set-option -g mouse-resize-pane on | ||
39 | ##set-option -g mouse-select-pane on | ||
40 | ##set-option -g mouse-select-window on | ||
41 | # This wont work under Ubuntu 16.04. | ||
42 | ##set-option -g mode-mouse on # on - mouse does copy mode stuff; copy-mode - mouse can't go into copy mode, but does stuff once in there; off - mouse is unmolested. | ||
43 | # Instead do this (also defaults to turning on the above three mouse things) - | ||
44 | set-option -g mouse on | ||
45 | # Or this. sigh | ||
46 | #set-option -g mouse | ||
47 | ##set-option -g mouse-utf8 off # Defaults to on. | ||
48 | |||
49 | set-option -g set-remain-on-exit on | ||
50 | |||
51 | # How to set the title of the terminal window. | ||
52 | set-option -g set-titles on | ||
53 | set-option -g set-titles-string '#W' # Default is "#S:#I:#W - "#T"" | ||
54 | |||
55 | set-option -g status-interval 1 # Redraw status line every second, for the clock. | ||
56 | set-option -g status-justify centre # Window list in the middle. | ||
57 | ##set-option -g status-utf8 on | ||
58 | |||
59 | # Character pair Replaced with | ||
60 | #(shell-command) First line of the command's output | ||
61 | #[attributes] Colour or attribute change | ||
62 | #H Hostname of local host (not FDQN) | ||
63 | #h Hostname of local host without the domain name | ||
64 | #F Current window flag | ||
65 | #I Current window index | ||
66 | #D Current pane unique identifier | ||
67 | #P Current pane index | ||
68 | #S Session name | ||
69 | #T Current pane title | ||
70 | #W Current window name | ||
71 | ## A literal ‘#’ | ||
72 | |||
73 | # Yes, my terminal really is bigger than 160 characters. | ||
74 | set-option -g status-left-length 42 | ||
75 | #set-option -g status-left '[#H #S #F]' | ||
76 | set-option -g status-left '#H [#S:#I.#P]#F' | ||
77 | set-option -g status-right-length 64 | ||
78 | set-option -g status-right "%F #(uptime | cut -d ' ' -f 2-2,10-)" # %F is ISO date, uptime starts with the current time, and ends with the load average. B-) | ||
79 | |||
80 | # Set window notifications | ||
81 | set-option -g visual-activity on # Show status message for activity in monitor-activity windows. | ||
82 | #set-option -g visual-content on # Show status message for content in monitor-content windows. Based on a fnmatch(3) string. | ||
83 | set-option -g visual-silence on # Show status message for silence in monitor-silence windows. Based on a set interval. | ||
84 | |||
85 | set-option -gw alternate-screen off # Don't save the original screen before starting tmux, may also allow use of the terminals original scrollback buffer. | ||
86 | set-option -gw clock-mode-style 24 # We are using the uptime clock anyway, so this is pointless. | ||
87 | |||
88 | # Highlight active window | ||
89 | set-option -gw window-status-current-bg red | ||
90 | set-option -gw window-status-current-format '[#I:#W]' | ||
91 | set-option -gw window-status-format '[#I:#W]#F' | ||
92 | |||
93 | # Set window notifications | ||
94 | set-option -gw monitor-activity on # Bell on activity. | ||
95 | |||
96 | # We want 256 colours in our terminal. | ||
97 | set-option -g default-terminal "screen-256color" | ||
diff --git a/scripts/install/secure.sh b/scripts/install/secure.sh new file mode 100755 index 0000000..95aae84 --- /dev/null +++ b/scripts/install/secure.sh | |||
@@ -0,0 +1,26 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | source ../common.sh | ||
4 | |||
5 | echo "Securing OpenSim." | ||
6 | sudo chmod 600 ${OS_PATH}/config/*.ini | ||
7 | sudo chmod 600 ${OS_PATH}/config/ROBUST/*.ini | ||
8 | sudo chown -R ${OS_USER}:${OS_USER} ${OS_PATH} | ||
9 | sudo chmod -R 775 ${OS_PATH} | ||
10 | sudo chmod -R a-x ${OS_PATH} | ||
11 | sudo chmod -R a+X ${OS_PATH} | ||
12 | sudo chmod -R g+w ${OS_PATH} | ||
13 | sudo chmod -R a+x ${OS_PATH}/current/*.sh | ||
14 | sudo chmod -R a+x ${OS_PATH}/current/scripts/*.sh | ||
15 | sudo chmod -R a+x ${OS_PATH}/current/scripts/install/*.sh | ||
16 | sudo chmod a+x ${OS_PATH}/current/scripts/show-console | ||
17 | sudo chmod a+x ${OS_PATH}/current/scripts/start-sim | ||
18 | |||
19 | sudo chmod ug+rwx ${OS_PATH}/config | ||
20 | sudo chmod g+s ${OS_PATH}/config | ||
21 | sudo chmod 600 ${OS_PATH}/config/*.ini | ||
22 | sudo chmod 600 ${OS_PATH}/config/ROBUST/*.ini | ||
23 | |||
24 | chmod ug+rwx ${OS_PATH}/caches | ||
25 | chmod o-rwx ${OS_PATH}/caches | ||
26 | chmod g+s ${OS_PATH}/caches | ||
diff --git a/scripts/show-console b/scripts/show-console new file mode 100755 index 0000000..d8b1775 --- /dev/null +++ b/scripts/show-console | |||
@@ -0,0 +1,3 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | tmux -S ../../var/run/opensim-tmux.socket select-window -t "SledjChisl" \; attach-session -t "SledjChisl" | ||
diff --git a/scripts/start-sim b/scripts/start-sim new file mode 100755 index 0000000..0a58294 --- /dev/null +++ b/scripts/start-sim | |||
@@ -0,0 +1,218 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | source common.sh | ||
4 | getPrgDir | ||
5 | |||
6 | USER=$(whoami) | ||
7 | console_name="SledjChisl" | ||
8 | tmux_command="tmux -S ${PRGDIR}/../../var/run/opensim-tmux.socket" | ||
9 | tmux_session=${console_name} | ||
10 | tmux_window="${tmux_command} select-window -t ${tmux_session}" | ||
11 | tmux_send="${tmux_command} send-keys -t ${tmux_session}" | ||
12 | bindir="${PRGDIR}/../bin" | ||
13 | date=$(date '+%F_%T') | ||
14 | all="" | ||
15 | delay=45 | ||
16 | quiet="" | ||
17 | waiting="" | ||
18 | inventory="" | ||
19 | |||
20 | function wait_for_text() | ||
21 | { | ||
22 | while :; do | ||
23 | sleep 10 | ||
24 | ${tmux_command} capture-pane -t ${tmux_session}:"${1}" -p | grep -E "${2}" 2>&1 > /dev/null && return | ||
25 | done | ||
26 | } | ||
27 | |||
28 | |||
29 | if [ $USER = "${OS_USER}" ] | ||
30 | then | ||
31 | SUDO="" | ||
32 | else | ||
33 | SUDO="sudo -Hu ${OS_USER}" | ||
34 | fi | ||
35 | |||
36 | if [ "$1" = "-a" ] | ||
37 | then | ||
38 | all="-a" | ||
39 | shift 1 | ||
40 | fi | ||
41 | |||
42 | if [ "$1" = "-d" ] | ||
43 | then | ||
44 | delay=$2 | ||
45 | shift 2 | ||
46 | fi | ||
47 | |||
48 | if [ "$1" = "-q" ] | ||
49 | then | ||
50 | quiet="-q" | ||
51 | shift 1 | ||
52 | fi | ||
53 | |||
54 | if [ "$1" = "-w" ] | ||
55 | then | ||
56 | waiting="-w" | ||
57 | shift 1 | ||
58 | fi | ||
59 | |||
60 | if [ "x$1" = "x" ]; then | ||
61 | tgt=$(basename $(pwd)) | ||
62 | # These checks are kludgy. | ||
63 | if [ "$tgt" = "scripts" ]; then | ||
64 | all="-a" | ||
65 | cd ${PRGDIR}/../../config/ROBUST | ||
66 | tgt="ROBUST" | ||
67 | fi | ||
68 | if [ "$tgt" = "bin" ]; then | ||
69 | uptime | ||
70 | wait_for_text "ROBUST" "INITIALIZATION COMPLETE FOR ROBUST" | ||
71 | if [ ! "x$all" = "x" ] | ||
72 | then | ||
73 | echo "Sleeping for $((${delay} / 2)) seconds." | ||
74 | sleep $((${delay} / 2)) | ||
75 | for i in $(seq -w 1 99) | ||
76 | do | ||
77 | if [ -e "${PRGDIR}/../../config/sim${i}" ] | ||
78 | then | ||
79 | uptime | ||
80 | echo "Starting sim${i}." | ||
81 | cd ${PRGDIR}/../../config/sim${i}; ./start-sim -w | ||
82 | uptime | ||
83 | # Sleep for a while, so that there is plenty of time to finish starting scripts and such, | ||
84 | # and we are not keeping the computer very busy if there are lots of sims. | ||
85 | echo "Sleeping for ${delay} seconds." | ||
86 | sleep ${delay} | ||
87 | fi | ||
88 | done | ||
89 | uptime | ||
90 | fi | ||
91 | exit 0 | ||
92 | fi | ||
93 | num="$(echo ${tgt} | cut -c 4-)" | ||
94 | elif [ -d "$1" ]; then | ||
95 | tgt=$1 | ||
96 | elif [ -d "sim$1" ]; then | ||
97 | num=$1 | ||
98 | tgt="sim${num}" | ||
99 | else | ||
100 | tgt=$1 | ||
101 | inventory=$1 | ||
102 | fi | ||
103 | |||
104 | if [ "x$tgt" = "x" ]; then | ||
105 | echo "usage:" | ||
106 | echo " $ $(basename $0) <sim>" | ||
107 | echo "where <sim> is one of: " robust sim[0-9][0-9] | ||
108 | exit 1 | ||
109 | fi | ||
110 | |||
111 | cd ${bindir} | ||
112 | |||
113 | if ( ${tmux_command} -q list-sessions 2>/dev/null | grep -q ${console_name}: ); then | ||
114 | true | ||
115 | else | ||
116 | # The sudo is only so that the session is owned by opensim, otherwise it's owned by whoever ran this script, which is a likely security hole. | ||
117 | # After the session is created, we rely on the ${PRGDIR}/../../caches/ directory to be group sticky, so that anyone in the opensim group can attach to the tmux socket. | ||
118 | $SUDO ${tmux_command} new-session -d -s ${console_name} -n "ROBUST" | ||
119 | fi | ||
120 | |||
121 | |||
122 | if [ "x$tgt" = "xROBUST" ]; then | ||
123 | exe="Robust" | ||
124 | title="ROBUST" | ||
125 | elif [ "x$inventory" = "x" ]; then | ||
126 | exe="OpenSim" | ||
127 | # Grab the first RegionName line of the sims .ini file, cut it down to the name. | ||
128 | title=$(getSimName ${num}) | ||
129 | fi | ||
130 | |||
131 | case $(basename $0) in | ||
132 | "start-sim") | ||
133 | cmd="mono ${exe}.exe -inidirectory=../../config/${tgt} " | ||
134 | |||
135 | # Check if it's already running. | ||
136 | if [ -e ${PRGDIR}/../../caches/${tgt}.pid ] | ||
137 | then | ||
138 | # Double check if it's REALLY running. | ||
139 | if [ "x$(ps -p $(cat ${PRGDIR}/../../caches/${tgt}.pid) --no-headers -o comm)" = "x" ]; then | ||
140 | $SUDO rm -f ${PRGDIR}/../../caches/${tgt}.pid | ||
141 | fi | ||
142 | fi | ||
143 | # Now see if it's really really running. lol | ||
144 | if [ ! -e ${PRGDIR}/../../caches/${tgt}.pid ] | ||
145 | then | ||
146 | if [ "x$tgt" = "xROBUST" ]; then | ||
147 | ${tmux_command} split-window -hp 50 -t "${tmux_session}:" "${cmd}" | ||
148 | else | ||
149 | ${tmux_command} new-window -dn "${title}" -t "${tmux_session}:${num}" "${cmd}" | ||
150 | fi | ||
151 | fi | ||
152 | |||
153 | if [ ! "x$all" = "x" ] | ||
154 | then | ||
155 | ${tmux_send}:ROBUST.{left} "../scripts/start-sim -a -d ${delay}" Enter | ||
156 | fi | ||
157 | |||
158 | if [ "x$quiet" = "x" ] | ||
159 | then | ||
160 | if [ "x$tgt" = "xROBUST" ]; then | ||
161 | ${tmux_window} \; attach-session -t "${tmux_session}" | ||
162 | fi | ||
163 | fi | ||
164 | |||
165 | if [ ! "x$waiting" = "x" ] | ||
166 | then | ||
167 | wait_for_text "${title}" "INITIALIZATION COMPLETE FOR ${title}" | ||
168 | fi | ||
169 | ;; | ||
170 | |||
171 | "backup-inventory") | ||
172 | cd ${PRGDIR} | ||
173 | $SUDO ${PRGDIR}/gitAR.sh i "${inventory}" | ||
174 | user=$(sanitize "${inventory}") | ||
175 | # Add the full date and time to create the IAR file name. | ||
176 | cmd="save iar -c ${inventory} / password ${PRGDIR}/../../backups/${user}-${date}.iar" | ||
177 | # Do it in the highest numbered window. | ||
178 | ${tmux_send}:"$" "${cmd}" Enter | ||
179 | wait_for_text "$" "Saved archive with [[:digit:]]+ items for ${user/_/ }" | ||
180 | ${tmux_send}:"$" "force gc" Enter Enter Enter | ||
181 | ;; | ||
182 | |||
183 | "backup-sim") | ||
184 | if [ -e ${PRGDIR}/../../caches/${tgt}.pid ]; then | ||
185 | cd ${PRGDIR} | ||
186 | $SUDO ${PRGDIR}/gitAR.sh o "${title}" | ||
187 | sim=$(sanitize "${title}") | ||
188 | # Add the full date and time to create the OAR file name. | ||
189 | cmd="save oar --all ${PRGDIR}/../../backups/${sim}-${date}.oar" | ||
190 | ${tmux_send}:"${title}" "${cmd}" Enter | ||
191 | wait_for_text "${title}" "Finished writing out OAR for ${title}" | ||
192 | # Generate the map tiles, coz the good generator leaks memory badly if you leave it turned on. | ||
193 | ${tmux_send}:"${title}" "generate map" Enter | ||
194 | ${tmux_send}:"${title}" "force gc" Enter Enter Enter | ||
195 | else | ||
196 | echo "No OAR created for ${title}, it's not running." | ||
197 | fi | ||
198 | ;; | ||
199 | |||
200 | "stop-sim") | ||
201 | if [ -e ${PRGDIR}/../../caches/${tgt}.pid ]; then | ||
202 | ${tmux_send}:"${title}" "alert WARNING - Emergency shutdown in one minute!" Enter | ||
203 | ${tmux_send}:"${title}" "alert WARNING - Emergency shutdown in one minute!" Enter | ||
204 | sleep 30 | ||
205 | ${tmux_send}:"${title}" "alert WARNING - Emergency shutdown in thirty seconds!" Enter | ||
206 | ${tmux_send}:"${title}" "alert WARNING - Emergency shutdown in thirty seconds!" Enter | ||
207 | sleep 30 | ||
208 | ${tmux_send}:"${title}" "shutdown" Enter | ||
209 | sleep 30 | ||
210 | if [ -e ${PRGDIR}/../../caches/${tgt}.pid ]; then | ||
211 | echo "Killing it with extreme prejudice!" | ||
212 | kill -TERM `cat ${PRGDIR}/../../caches/${tgt}.pid` | ||
213 | fi | ||
214 | else | ||
215 | echo "Sim ${title} is not running, so not stopping." | ||
216 | fi | ||
217 | ;; | ||
218 | esac | ||