diff options
author | David Walter Seikel | 2016-11-27 23:51:59 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-27 23:51:59 +1000 |
commit | c0ff56729a59dc30589de6af6120d825fbaa8cc3 (patch) | |
tree | 1c7e2f842548a5c9fef566d2045f3ad8aac603cb | |
parent | White space and typo clean ups. (diff) | |
download | opensim-SC-c0ff56729a59dc30589de6af6120d825fbaa8cc3.zip opensim-SC-c0ff56729a59dc30589de6af6120d825fbaa8cc3.tar.gz opensim-SC-c0ff56729a59dc30589de6af6120d825fbaa8cc3.tar.bz2 opensim-SC-c0ff56729a59dc30589de6af6120d825fbaa8cc3.tar.xz |
Break out common script bits into their own file.
Diffstat (limited to '')
-rwxr-xr-x | scripts/backup-inventories.sh | 17 | ||||
-rwxr-xr-x | scripts/backup-sims.sh | 21 | ||||
-rwxr-xr-x | scripts/common.sh | 76 | ||||
-rwxr-xr-x | scripts/gitAR.sh | 23 | ||||
-rwxr-xr-x | scripts/start-sim | 20 |
5 files changed, 89 insertions, 68 deletions
diff --git a/scripts/backup-inventories.sh b/scripts/backup-inventories.sh index 30f8ac6..1d753eb 100755 --- a/scripts/backup-inventories.sh +++ b/scripts/backup-inventories.sh | |||
@@ -1,20 +1,7 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | # Figure out where we are, most of this mess is to troll through soft links. | 3 | source common.sh |
4 | PRG="$0" | 4 | getPrgDir |
5 | while [ -h "${PRG}" ] ; do | ||
6 | ls=$(ls -ld "${PRG}") | ||
7 | link=`expr "${ls}" : '.*-> \(.*\)$'` | ||
8 | if expr "${link}" : '.*/.*' > /dev/null; then | ||
9 | PRG="${link}" | ||
10 | else | ||
11 | PRG=$(dirname "${PRG}")/"${link}" | ||
12 | fi | ||
13 | done | ||
14 | PRGDIR=$(dirname "${PRG}") | ||
15 | pushd ${PRGDIR} >/dev/null | ||
16 | PRGDIR=$(pwd) | ||
17 | popd >/dev/null | ||
18 | 5 | ||
19 | # Get the database credentials. | 6 | # Get the database credentials. |
20 | declare -A creds | 7 | declare -A creds |
diff --git a/scripts/backup-sims.sh b/scripts/backup-sims.sh index fb18c18..2d174b1 100755 --- a/scripts/backup-sims.sh +++ b/scripts/backup-sims.sh | |||
@@ -1,25 +1,12 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | # Figure out where we are, most of this mess is to troll through soft links. | 3 | source common.sh |
4 | PRG="$0" | 4 | getPrgDir |
5 | while [ -h "${PRG}" ] ; do | ||
6 | ls=$(ls -ld "${PRG}") | ||
7 | link=`expr "${ls}" : '.*-> \(.*\)$'` | ||
8 | if expr "${link}" : '.*/.*' > /dev/null; then | ||
9 | PRG="${link}" | ||
10 | else | ||
11 | PRG=$(dirname "${PRG}")/"${link}" | ||
12 | fi | ||
13 | done | ||
14 | PRGDIR=$(dirname "${PRG}") | ||
15 | pushd ${PRGDIR} >/dev/null | ||
16 | PRGDIR=$(pwd) | ||
17 | popd >/dev/null | ||
18 | 5 | ||
19 | for i in $(seq 99) | 6 | for i in $(seq 99) |
20 | do | 7 | do |
21 | j=$(printf "sim%02d" $i) | 8 | j=$(num2name ${i}) |
22 | if [ -e "${PRGDIR}/../config/$j" ] | 9 | if [ -e "${PRGDIR}/../config/${j}" ] |
23 | then | 10 | then |
24 | cd ${PRGDIR}/../config/$j | 11 | cd ${PRGDIR}/../config/$j |
25 | ./backup-sim | 12 | ./backup-sim |
diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100755 index 0000000..2ec19ce --- /dev/null +++ b/scripts/common.sh | |||
@@ -0,0 +1,76 @@ | |||
1 | #!/bin/echo Don't run this file, it's for common functions." | ||
2 | |||
3 | |||
4 | # Figure out where we are, most of this mess is to troll through soft links. | ||
5 | # PRGDIR=$(getPrgDir) | ||
6 | getPrgDir() | ||
7 | { | ||
8 | PRG="$0" | ||
9 | while [ -h "${PRG}" ] ; do | ||
10 | ls=$(ls -ld "${PRG}") | ||
11 | link=`expr "${ls}" : '.*-> \(.*\)$'` | ||
12 | if expr "${link}" : '.*/.*' > /dev/null; then | ||
13 | PRG="${link}" | ||
14 | else | ||
15 | PRG=$(dirname "${PRG}")/"${link}" | ||
16 | fi | ||
17 | done | ||
18 | PRGDIR=$(dirname "${PRG}") | ||
19 | pushd ${PRGDIR} >/dev/null | ||
20 | export PRGDIR=$(pwd) | ||
21 | popd >/dev/null | ||
22 | } | ||
23 | |||
24 | |||
25 | # Convert number to sim name | ||
26 | # name=$(num2name 1) | ||
27 | num2name() | ||
28 | { | ||
29 | # Using a string format, coz using a number format ends with an octal error, coz 08 isn't a valid octal number. | ||
30 | # Why isn't octal dead already? | ||
31 | printf 'sim%02s' "$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/[\\/:\*\?"<>\|@#$%&\0\x01-\x1F\x27\x40\x60\x7F. ]/_/g' -e 's/^$/NONAME/' | ||
40 | } | ||
41 | |||
42 | |||
43 | # Grab the first Section line of the sims .xml file, cut it down to the name. | ||
44 | # name=$(getSimName 1) | ||
45 | getSimName() | ||
46 | { | ||
47 | grep "<Section " ${PRGDIR}/../../config/$(num2name $1)/*.xml | 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 | } | ||
76 | |||
diff --git a/scripts/gitAR.sh b/scripts/gitAR.sh index 2a067be..25cab48 100755 --- a/scripts/gitAR.sh +++ b/scripts/gitAR.sh | |||
@@ -11,31 +11,16 @@ | |||
11 | 11 | ||
12 | # Not really meant to be called by users, so don't bother validating the input and such. | 12 | # Not really meant to be called by users, so don't bother validating the input and such. |
13 | 13 | ||
14 | source common.sh | ||
15 | getPrgDir | ||
16 | |||
14 | type=$1 | 17 | type=$1 |
15 | title=$2 | 18 | title=$2 |
16 | |||
17 | # Figure out where we are, most of this mess is to troll through soft links. | ||
18 | PRG="$0" | ||
19 | while [ -h "${PRG}" ] ; do | ||
20 | ls=$(ls -ld "${PRG}") | ||
21 | link=`expr "${ls}" : '.*-> \(.*\)$'` | ||
22 | if expr "${link}" : '.*/.*' > /dev/null; then | ||
23 | PRG="${link}" | ||
24 | else | ||
25 | PRG=$(dirname "${PRG}")/"${link}" | ||
26 | fi | ||
27 | done | ||
28 | PRGDIR=$(dirname "${PRG}") | ||
29 | pushd ${PRGDIR} >/dev/null | ||
30 | PRGDIR=$(pwd) | ||
31 | popd >/dev/null | ||
32 | |||
33 | date=$(date '+%F_%T') | 19 | date=$(date '+%F_%T') |
34 | 20 | ||
35 | # Sanitize the name. Not removing [ or ], couldn't get that to work, only important for Windows. | ||
36 | name=$(echo "${title}" | sed -e 's/[\\/:\*\?"<>\|@#$%&\0\x01-\x1F\x27\x40\x60\x7F. ]/_/g' -e 's/^$/NONAME/') | ||
37 | # Convert the type to uppercase. | 21 | # Convert the type to uppercase. |
38 | gar="_git$(echo -n ${type} | tr '[:lower:]' '[:upper:]')AR" | 22 | gar="_git$(echo -n ${type} | tr '[:lower:]' '[:upper:]')AR" |
23 | name=$(sanitize "${title}") | ||
39 | 24 | ||
40 | if [ -d ${PRGDIR}/../../backups/temp_backup${type}_${name} ]; then | 25 | if [ -d ${PRGDIR}/../../backups/temp_backup${type}_${name} ]; then |
41 | echo "WARNING - Mess left over from last backup, not gonna run!" | 26 | echo "WARNING - Mess left over from last backup, not gonna run!" |
diff --git a/scripts/start-sim b/scripts/start-sim index ed2b07f..72bb9ba 100755 --- a/scripts/start-sim +++ b/scripts/start-sim | |||
@@ -1,21 +1,7 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | # Figure out where we are, most of this mess is to troll through soft links. | 3 | source common.sh |
4 | PRG="$0" | 4 | getPrgDir |
5 | while [ -h "${PRG}" ] ; do | ||
6 | ls=$(ls -ld "${PRG}") | ||
7 | link=`expr "${ls}" : '.*-> \(.*\)$'` | ||
8 | if expr "${link}" : '.*/.*' > /dev/null; then | ||
9 | PRG="${link}" | ||
10 | else | ||
11 | PRG=$(dirname "${PRG}")/"${link}" | ||
12 | fi | ||
13 | done | ||
14 | PRGDIR=$(dirname "${PRG}") | ||
15 | pushd ${PRGDIR} >/dev/null | ||
16 | PRGDIR=$(pwd) | ||
17 | popd >/dev/null | ||
18 | |||
19 | 5 | ||
20 | USER=$(whoami) | 6 | USER=$(whoami) |
21 | console_name="OpenSim_console" | 7 | console_name="OpenSim_console" |
@@ -78,7 +64,7 @@ if [ "x$tgt" = "xROBUST" ]; then | |||
78 | elif [ "x$inventory" = "x" ]; then | 64 | elif [ "x$inventory" = "x" ]; then |
79 | exe="OpenSim" | 65 | exe="OpenSim" |
80 | # Grab the first Section line of the sims .xml file, cut it down to the name. | 66 | # Grab the first Section line of the sims .xml file, cut it down to the name. |
81 | title=$(grep "<Section " ../config/${tgt}/*.xml | head -n 1 | cut -d '"' -f 2 ) | 67 | title=$(getSimName ${num}) |
82 | fi | 68 | fi |
83 | 69 | ||
84 | case $(basename $0) in | 70 | case $(basename $0) in |