#!/bin/bash

FILES=

#some files should always be included - they'll end up getting created by gedit if they save changes
FILES="$FILES /etc/groovix/groovix.conf"

for T in pacauth.conf cmon.conf pacrez.conf pactime.conf gxprintconfirm.conf gxprintconfirm-gui.conf vncmon.conf screensaver.conf vncmon.conf ; do
	if [ -e /etc/groovix/$T ] ; then
		FILES="$FILES /etc/groovix/$T"
	fi
done


BADCONF=2
while [ $BADCONF -ne 0 ]  ; do
	gedit $FILES
	SYNTAX_CHECK=`bash -n /etc/groovix/groovix.conf 2>&1 `
	if [ $? -ne 0 ] ; then
		zenity --question --ok-label="Edit Again" --title "ERROR! There is problem with groovix.conf" --text "Please try to correct the following problems:\n$SYNTAX_CHECK"
		if [ $? -eq 0 ] ; then
			#if they hit OK, we'll try again"
			BADCONF=1
		else
			# they hit cancel, so just let them through
			BADCONF=0
		fi
	else
		BADCONF=0
	fi
done


#todo: ask if they'd like to update and reboot now to apply changes

zenity --question --title 'Update and Reboot Now?' --text 'Hit REBOOT to update and reboot this computer to make sure all configuration changes have been applied' --ok-label='REBOOT' --cancel-label='Cancel'
if [ $? -eq 0 ] ; then
	#how to start something here that won't get killed when gui exits? 

	#make sure the session doesn't close on us due to timeouts	
	groovix-cancel-timeouts
	
	xterm -fullscreen -fg black -bg white -e 'groovix-net-control; echo rebooting in 10 seconds ; sleep 10'
	shutdown -r now
fi

