#!/bin/sh
#
# Downloads pvpgn support files needed to run the daemon from pvpgn.berlios.de.
#
# (C) 2005 Radu Spineanu <radu@timisoara.roedu.net>
# You may freely distribute this file under the terms of the GNU General
# Public License, version 2 or later.

set -e

DBASE="https://raw.githubusercontent.com/pvpgn/pvpgn-server/master/files/"
FILES="
    ad000001.smk
    ad000002.mng
    ad000002.smk
    icons.bni
    icons_STAR.bni
    icons-WAR3.bni
    IX86ExtraWork.mpq
    IX86ver1.mpq
    newbie.save
    PMACver1.mpq
    ver-IX86-1.mpq
    XMACver1.mpq
"

usage()
{
	echo "usage: pvpgn-support-installer [options]"
	echo "options:
	        -u              -- uninstall
	        -h              -- this message"
}

# look through input arguments
until [ -z "$1" ]; do
	case $1 in
		"-u") 
			UNINSTALL=1
			;;	
		"-h") 
			usage
			exit
			;;
	    	*   ) 
			usage
			exit
			;;
	esac
	shift
done

if [ "$UNINSTALL" ]; then
	echo "Removing support files from /var/lib/pvpgn/files ..."
	for i in $FILES; do
		rm -vf /var/lib/pvpgn/files/"$i"
	done
	exit 0
fi


set -u

cd "/var/lib/pvpgn/files"
for F in ${FILES}; do
    wget --continue "${DBASE}$F"
done

exit 0
