#!/bin/bash 
#
# manage -- manager script for Wescamp development.
#

# Only these things need to change per-campaign
abbrev=DM
campaign=Delfadors_Memoirs
wescamp=~/svn/wescamp-i18n/${campaign}-po/${campaign}
camppath=data/campaigns/${campaign}
client=~/svn/wesnoth/utils/campaigns_client.py

do=""
fc=""
if [ "$1" = "-n" ]
then
	shift
	do=echo
	fc=-n
fi

if [ -L ~/svn/wesnoth/$camppath ]
then
	dcamp=linked
elif [ -d ~/svn/wesnoth/$camppath ]
then
	ucamp=copied
else
	dcamp="not present"
fi

if [ -L ~/.wesnoth/$camppath ]
then
	ucamp=linked
elif [ -d ~/.wesnoth/$camppath ]
then
	ucamp=copied
else
	ucamp="not present"
fi

case $1 in
upload)
   echo "Uploading ${abbrev} to campaign server";
   $do $client -p 1.3.x -c ~/svn/wescamp-i18n -u $campaign;
   ;;
remove)
   case $ucamp in
   linked)
       echo "Unlinking ${abbrev} from user directory";
       $do rm ~/.wesnoth/$camppath;;
   copied)
       echo "Removing ${abbrev} from user directory";
       $do rm -fr ~/.wesnoth/$camppath;;
   *)
       echo "${abbrev} not installed in user directory."
   esac
   ;;
relink)
   $0 $fc remove
   echo "Relinking ${abbrev} to data directory";
   $do ln -s $wescamp ~/svn/wesnoth/$camppath;
   ;;
delink)
   echo "Delinking ${abbrev} from data directory";
   $do rm ~/svn/wesnoth/$camppath;
   ;;
nuke)
   echo -n "Password: "
   read password
   $do $client -r $campaign -P "$password";
   ;;
paths)
   echo "camp=$campaign"
   echo "wescamp=$wescamp"
   ;;
*)
    echo "${abbrev} $ucamp in user directory."
    echo "${abbrev} $dcamp in data directory."
    ;;
esac
