#!/usr/bin/env bash

# Run script to update your server to the current version (use argument "openjk" if using OpenJK engine).
# Customize variables below as necessary. 

# directory where base and MBII folder reside (AKA GameData on clients)
basedir="/home/mb2/jamp"
# server startup script in $basedir
startscript="start.sh"
# server stop script in $basedir
stopscript="stop.sh"

read -p "Stop all servers and update MBII?" -n 1 -r
echo    # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
    # stop servers
    sh $basedir/$stopscript

    # download newer files
    cd $basedir/MBII
    wget --execute="robots = off" -r -l 1 -nd -nH -N -A pk3,so,cfg,txt,mb2c,mbcr https://update.moviebattles.org/files/MBII/
    if [ "$1" == "openjk" ]
    then
        mv -f jampgamei386.so jampgamei386.jamp.so
        cp jampgamei386.nopp.so jampgamei386.so
    fi

    # start servers
    sh $basedir/$startscript
    
    echo "***** Done! *****"
else
	echo "Aborting"
fi