#!/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)
#
# resume: 15
# suspend: 70
#

. /etc/sysconfig/suspend

ARG=$1

if [[ $USB_RESTART != "yes" ]];then
    exit;
fi

function suspend {
    modules=`/sbin/modprobe -c | egrep -s "^(probeall|alias|install)( |\t)+usb-interface( |\t)+" | sed "s/^.*usb-interface//;s/\/sbin\/modprobe//g;s/;//g;s/\/bin\/true//;s/||//"`
    umount /proc/bus/usb >/dev/null 2>&1
    for module in $modules; do
	modprobe -r $module >/dev/null 2>&1
    done
}

function resume {
    service usb start
    [[ -f /sbin/hotplug ]] && /sbin/hotplug usb
}

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