summaryrefslogtreecommitdiff
path: root/includes/generic-includes.sh
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2009-04-13 12:31:42 +0100
committerNick White <git@njw.me.uk>2009-04-13 12:31:42 +0100
commit1bbff3ce1b261ef9cb6ba217ca0d8fcb54971513 (patch)
treeac5ca6418afec68f5f5c3f2f84601559d41d144b /includes/generic-includes.sh
downloadgemrb-gameinstallers-1bbff3ce1b261ef9cb6ba217ca0d8fcb54971513.tar.bz2
gemrb-gameinstallers-1bbff3ce1b261ef9cb6ba217ca0d8fcb54971513.zip
Initial import
Diffstat (limited to 'includes/generic-includes.sh')
-rw-r--r--includes/generic-includes.sh122
1 files changed, 122 insertions, 0 deletions
diff --git a/includes/generic-includes.sh b/includes/generic-includes.sh
new file mode 100644
index 0000000..e14138f
--- /dev/null
+++ b/includes/generic-includes.sh
@@ -0,0 +1,122 @@
+### default variables ###
+
+[ -z "$TMPDIR" ] && export TMPDIR="/tmp/iepatch"
+
+[ -z "$TARGETDIR" ] && export TARGETDIR="$PWD/$SHORTGAMENAME"
+
+[ -z "$LANGUAGE" ] && export LANGUAGE="English"
+
+### functions ###
+
+function die
+{
+ #echo "Install can not continue, cleaning up partial install"
+ #rm -rf "$TARGETDIR"
+
+ echo ""
+ echo "The install failed; sorry."
+ echo "Please make sure you have the correct CDs for $FULLGAMENAME"
+ echo "and enough free disk space, and try again."
+
+ exit 1
+}
+
+function diequietly
+{
+ exit 1
+}
+
+function setuptmp
+{
+ rm -rf $TMPDIR
+ mkdir -p $TMPDIR || die
+}
+
+function cleanuptmp
+{
+ rm -rf $TMPDIR
+}
+
+function checkforbin
+{
+ # usage: checkforbin binnames...
+ retstatus=0
+
+ while [ "$1" != "" ]; do
+ binname=$1
+
+ which "$binname" &> /dev/null
+ if [ $? -ne 0 ]; then
+ echo "WARNING: This script needs $binname, which doesn't appear to be installed." 1>&2
+ retstatus=1
+ fi
+
+ shift
+ done
+
+ return $retstatus
+}
+
+function setperms
+{
+ # usage setperms targetdir
+
+ if ! [ -d "$1" ]; then
+ return 1
+ fi
+
+ find "$1" -type d -exec chmod 755 '{}' \;
+ find "$1" -type f -exec chmod 644 '{}' \;
+ find "$1" -type f -iname '*.exe' -exec chmod 755 '{}' \;
+ find "$1" -type f -iname '*.ini' -exec chmod 664 '{}' \;
+ chgrp -R games "$1"
+ if [ -d "$1"/save ]; then
+ chmod -R g+w "$1"/save
+ fi
+ if [ -d "$1"/mpsave ]; then
+ chmod -R g+w "$1"/mpsave
+ fi
+}
+
+function usage
+{
+ echo "Usage:" $0 "[-i installdir] [-p patchdir] [-c cdmount] [-l language]"
+ echo -e " -i installdir is the directory to install to."
+ echo -e " default:" $TARGETDIR
+ echo -e " -c cdmount is the mount location of the cd drive used."
+ echo -e " default:" $CDMOUNT
+ echo -e " -p patchdir is an optional directory containing patch files."
+ echo -e " default:" $PATCHDIR
+ echo -e " -l language can be one of English, Spanish, French, German, Italian or Language Independant"
+ echo -e " default:" $LANGUAGE
+ # TODO: Add option to show and select all known BG1 versions
+}
+
+function parseargs
+{
+ while getopts ":i:p:c:l:" options; do
+ case $options in
+ i ) export TARGETDIR="$OPTARG";;
+ p ) export PATCHDIR="$OPTARG";;
+ c ) export CDMOUNT="${OPTARG%\/}";; # ensure no trailing slash
+ l ) export LANGUAGE="$OPTARG";;
+ \? ) usage
+ exit 1;;
+ h ) usage
+ exit 1;;
+ esac
+ done
+}
+
+function copylower
+{
+ #usage: copylower source destination
+ if [ -d "$1" ]; then
+ for filename in $(find "$1" -type f); do
+ lowerpath="$(echo $filename|gawk -F "$1" '{print $2}'|tr A-Z a-z)"
+ cp -f "$filename" "$2/$lowerpath" || die
+ done
+ elif [ -f "$1" ]; then
+ cp -f "$(echo $1|tr A-Z a-z)" "$2"
+ fi
+}