#!/bin/sh
#
#
# chkconfig: 345 20 05
# description: This startup script sets auth to krb5 and activates cifs homes

WITHOUT_RC_COMPAT=1


# Source function library.
. /etc/init.d/functions
. alterator-datetime-functions
. shell-config


RETVAL=0

start()
{
	auth=/usr/lib/alterator/backend3/auth
	if grep -q krb5 /proc/cmdline ; then
		echo "setting auth to krb5"
		date=$(nc ldap 13)
		[ -n "$date" ] && date -s "$date"
		domain=$(host ldap | cut -d' ' -f 1| cut -d. -f 2-100)
		$auth &>/dev/null <<EOF
_message:begin
action:write
auth_type:krb5
domain:$domain
_message:end
EOF
net_shares=/usr/lib/alterator/backend3/net-shares
		$net_shares &>/dev/null <<EOF
_message:begin
action:write
homes:#t
_message:end
EOF
[ -f /etc/X11/gdm/custom.conf ] && subst 's/AutomaticLoginEnable/#AutomaticLoginEnable/' /etc/X11/gdm/custom.conf ||:
[ -f /etc/lightdm/lightdm.conf ] && subst 's/autologin-/#autologin-/' /etc/lightdm/lightdm.conf ||: 


		ip -o addr | grep '[0-9]: e[nt]' | cut -d' ' -f2 | xargs -i ip link set dev {} multicast on
	fi

	# Set time zone from kernel command line
	ZONE=$(cat /proc/cmdline | sed -n 's/^.* tz=\([^ ]*\).*/\1/gp')
	if [ -z "$ZONE" ];then
		# Set in_language for read_zone
		in_language=$(sed -n 's/^.* lang=\([^ ]*\).*/\1/gp' /proc/cmdline)
		ZONE=$(read_zone)
	fi
	if [ -n "$ZONE" ];then
		shell_config_set /etc/sysconfig/clock ZONE "'$ZONE'"
		rm -f /etc/localtime
        	/etc/rc.d/init.d/clock start
	fi
}

stop()
{
	true
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	*)
		msg_usage "${0##*/} {start|stop}"
		RETVAL=1
esac

exit $RETVAL
