#!/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

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
}

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
