#!/bin/sh

# Installs the Epic Bonus Pack for UT2003
#
# Script created by MeltDown <meltdown@unrealtower.org>
# For more information see http://www.unrealtower.org/
# Version 1.0, 2003-03-13
#
# This script is covered by the GPL license, as can be found at
# http://www.gnu.org/licenses/gpl.html

DEFAULTDIR="/usr/games/ut2003"
PACKNAME="UT2003-epicbonuspackone.exe"
PACKDIR="UT2003-BonusPack"

echo -n "Where did you install UT2003? [$DEFAULTDIR]: "
read INSTALLDIR

if [ -z $INSTALLDIR ]; then
	INSTALLDIR="$DEFAULTDIR";
fi

if [ ! -x $INSTALLDIR ]; then
	echo "The directory $INSTALLDIR doesn't exist, or isn't accessible"
	exit 1
fi

if [ ! -w $INSTALLDIR ]; then
	echo "You're not allowed to write to $INSTALLDIR"
	exit 2
fi

if [ ! -r "$PACKNAME" ]; then
	echo "Unable to find $PACKNAME in the current directory. Place this script in the same directory as UT2003-epicbonuspackone.exe and start it again."
	exit 3
fi

if [ ! -w "." ]; then
	echo "I can't write to the current directory, but I have to."
	exit 4
fi

echo "Unpacking $PACKNAME"
unzip $PACKNAME >/dev/null

cp $INSTALLDIR/System/Manifest.ini $INSTALLDIR/System/Manifest.ini-PRE-EPIC-BONUS-PACK

echo "Copying $PACKDIR/* to $INSTALLDIR"
echo
echo "Don't be afraid if you see warnings about preserving times, they are harmless"
echo
cp -ba $PACKDIR/* $INSTALLDIR

echo "Removing temporary directory '$PACKDIR'"
rm -rf $PACKDIR

cd $INSTALLDIR/System

echo
echo "Editing Default.ini in $PWD"
cat >> Default.ini <<EOT

[Xinterface.Tab_AudioSettings]
BonusPackInfo[1]=(PackageName="AnnouncerEvil.uax",Description="Evil")
BonusPackInfo[2]=(PackageName="AnnouncerFemale.uax",Description="Female")
BonusPackInfo[3]=(PackageName="AnnouncerSexy.uax",Description="Aroused")

EOT

ed Default.ini >/dev/null 2>&1 <<EOT
/\[xInterface.ExtendedConsole\]
a
MusicManagerClassName=OGGPlayer.UT2OGGMenu
.
w
q
EOT

ed Default.ini >/dev/null 2>&1 <<EOT
$
?EditPackages?
a
EditPackages=BonusPack
EditPackages=SkaarjPack
EditPackages=SkaarjPack_rc
.
w
q
EOT

ed Default.ini >/dev/null 2>&1 <<EOT
$
?ServerPackages?
a
ServerPackages=BonusPack
ServerPackages=SkaarjPack
ServerPackages=SkaarjPack_rc
.
w
q
EOT

echo "Editing DefUser.ini in $PWD"
sed 's/^F11=.*$/F11=MusicMenu/g'  < DefUser.ini > DefUser.ini~~
mv DefUser.ini~~ DefUser.ini

if [ -d $HOME/.ut2003/System ]; then
cd "$HOME/.ut2003/System"
echo "Editing UT2003.ini in $PWD"
cat >> UT2003.ini <<EOT

[Xinterface.Tab_AudioSettings]
BonusPackInfo[1]=(PackageName="AnnouncerEvil.uax",Description="Evil")
BonusPackInfo[2]=(PackageName="AnnouncerFemale.uax",Description="Female")
BonusPackInfo[3]=(PackageName="AnnouncerSexy.uax",Description="Aroused")

EOT

ed UT2003.ini >/dev/null 2>&1 <<EOT
/\[xInterface.ExtendedConsole\]
a
MusicManagerClassName=OGGPlayer.UT2OGGMenu
.
wq
EOT

ed UT2003.ini >/dev/null 2>&1 <<EOT
$
?EditPackages?
a
EditPackages=BonusPack
EditPackages=SkaarjPack
EditPackages=SkaarjPack_rc
.
wq
EOT

ed UT2003.ini >/dev/null 2>&1 <<EOT
$
?ServerPackages?
a
ServerPackages=BonusPack
ServerPackages=SkaarjPack
ServerPackages=SkaarjPack_rc
.
wq
EOT

echo "Editing User.ini in $PWD"
sed 's/^F11=.*$/F11=MusicMenu/g' < User.ini > User.ini~~
mv User.ini~~ User.ini
fi

echo 'All done!'
echo
echo
echo "Test if UT2003 works as expected. If it does, you can remove all
backup files by typing:"
echo
echo "find $INSTALLDIR -name '*~' -exec rm -f '{}' \;"
echo
echo 'Happy fragging! Visit me at http://www.unrealtower.org/'
echo 'This install script was brought to you by MeltDown'

