aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts/common.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/common.sh')
-rwxr-xr-xscripts/common.sh75
1 files changed, 75 insertions, 0 deletions
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
3OS_PATH="/opt/opensim_SC"
4OS_USER="opensimsc"
5
6# Figure out where we are, most of this mess is to troll through soft links.
7# PRGDIR=$(getPrgDir)
8getPrgDir()
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)
29num2name()
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")
37sanitize()
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)
45getSimName()
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"
54sleepPerSize()
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}