#!/bin/sh
#
# livecd-install-wmaker		Tweak wmaker for the livecd-install button
#
# chkconfig: 345 05 95
# description:	aimed at livecd use

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

LOCKFILE=/var/lock/subsys/livecd-install-wmaker
RETVAL=0

prefix="/etc/X11/WindowMaker"
script="/usr/share/WindowMaker/autostart.d/style.sh"

start()
{
	echo -n "Configuring WindowMaker: "

	sed -i -f - "$prefix/WMWindowAttributes" << EOF
/^{/a\  Logo.ALTLinux = {Icon="/usr/share/design/current/icons/large/altlinux.png"; };
EOF
	# operate on the Dock section, append another one to Applications
	sed -i -f - "$prefix/WMState" << EOF
/^  Dock = {$/,/^  Clip = {$/ s/      }$/&,\\
      {\\
        Name = Logo.ALTLinux;\\
        Lock = Yes;\\
        AutoLaunch = No;\\
        Command = "livecd-install";\\
        DropCommand = "livecd-install %d";\\
        Position = "0,2";\\
        Forced = No;\\
        BuggyApplication = No;\\
      }/
EOF
	# generate the script to set more compatible default style
	cat > "$script" << EOF
#!/bin/sh
setstyle /usr/share/WindowMaker/Styles/Traditional.style
sleep 1	# racey...
exec setstyle /usr/share/WindowMaker/Styles/Traditional.style
EOF
	chmod +x "$script"

	RETVAL=$?
	[ $RETVAL = 0 ] && echo_success || echo_failure
	return $RETVAL
}

# See how we were called.
case "$1" in
	start|restart|reload)
		start
		;;
	stop)
		;;
	condstop)
		;;
	condrestart|condreload)
		if [ -e "$LOCKFILE" ]; then
			start
		fi
		;;
	status)
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
