#!/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: 40
# resume: 15
#

. /etc/sysconfig/suspend

ARG=$1

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

function suspend {
    if [[ $PCMCIA_BIOS_BUG == "yes" ]];then
	/sbin/cardctl eject
    else
	/sbin/cardctl suspend
    fi

    if [[ $PCMCIA_WAIT == "yes" ]];then
	stabs=
	for s in /var/run/stab /var/lib/pcmcia/stab; do
	    [ -f $s ] && stabs="$stabs $s"
	done
	if [ -z $stabs ]; then
	    logger "No pcmcia stab file, not waiting for PCMCIA device removal"
	    return;
	fi
	while grep '^Socket' $stabs 2>/dev/null | grep -qv 'empty$'; do
	    logger "Waiting for pcmcia-device to be removed..."
	    sleep 10
	done
    fi
}

function resume {
    if [ $PCMCIA_BIOS_BUG == "yes" ]; then
	/sbin/cardctl insert
    else
	/sbin/cardctl resume
    fi
}

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