#!/bin/sh
#
# X11 ROM apm wrapper
# http://www.pdaXrom.org
#

pre_suspend() {
    # test -e /etc/rc.d/init.d/pcmcia && /etc/rc.d/init.d/pcmcia stop >/dev/null 2>/dev/null
    cardctl eject
    rmmod -a
    rmmod -a
    echo -n Suspending ...
}

post_suspend() {
    # test -e /etc/rc.d/init.d/pcmcia && /etc/rc.d/init.d/pcmcia start >/dev/null 2>/dev/null
    # sleep 1
    cardctl insert > /dev/null 2>&1
    echo ... Resumed
}

APM=/usr/bin/apm.x

if [ "$1" = "--suspend" -o "$1" = "-s" -o "$1" = "--su" ]; then
    pre_suspend
    $APM --suspend
    post_suspend
else
    $APM $@
fi
