#!/bin/bash
# $Revision: 1.48 $, $Date: 2004/03/11 18:39:43 $
# GPL, mimooh@inf.sgsp.edu.pl

. /etc/pldconf/ustawienia || exit

if [ -z "$PLDCONF_FUNCS_LOADED" ]; then
	# needs to be done just once per pldconf session
	. /usr/share/pldconf/pldconf_functions && export PLDCONF_FUNCS_LOADED=yes || exit 
fi

gui_func()
{
	if [ `id -nu` = root ]; then
		eval `dml -t "    _p_l_d_c_o_n_f $PLDCONF_VERSION"<< EOF
		<meta title="Menu administratora" width=28> 
		<br>
		<menu id=res_menu res=1 height=15> 
		<item id=ustawienia> Ustawienia pldconf
		<item id=poldek> Dodaj/Usu programy
		<item id=users> Konta
		<item id=X> rodowisko graficzne
		<item id=net> Sie 
		<item id=filesystems> Dyski/Systemy plikw
		<item id=boot> Uruchamianie systemu
		<item id=devices> Urzdzenia
		<item id=inne> Inne 
		<item id=sysinfo> Informacje o systemie
		<item id=pld_install> Instalacja PLD
		<item id=dml_help> Pomoc
		<item id=template> Wzorzec moduw
		<item id=autorzy> Autorzy
		<item id=dml_exit> Wyjcie
		</menu>
EOF`

		case $res_menu in 
			ustawienia)
			exec ${DATA_DIR}/ustawienia.sh
			;;
			poldek)
			exec ${DATA_DIR}/poldek.sh
			;;
			users)
			exec ${DATA_DIR}/user.pl
			;;
			X)
			exec ${DATA_DIR}/X/X_menu.sh
			;;
			net)
			exec ${DATA_DIR}/NET/net_menu.sh 
			;;
			filesystems)
			exec ${DATA_DIR}/filesystems.sh
			;;
			boot)
			exec ${DATA_DIR}/BOOT/boot_menu.sh
			;;
			devices)
			exec ${DATA_DIR}/DEVICES/device_menu.sh
			;;
			inne)
			exec ${DATA_DIR}/inne.sh
			;;
			sysinfo)
			exec ${DATA_DIR}/SYSINFO/sysinfo_menu.sh
			;;
			pld_install)
			exec ${DATA_DIR}/install_pld.sh
			;;
			dml_help)
			dml_help=yes
			dml_help_check ${DATA_DIR}/POMOC/README_pomoc.txt
			;;
			template)
			exec ${DATA_DIR}/template.sh
			;;
			autorzy)
			exec ${DATA_DIR}/autorzy.sh
			;;
		esac
	else 
		exec ${DATA_DIR}/menu_user.sh
	fi
}

print_help() {
	clear
	cat << EOF
Dozwolone opcje:
-X   -Konfiguracja X;
-d   -Konfiguracja desktopu;
-H   -Konfiguracja urzdze;
-i   -Dodaj/Usu programy;
-n   -Konfiguracja sieci;
-b   -Konfiguracja menedera startu;
-D   -Instalacja PLD;
-M   -Poczenie z internetem GUI;
-m   -Poczenie z internetem [operator|help];
-I   -Inne;
-v   -Wersja;
-h   -Opis opcji;

Wiele z tych opcji ma wasne podopcje, np. 
pldconf -d -h

EOF
}

getopts "XdHmMinbDIwfvh" opt && shift
case $opt in
	X) exec ${DATA_DIR}/X/X.sh "$@";;
	d) exec ${DATA_DIR}/X/desktop.sh "$@";;
	H) exec ${DATA_DIR}/DEVICES/device_menu.sh "$@";;
	M) exec ${DATA_DIR}/NET/wvdial_connect.sh;;
	m) exec ${DATA_DIR}/NET/wvdial_connect.sh "$@";;
	i) exec ${DATA_DIR}/poldek.sh "$@";;
	n) exec ${DATA_DIR}/NET/net_menu.sh "$@";;
	b) exec ${DATA_DIR}/BOOT/boot_manager.pl "$@";;
	D) exec ${DATA_DIR}/install_pld.sh "$@";;
	I) exec ${DATA_DIR}/inne.sh "$@";;
	w) exec ${DATA_DIR}/template.sh "$@";;
	f) exec ${DATA_DIR}/filesystems.sh "$@";;
	h) print_help;;
	v) echo pldconf $PLDCONF_VERSION;;
	?) gui_func;;
esac

