#!/bin/bash
# Plan launch script (0.1) by Eskild Hustvedt <eskild@mandriva.org>
# This script will autodetect language and copy the holiday file the first time
# plan is run. This script is licensed under the GNU General Public License
# and comes with ABSOLUTELY NO WARRANTY
if [ ! -e $HOME/.plan.dir ]; then
	echo "Creating configuration files..."
	mkdir -p $HOME/.plan.dir
	# Software language
	case $LANG in
		nb_NO | nn_NO ) PLANLANG="Norwegian";;
		de_DE ) PLANLANG="German" ;;
		nl_NL ) PLANLANG="Dutch" ;;
		fr_FR ) PLANLANG="French" ;;
		it_IT ) PLANLANG="Italian" ;;
		es_ES ) PLANLANG="Spanish" ;;
		* ) PLANLANG="English" ;;
	esac
	# Holiday file
	case $LC_ADDRESS in
		nb_NO | nn_NO | nb | nn | no_NO ) HOLIDAY="norway" ;;
		en_US | us ) HOLIDAY="us" ;;
		en_UK | uk ) HOLIDAY="uk" ;;
		sv | sv_SE ) HOLIDAY="swedish";;
		fr | fr_FR ) HOLIDAY="french" ;;
		it | it_IT ) HOLIDAY="italy" ;;
		el_GR ) HOLIDAY="greek" ;;
		cs_CZ ) HOLIDAY="czech" ;;
		da_DK ) HOLIDAY="denmark" ;;
		nl_NL ) HOLIDAY="dutch" ;;
		fi_FI ) HOLIDAY="finnish" ;;
		de_DE ) HOLIDAY="german" ;;
		hu_HU ) HOLIDAY="hungary" ;;
		ja_JP ) HOLIDAY="japan" ;;
		pt_PT ) HOLIDAY="portugal" ;;
		sk_SK ) HOLIDAY="slovak" ;;
		es_ES ) HOLIDAY="spain" ;;
		* ) HOLIDAY="NULL";;
	esac
	# Write language
	cat << END > $HOME/.plan.dir/dayplan
plan
L	$PLANLANG
END
	# Copy holiday file
	if [ "$HOLIDAY" != "NULL" ] && [ -e /usr/lib/plan/holidays/holiday_$HOLIDAY ]; then
		cat /usr/lib/plan/holidays/holiday_$HOLIDAY > $HOME/.plan.dir/holiday
	fi
fi
/usr/lib/plan/plan $*
