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/common.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 scripts/common.sh (limited to 'scripts/common.sh') 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 "