#!/bin/sh
# $Id: livecd,v 1.3 2004/06/30 16:58:38 havner Exp $

# livecd	Autodetection for livecd
#
# chkconfig:	345 94 06
#
# description:	DHCP and mixer
#
# author:	Lukasz Pawelczyk <havner@pld-linux.org> 2004

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

if [ -f /etc/sysconfig/livecd ]; then
	. /etc/sysconfig/livecd
fi

case "$1" in
	start|restart|reload|force-reload)
	CHARS="LiveCD: "

	for I in `cat /etc/modprobe.conf | grep "^alias eth" | awk '{print $2}'`; do
		modprobe $I > /dev/null 2>&1
	done

	for I in $DHCP_INTERFACES; do
		if [ "`dmesg | grep $I`" != "" ] || [ "`cat /etc/modprobe.conf | grep $I`" != "" ]; then
			show "Backgrounding DHCP for $I"
			busy
			dhcpcd "$I" &
			ok
		fi
	done

	show "Loading mixer settings for detected audio devices"
	busy
	COUNT=0
	for I in `grep snd-card-[0-9] /etc/modprobe.conf | awk '{print $3}'`; do
		aumix -d /dev/mixer${COUNT} -L > /dev/null 2>&1
		let $((++COUNT))
	done
	ok

	touch /var/lock/subsys/livecd
	;;
	stop)
	CHARS="LiveCD: "
	if [ "`cat /proc/mounts | grep \/home\/users`" != "" ]; then
		for I in `lsof /home/users | grep -v COMMAND | awk '{print $2}' | sort | uniq`; do
			kill -15 $I > /dev/null 2>&1
			kill -9 $I > /dev/null 2>&1
		done
		run_cmd "Unmounting home filesystem" umount /home/users 2>/dev/null
	fi
	rm -f /var/lock/subsys/livecd
	;;
	status)
	;;
	*)
	msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
	exit 3
esac

exit 0
