#!/bin/bash
# -*- Mode: shell-script -*-
# Copyright (C) 2003 by MandrakeSoft, Chmouel Boudjnah <chmouel@mandrakesoft.com>
# Redistribution of this file is permitted under the terms of the GNU 
# Public License (GPL)
# suspend: 5
# resume: 5

. /etc/sysconfig/suspend

ARG=$1
SOUND_MODULE_RUN=/var/run/pm/soundmodule

function suspend {
    if [[ $RESTORE_SOUND == "yes" && -n $SOUND_MODULES ]];then
	rm -f $SOUND_MODULE_RUN
	for m in $SOUND_MODULES; do
	    if lsmod |grep -q "^$m " &>/dev/null; then
		rmmod $m
		echo $m >>$SOUND_MODULE_RUN
	    fi
	done
    fi

    if [[ $USB_RESTART == "yes" && -n $USB_MODULES ]];then
	for m in $USB_MODULES; do
	    if lsmod |grep -q "^$m " &>/dev/null; then
		rmmod $m
	    fi
	done
    fi

}

function resume {
    for module in $RELOAD_MODULES; do
	rmmod $module
	modprobe $module
    done
}

case $ARG in
    suspend)
	suspend
	;;
    resume)
	resume
	;;
esac