#!/bin/sh
# -*- Mode: shell-script -*-

[ -e /etc/sysconfig/apmd ] && . /etc/sysconfig/apmd

if [ "$RESTORESOUND" = "yes" -o "$RESTORESOUNDPROGS" = "yes" ]; then
    # Get the sound modules back up...
    # soundon is from the commercial OSS drivers, don't worry
    # if you don't have it.
    [ -x /usr/bin/soundon ] && /usr/bin/soundon
    [ -x /usr/sbin/soundon ] && /usr/sbin/soundon
    [ -x /usr/local/bin/soundon ] && /usr/local/bin/soundon
    [ -x /usr/local/sbin/soundon ] && /usr/local/sbin/soundon
    for m in `cat /var/run/apm-soundmodules`; do
	modprobe $m
    done
    rm -f /var/run/apm-soundmodules
fi
if [ "$RESTORESOUNDPROGS" = "yes" ]; then
		# at least we can restart the programs using sound on
		# the right display
		# If you're using the trial version of OSS, you want to add
		#sleep 5
		# here to wait for the trial text
    for n in `cat /var/run/apm-soundprogs`; do
	SOUNDPROG=`echo $n|cut '-d|' -f1`
	SOUNDPID=`echo $n|cut '-d|' -f2`
	SOUNDUSER=`echo $n|cut '-d|' -f3`
	SOUNDDISPLAY=`echo $n|cut '-d|' -f4`
	su --shell="/bin/bash" - "$SOUNDUSER" -c "source /etc/profile;[ -f ~/.bashrc ] && source ~/.bashrc;[ -f ~/.bash_profile ] && source ~/.bash_profile;export DISPLAY="$SOUNDDISPLAY";$SOUNDPROG &"
	logger "apmscript: Program $SOUNDPROG started as user $SOUNDUSER on display $SOUNDDISPLAY."
    done
    rm -f /var/run/apm-soundprogs
fi
