#!/bin/bash
#   Updates both l10n branches
#   Copyright (C) 2005 Greek KDE l10n Team.
#   Written by Spiros Georgaras <sngeorgaras@otenet.gr>, 2005.
#
#   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, 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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
#

function help(){
	echo "A tool to update both trunk and stable branch"
	echo "of the local copy of the KDE SVN repository"
	echo
	echo -n "Usage:	$(basename "$0") <options>"
	echo "Options are:"
	echo "  -n  execute no sanity checks"
	echo "  -h  display this screen and exit"
	echo
}

function	findBranch(){
if `isInStable "$PWD"`;then
echo -n "stable "
else
	echo -n "trunk "
fi
}

function	findFolder(){
local check=`svn info | grep URL |grep templates`
if test -z "$check" ;then
	echo messages
else
	echo templates
fi
}

#
# Script starts here
#
# Copy this to all scripts
if [ -e "$HOME"/.l10n.conf ];then
	. "$HOME"/.l10n.conf
	if [ -z "$installFolder" ];then
		echo `basename "$0"`"> Error: parameter installFolder not set..."
		echo `basename "$0"`"> Please edit ~/.l10n.conf"
		echo
		exit 1
	fi
	if [ ! -d "$installFolder" ];then
		echo `basename "$0"`"> Error: parameter \"installFolder\""
		echo `basename "$0"`"> Value: \"$installFolder\""
		echo  `basename "$0"`" Does not exist or is not a folder"	
		echo `basename "$0"`"> Please edit ~/.l10n.conf"
		echo
		exit 1
	fi
	if [ ! -r "$installFolder" ];then
		echo `basename "$0"`"> Error: parameter \"installFolder\""
		echo `basename "$0"`"> Value: \"$installFolder\""
		echo `basename "$0"`"  No read permission to this folder"
		echo `basename "$0"`"> Please edit ~/.l10n.conf"
		echo
		exit 1
	fi
	. "$installFolder"/l10n-common
	parceConfig
	errorDetected=$?
else
	echo `basename "$0"`"> Error: ~/.l10n.conf - Not found"
	echo "A sample l10n.conf file can be found at
ftp://ftp.i18n.kde.org/teams/el/scripts"
	echo
	exit 1
fi
# End copy
#
while getopts ":vhn" Option
do
	case $Option in
	h) # show help
		help
		exit 0;;
	n) # run no checks
		runCheck=false;;
	v) # show version
		showVersion 'S. Georgaras <sngeorgaras@otenet.gr>'
		echo
		exit 0
	esac
done
shift $(($OPTIND - 1))
for k in "$POT_TRUNK" "$PO_TRUNK" "$POT_STABLE" "$PO_STABLE"
do
	if `isInStable "$k"`;then
		if [ "$usingStable" != "true" ];then continue;fi
	else
		if [ "$usingTrunk" != "true" ];then continue;fi
	fi
	cd "$k"
	echo -n ">>>  l10n-up:  Updating "
	findBranch
	findFolder
	svn up
done
