PDA

View Full Version : Quake 4 DVD installation script


brebs
19th May 2008, 06:36 PM
Here's a reasonably distro-agnostic and foolproof installation script for Quake4, to ease the pain of installing it from a DVD.

Save it as a text file named installquake4. Then take a look at it, tweaking the DVD line if required, then run it as root:
sudo bash installquake4
It does not work yet with the multiple CD version - maybe support for that will be added later.

Here's a copy of the script:
#!/bin/bash

# installquake4 - installs Quake 4 from DVD. Run as root.
# Version 1.1 (added check on EUID)

# Copyright (C) 2008 Paul Bredbury <brebs@sent.com>
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The **** You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.

# Installs startup scripts in /usr/bin rather than /usr/local/bin,
# to prevent having to explain to newbies how to change their PATH.

# Tweak these to fit your installation
DVD=/media/cdrom
DEST=/opt/quake4

if [[ $EUID -ne 0 ]] ; then
echo "This script must be run as root." >&2
exit 1
fi

if [[ -e "$DEST" ]] ; then
echo "$DEST already exists - remove it." >&2
exit 1
fi

# Check that ImageMagick is installed
if [[ -z $(convert -help | grep ImageMagick) ]] ; then
echo "Install ImageMagick, then re-run this script." >&2
echo "Fedora command to use: yum install ImageMagick" >&2
echo "Ubuntu command to use: apt-get install imagemagick" >&2
exit 1
fi

# Check that md5sum is installed
md5sum --version > /dev/null
if [[ $? -gt 0 ]] ; then
echo "Install md5sum, then re-run this script." >&2
echo "Fedora command to use: yum install coreutils" >&2
echo "Ubuntu command to use: apt-get install coreutils" >&2
exit 1
fi

# Check that wget is installed
wget --version > /dev/null
if [[ $? -gt 0 ]] ; then
echo "Install wget, then re-run this script." >&2
echo "Fedora command to use: yum install wget" >&2
echo "Ubuntu command to use: apt-get install wget" >&2
exit 1
fi

# Check DVD
if ! [[ -e "$DVD"/Setup/Data/q4base/pak001.pk4 ]] ; then
echo "Attempting to mount $DVD"
mount -t udf -o ro /dev/dvd "$DVD" || mount -t udf -o ro /dev/cdrom "$DVD"
fi
if ! [[ -e "$DVD"/Setup/Data/q4base/pak001.pk4 ]] ; then
echo "Cannot find pak001.pk4 at $DVD/Setup/Data/q4base/pak001.pk4" >&2
exit 1
fi
if ! [[ -e "$DVD"/Setup/Data/q4base/pak009.pk4 ]] ; then
echo "Cannot find pak009.pk4 at $DVD/Setup/Data/q4base/pak009.pk4" >&2
exit 1
fi

TMP=$(mktemp -d)

if [[ -z "$TMP" ]] ; then
echo "TMP undefined!" >&2
exit 1
fi

cd "$TMP" || exit 1
echo "Using $TMP for temporary storage"

if [[ -e /root/games/quake4-linux-1.4.2.x86.run ]] ; then
echo "Using local copy of .run"
cp /root/games/quake4-linux-1.4.2.x86.run . || exit 1
else
wget http://www.mirrorservice.org/sites/quakeunity.com/quake4/point_releases/quake4-linux-1.4.2.x86.run
fi
if [[ $(md5sum quake4-linux-1.4.2.x86.run | awk '{ print $1 }') != "bd2cb8164ede4272adcc091f724855ac" ]] ; then
rm -f quake4-linux-1.4.2.x86.run
wget http://ftp4.de.freesbie.org/pub/misc/ftp.idsoftware.com/idstuff/quake4/linux/quake4-linux-1.4.2.x86.run
fi
if [[ $(md5sum quake4-linux-1.4.2.x86.run | awk '{ print $1 }') != "bd2cb8164ede4272adcc091f724855ac" ]] ; then
echo "Re-download quake4-linux-1.4.2.x86.run" >&2
exit 1
fi
echo "Downloaded $TMP/quake4-linux-1.4.2.x86.run"

bash quake4-linux-1.4.2.x86.run --noexec --keep || exit 1
cd quake4-linux-1.4.2 || exit 1

# Rename the .off files, so they will be used
cd q4base || exit 1
if [[ ! -z $(ls *.off 2> /dev/null) ]] ; then
for f in *.off ; do
#echo "Renaming ${f}"
mv "${f}" "${f%.off}" || exit 1
done
fi
cd .. || exit 1

# Icon. Uses ImageMagick to remove the pink background.
convert -transparent magenta q4icon.bmp quake4.png || exit 1
mkdir -p /usr/share/icons || exit 1
mv -f quake4.png /usr/share/icons/ || exit 1
chown root:root /usr/share/icons/quake4.png || exit 1
chmod 644 /usr/share/icons/quake4.png || exit 1

mkdir -p "$DEST" || exit 1

# Based on http://bugs.gentoo.org/show_bug.cgi?id=173491
mv pb q4mp openurl.sh bin/Linux/x86/{quake4{,smp}.x86,q4ded.x86,*.so.?} *.{htm,txt} Docs README us/version.info "$DEST" || exit 1
mkdir -p "$DEST"/q4base || exit 1
mv q4base/* us/q4base/* "$DEST"/q4base/ || exit 1

# Data from DVD
# Based on http://sources.gentoo.org/viewcvs.py/*checkout*/gentoo-x86/games-fps/quake4-data/quake4-data-1.0.2147.12.ebuild
cd "$DEST"/q4base || exit 1
echo "Copying files from DVD"
cp "$DVD"/Setup/Data/q4base/zpak_{english,french,italian,spanish}.pk4 . || exit 1
cp "$DVD"/Setup/Data/q4base/pak{001,002,003,004,005,006,007,008,009,010,011,01 2}.pk4 . || exit 1

echo "Tidying up"
# Permissions
cd "$DEST" || exit 1
chown -R root:root * || exit 1
find -type f -exec chmod 644 '{}' \;
find -type d -exec chmod 755 '{}' \;
chmod 755 *.so.? pb/*.so openurl.sh *.x86 || exit 1

# Game & server executables
echo -e "#!/bin/sh\ncd \"$DEST\" && export LD_LIBRARY_PATH=\"$DEST:\${LD_LIBRARY_PATH}\" && exec ./quake4smp.x86 \"\$@\"" > /usr/bin/quake4 || exit 1
echo -e "#!/bin/sh\ncd \"$DEST\" && export LD_LIBRARY_PATH=\"$DEST:\${LD_LIBRARY_PATH}\" && exec ./q4ded.x86 \"\$@\"" > /usr/bin/quake4-server || exit 1
for f in /usr/bin/quake4{,-server} ; do
chown root:root $f
chmod 755 $f
done

# Desktop entry
cat > /usr/share/applications/quake4.desktop << EOF
[Desktop Entry]
Name=Quake 4
Comment=First-person shooter - sequel to Quake 2
Icon=quake4
Exec=quake4
Terminal=false
Type=Application
Categories=Game;ActionGame;
EOF
chown root:root /usr/share/applications/quake4.desktop || exit 1
chmod 644 /usr/share/applications/quake4.desktop || exit 1

echo
echo "Installed Quake 4. Run by entering: quake4"
echo "Run the server with: quake4-server"
echo
# The default language is Spanish!
echo "After running quake4 once, reset the language by running:"
echo "sed -i 's:spanish:english:' ~/.quake4/q4base/Quake4Config.cfg"

exit 0