#!/bin/sh
# Version 00.00.01
#  Systemlog Permanent setzen / ruecksetzen
#
# help Linux Shell
# http://www.linux-praxis.de/linux1/shell2_5.html

#---------------
setSyslogPerm()
{
	echo "enable permanent log"
	unlink /var/log
	mkdir /home/cti/syslog.perm
	ln -s /home/cti/syslog.perm /var/log
}
#---------------
setSyslogDefault()
{
	echo "disable permanent log"
	unlink /var/log
	ln -s /tmp /var/log
}
#---------------
SetSyslog()
{
	case "$1" in
		"enable")
		setSyslogPerm
		;;
		"disable")
		setSyslogDefault
		;;
	*)
	exit 1
	esac
}
#---------------
SetWeeklyReboot()
{
	STUNDE="$1"
	MINUTE="$2"
	DOW="$3"

	if [ "$STUNDE" = "disable" ]; then
		echo -en "disable weekly reboot"
		#	systemlink 	entfernen
		unlink /etc/cron.weekly/cron_weekly_reboot
	else
	# Note Einstellig, wenn < 10 !
		if [ "$STUNDE" -gt 23 ] && [ "$STUNDE" -lt 0 ]; then
			echo "Eingabefehler Stunde: <$STUNDE>"
			exit 1
		fi
		if [ "$MINUTE" -gt 59 ] && [ "$MINUTE" -lt 0 ]; then
			echo "Eingabefehler Minuten <$MINUTE>"
			exit 1
		fi
		if [ "$DOW" -gt 7 ] && [ "$DOW" -lt 0 ]; then
			echo "Eingabefehler Tag der Woche: <$DOW>"
			exit 1
		fi
	fi
# kopiere Vorlage & fuege Zeile ein /etc/cron.d/system
#--> mm hh * *  dd
	cp /home/cti/conf/system.crond /etc/cron.d/system
	echo -en "Setze auf [$STUNDE] : [$MINUTE] - [$DOW]"
	if [ "$STUNDE" = "disable" ]; then
		echo "@monthly        ID=sys-monthly  /bin/run-parts /etc/cron.monthly" >> /etc/cron.d/system
	else
		echo "$MINUTE $STUNDE * * $DOW      ID=sys-weekly   /bin/run-parts /etc/cron.weekly" >> /etc/cron.d/system
		echo "@monthly        ID=sys-monthly  /bin/run-parts /etc/cron.monthly" >> /etc/cron.d/system
		#	systemlink 	nach /etc/cron.weekly/
		ln -sf /home/cti/shellscripts/cron_weekly_reboot  /etc/cron.weekly/cron_weekly_reboot

	fi
	# restart crond
	/etc/init.d/S90dcron restart
}
#====================
# main case ...
#====================
case "$1" in
	set_syslog)
	SetSyslog "$2"
	;;
	set_weekly_reboot)
	SetWeeklyReboot  "$2" "$3" "$4"
	;;
	*)
	echo "Usage: $0 { set_syslog | set_weekly_reboot } "
	exit 1
esac
exit $?

exit $?

