#! /bin/sh

DRAKSYNC_MODULES_DIR=/usr/share/draksync/modules
export PYTHONPATH=$DRAKSYNC_MODULES_DIR:$PYTHONPATH

# python is unable to convert gettext translations to current locale,
# it could be easily fixed, but then python only has a small subset
# of known encodings, and for unknown ones (like "euc-jp") it crashes
# with an error message of "unknown encoding".
# so, the easier solution is to have all translations in UTF-8 and
# force use of UTF-8 here.

[ -z "$LC_ALL" ] && LC_ALL="$LC_CTYPE"
[ -z "$LC_ALL" ] && LC_ALL="$LANG"
[ -z "$LC_ALL" ] && LC_ALL="`echo $LANGUAGE | cut -d: -f1`"
[ -z "$LC_ALL" ] && LC_ALL="en_US.UTF-8"

case "$LC_ALL" in
	*UTF-8) ;;
	ja*) export LC_ALL="ja_JP.UTF-8" ;;
	ko*) export LC_ALL="ko_KR.UTF-8" ;;
	zh_TW*|zh_HK*) export LC_ALL="zh_TW.UTF-8" ;;
	zh*) export LC_ALL="zh_CN.UTF-8" ;;
	??_??|???_??) export LC_ALL="${LC_ALL}.UTF-8" ;;
	*) export LC_ALL="en_US.UTF-8" ;;
esac

# also, old gtk1 is still being used; so some languages
# cannot be properly displayed
case "$LANGUAGE" in
	ar*|bn*|fa*|he*|hi*) export LANGUAGE="C" ;
	echo -n "Sorry, but Gtk1 toolkit is unable " ;
        echo    "to properly display your language." ;
        echo    "Translations will be disabled." ;
	;;
esac

# Rerun through ssh-agent if we have ssh-agent installed but not running...
if ps uwx | grep -v grep | grep ssh-agent > /dev/null || ! which ssh-agent > /dev/null 2> /dev/null; then
	python $DRAKSYNC_MODULES_DIR/DrakSync.py
else
	ssh-agent python $DRAKSYNC_MODULES_DIR/DrakSync.py
fi
