From c0ff56729a59dc30589de6af6120d825fbaa8cc3 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 27 Nov 2016 23:51:59 +1000 Subject: Break out common script bits into their own file. --- scripts/backup-inventories.sh | 17 ++-------- scripts/backup-sims.sh | 21 +++--------- scripts/common.sh | 76 +++++++++++++++++++++++++++++++++++++++++++ scripts/gitAR.sh | 23 +++---------- scripts/start-sim | 20 ++---------- 5 files changed, 89 insertions(+), 68 deletions(-) create mode 100755 scripts/common.sh 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 @@ #!/bin/bash -# Figure out where we are, most of this mess is to troll through soft links. -PRG="$0" -while [ -h "${PRG}" ] ; do - ls=$(ls -ld "${PRG}") - link=`expr "${ls}" : '.*-> \(.*\)$'` - if expr "${link}" : '.*/.*' > /dev/null; then - PRG="${link}" - else - PRG=$(dirname "${PRG}")/"${link}" - fi -done -PRGDIR=$(dirname "${PRG}") -pushd ${PRGDIR} >/dev/null -PRGDIR=$(pwd) -popd >/dev/null +source common.sh +getPrgDir # Get the database credentials. 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 @@ #!/bin/bash -# Figure out where we are, most of this mess is to troll through soft links. -PRG="$0" -while [ -h "${PRG}" ] ; do - ls=$(ls -ld "${PRG}") - link=`expr "${ls}" : '.*-> \(.*\)$'` - if expr "${link}" : '.*/.*' > /dev/null; then - PRG="${link}" - else - PRG=$(dirname "${PRG}")/"${link}" - fi -done -PRGDIR=$(dirname "${PRG}") -pushd ${PRGDIR} >/dev/null -PRGDIR=$(pwd) -popd >/dev/null +source common.sh +getPrgDir for i in $(seq 99) do - j=$(printf "sim%02d" $i) - if [ -e "${PRGDIR}/../config/$j" ] + j=$(num2name ${i}) + if [ -e "${PRGDIR}/../config/${j}" ] then cd ${PRGDIR}/../config/$j ./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 @@ +#!/bin/echo Don't run this file, it's for common functions." + + +# Figure out where we are, most of this mess is to troll through soft links. +# PRGDIR=$(getPrgDir) +getPrgDir() +{ + PRG="$0" + while [ -h "${PRG}" ] ; do + ls=$(ls -ld "${PRG}") + link=`expr "${ls}" : '.*-> \(.*\)$'` + if expr "${link}" : '.*/.*' > /dev/null; then + PRG="${link}" + else + PRG=$(dirname "${PRG}")/"${link}" + fi + done + PRGDIR=$(dirname "${PRG}") + pushd ${PRGDIR} >/dev/null + export PRGDIR=$(pwd) + popd >/dev/null +} + + +# Convert number to sim name +# name=$(num2name 1) +num2name() +{ + # Using a string format, coz using a number format ends with an octal error, coz 08 isn't a valid octal number. + # Why isn't octal dead already? + printf 'sim%02s' "$1" +} + + +# Sanitize the name. Not removing [ or ], couldn't get that to work, only important for Windows. +# name=$(sanitize "the name") +sanitize() +{ + echo "$1" | sed -e 's/[\\/:\*\?"<>\|@#$%&\0\x01-\x1F\x27\x40\x60\x7F. ]/_/g' -e 's/^$/NONAME/' +} + + +# Grab the first Section line of the sims .xml file, cut it down to the name. +# name=$(getSimName 1) +getSimName() +{ + grep "
\(.*\)$'` - if expr "${link}" : '.*/.*' > /dev/null; then - PRG="${link}" - else - PRG=$(dirname "${PRG}")/"${link}" - fi -done -PRGDIR=$(dirname "${PRG}") -pushd ${PRGDIR} >/dev/null -PRGDIR=$(pwd) -popd >/dev/null - date=$(date '+%F_%T') -# Sanitize the name. Not removing [ or ], couldn't get that to work, only important for Windows. -name=$(echo "${title}" | sed -e 's/[\\/:\*\?"<>\|@#$%&\0\x01-\x1F\x27\x40\x60\x7F. ]/_/g' -e 's/^$/NONAME/') # Convert the type to uppercase. gar="_git$(echo -n ${type} | tr '[:lower:]' '[:upper:]')AR" +name=$(sanitize "${title}") if [ -d ${PRGDIR}/../../backups/temp_backup${type}_${name} ]; then 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 @@ #!/bin/bash -# Figure out where we are, most of this mess is to troll through soft links. -PRG="$0" -while [ -h "${PRG}" ] ; do - ls=$(ls -ld "${PRG}") - link=`expr "${ls}" : '.*-> \(.*\)$'` - if expr "${link}" : '.*/.*' > /dev/null; then - PRG="${link}" - else - PRG=$(dirname "${PRG}")/"${link}" - fi -done -PRGDIR=$(dirname "${PRG}") -pushd ${PRGDIR} >/dev/null -PRGDIR=$(pwd) -popd >/dev/null - +source common.sh +getPrgDir USER=$(whoami) console_name="OpenSim_console" @@ -78,7 +64,7 @@ if [ "x$tgt" = "xROBUST" ]; then elif [ "x$inventory" = "x" ]; then exe="OpenSim" # Grab the first Section line of the sims .xml file, cut it down to the name. - title=$(grep "