#!/bin/sh

if [ -e /etc/italc/keys/public/ ]; then

	ITALC_STUDENT_GROUP=`stat -c %G /etc/italc/keys/public/`

	MSG="
iTALC Client Applet

You are not allowed to launch iTALC's client applet.

Ask your system administrator to add your account to
POSIX group \"$ITALC_STUDENT_GROUP\".

Exiting...
"

else
	MSG="
iTALC Client Applet

The iTALC setup has not been complete, yet. Read

  /usr/share/doc/italc-client/README.setup.gz

or execute

  sudo dpkg-reconfigure italc-client

Exiting...
"
fi

# if -autostart is given as first cmdline option, we
# will not display any GUI error messages...
if [ "x$1" = "x-autostart" ]; then
	shift
	AUTOSTART="true"
fi

if test -x /etc/italc/keys/public; then
	/usr/lib/italc/ica "$@" &
else

	if [ -z "$DISPLAY" ]; then
		# No Display set...
		echo
		echo "iTALC Client Applet"
		echo "-------------------"
		echo "No \$DISPLAY environment variable set. Cannot launch iTALC Client Applet."
		echo
		echo "Exiting..."
		echo
	elif type kdialog 1>/dev/null && [ "x$AUTOSTART" != "xtrue" ]; then
		kdialog --title "iTALC Client" --error "$MSG"
	elif type zenity 1>/dev/null && [ "x$AUTOSTART" != "xtrue" ]; then
		zenity --title "iTALC Client" --error --text "$MSG"
	else
		echo
		echo "$MSG"
		echo
	fi

fi
