diff options
author | Nick White <git@njw.me.uk> | 2009-04-13 12:31:42 +0100 |
---|---|---|
committer | Nick White <git@njw.me.uk> | 2009-04-13 12:31:42 +0100 |
commit | 1bbff3ce1b261ef9cb6ba217ca0d8fcb54971513 (patch) | |
tree | ac5ca6418afec68f5f5c3f2f84601559d41d144b /includes | |
download | gemrb-gameinstallers-1bbff3ce1b261ef9cb6ba217ca0d8fcb54971513.tar.bz2 gemrb-gameinstallers-1bbff3ce1b261ef9cb6ba217ca0d8fcb54971513.zip |
Initial import
Diffstat (limited to 'includes')
-rw-r--r-- | includes/autoinstall-includes.sh | 59 | ||||
-rw-r--r-- | includes/cd-includes.sh | 52 | ||||
-rw-r--r-- | includes/generic-includes.sh | 122 | ||||
-rw-r--r-- | includes/patch-includes.sh | 17 |
4 files changed, 250 insertions, 0 deletions
diff --git a/includes/autoinstall-includes.sh b/includes/autoinstall-includes.sh new file mode 100644 index 0000000..a3bfa52 --- /dev/null +++ b/includes/autoinstall-includes.sh @@ -0,0 +1,59 @@ +### variables ### + +[ -z "$FULLINSTALL" ] && export FULLINSTALL=1 + +### functions ### + +# a simplified version of query() from sorcery +# $1 = question +# $2 = default boolean answer [yYnN] +function query { + while true; do + RESPONSE="" + echo -e -n "$1 [$2] " + read -n 1 RESPONSE + echo + + RESPONSE=${RESPONSE:=$2} + case $RESPONSE in + n|N) return 1 ;; + y|Y) return 0 ;; + esac + done +} + +function recommendcfg +{ + # usage: recommendcfg [numofcds] + + if [ "$1" ]; then + NUMOFCDS=$1 + else + NUMOFCDS=0 + fi + + echo + echo "To play the game with GemRB, you will need to add the following" + echo "lines to your GemRB.cfg file:" + echo + LINE="GamePath=$TARGETDIR"; echo $LINE + if [ $FULLINSTALL -eq 1 ]; then + LINE="CD1=$TARGETDIR"; echo $LINE + if [ $NUMOFCDS -gt 0 ]; then + for CDNUMBER in $(seq 2 $NUMOFCDS); do + LINE="CD$CDNUMBER=$TARGETDIR" + echo $LINE + done + fi + echo "GameOnCD=0" + else + LINE="CD1=$CDMOUNT"; echo $LINE + if [ $NUMOFCDS -gt 0 ]; then + for CDNUMBER in $(seq 2 $NUMOFCDS); do + LINE="CD$CDNUMBER=$CDMOUNT/cd$CDNUMBER" + echo $LINE + done + fi + echo "GameOnCD=1" + fi +} diff --git a/includes/cd-includes.sh b/includes/cd-includes.sh new file mode 100644 index 0000000..e3d00fd --- /dev/null +++ b/includes/cd-includes.sh @@ -0,0 +1,52 @@ +### default variables ### + +[ -z "$CDMOUNT" ] && export CDMOUNT="/media/cdrom" + +### functions ### + +function checkcd +{ + # usage: checkcd md5sum md5file + checksum=$(md5sum $2 2>/dev/null|awk '{print $1}') + + if [ "$checksum" != "$1" ]; then + return 1 + fi + + return 0 +} + +function getcd +{ + # usage: getcd cdnum [md5sum] [md5file] + # note we're redirecting to stderr to ensure questions + # are always shown + + if [ $# -ge 3 ]; then + answer="" + while [ $(checkcd $2 $CDMOUNT/$3; echo $?) -ne 0 ]; do + echo " * Insert CD $1 and press any key, or press 'c' to continue without checking" 1>&2 + read -sn 1 answer + if [ "$answer" == 'c' ]; then + return 0 + fi + done + else + echo "* Please insert CD $1 and press any key" 1>&2 + read -sn 1 + fi + + return 0 +} + +function copycdextras +{ + # usage: copycdextras cdnum + # essentially a case insensitive cp -R cd#/* + CDNUMBER=$1 + + for filename in $(find $CDMOUNT/[cC][dD]$CDNUMBER/ -type f || die); do + relativepath=$(echo $filename|gawk -F "$CDMOUNT/[cC][dD]$CDNUMBER" '{print $2}'|tr A-Z a-z) + cp $filename "$TARGETDIR"/$relativepath || die + done +} 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 +} diff --git a/includes/patch-includes.sh b/includes/patch-includes.sh new file mode 100644 index 0000000..0f76409 --- /dev/null +++ b/includes/patch-includes.sh @@ -0,0 +1,17 @@ +### default variables ### + +[ -z "$PATCHDIR" ] && export PATCHDIR="$PWD" + +### functions ### + +function getpatch +{ + url=$1 + filename=$(basename $url) + + if [ -f "$PATCHDIR/$filename" ]; then + cp "$PATCHDIR/$filename" $TMPDIR || die + else + wget $url -O $TMPDIR/$filename || die + fi +} |