### default variables ### [ -z "$TMPDIR" ] && export TMPDIR="/tmp/iepatch" [ -z "$TARGETDIR" ] && [ -e "$SHORTGAMENAME" ] && 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" &> /dev/null 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 }