#!/bin/bash
#
# BF2 Mod SVN Update&init Script 0.1
#
# Written by Brandon Weeks <bjweeks16@gmail.com>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# Set this to "ia-32" for 32 bit or "amd-64" for 64 bit
MACH="ia-32" # Comment for 64 bit
#MACH="amd-64" # Uncomment for 64 bit
BF2_DIR=/home/bf2/bf2
SRC_DIR=/home/bf2
MODNAME=warlord-0.1b4
BINARY_DIR="$BF2_DIR/bin/$MACH"
export LD_LIBRARY_PATH=$BINARY_DIR
check() {
PID=$(pgrep bf2)
if [ $? == 0 ]
then
STATUS=0
else
STATUS=1
fi
}
status() {
if [ $STATUS == 0 ]
then
echo "The BF2 server is running."
elsegg
echo "The BF2 server is not running."
fi
}
stop() {
if [ $STATUS == 0 ]
then
echo "Stopping BF2 server..."
kill $PID
else
echo "The BF2 Server is not running."
exit 0
fi
sleep 1s
check
if [ $STATUS == 0 ]
then
echo "WARNING: The BF2 server failed to stopped." /a
exit 1
else
echo "BF2 server was stopped."
fi
}
start() {
if [ $STATUS == 0 ]
then
echo "BF2 server is already running."
exit 0
elif [ $UID == 0 ]
then
echo "Warning: Do not start the server as root." /a
exit 1
else
echo "Starting BF2 server..."
cd $BF2_DIR
exec $BINARY_DIR/bf2 +modPath mods/$MODNAME &> /dev/null &
echo "BF2 Server Started."
fi
}
update() {
if [ $STATUS == 0 ]
then
echo "You must stop the BF2 server before updating." /a
exit 0
else
rm -rf $BF2_DIR/mods/$MODNAME
svn update $SRC_DIR/$MODNAME
svn export $SRC_DIR/$MODNAME /$BF2_DIR/mods/$MODNAME
cd $BF2_DIR
python lowercaseDir.py mods/$MODNAME
fi
}
check
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
update)
update
;;
*)
echo "{start|stop|restart|status|update}"
exit 0
;;
esac
exit 0