From 1bbff3ce1b261ef9cb6ba217ca0d8fcb54971513 Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 13 Apr 2009 12:31:42 +0100 Subject: Initial import --- includes/generic-includes.sh | 122 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 includes/generic-includes.sh (limited to 'includes/generic-includes.sh') 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 +} -- cgit v1.2.3