#!/bin/bash

# rc.sd 1.00 2001/08/08 22:40:44 (Hideki Hayami)
#
# Tags for init configuration tools
#
# processname: sdmgr
# pidfile: /var/run/sdmgr.pid
# control script: /etc/sdcontrol
# description: currently SD support is only for memory devices \
#              which is used as block device.

# Source function library.
. /etc/rc.d/init.d/functions

KERNEL=`/bin/uname -r`
SDMGR_MODULE=sdcardmgr
MDIR=/lib/modules/$KERNEL/kernel/drivers/sdcard/
MODS_LOAD="sd_linux sd_core sd_memory sdmmc_linux sdlink sd_pxahci"
MODS_UNLOAD="sd_pxahci sdlink sdmmc_linux sd_memory sd_core sd_linux" 

usage()
{
    echo "Usage: $0 {start|start_save|stop|status|restart|reload}"
}



if [ $# -lt 1 ] ; then usage ; exit 0 ; fi
action=$1

case "$action" in

start)
    for f in $MODS_LOAD; do insmod $f ; done
    ;;
start_save)
    msg -n "Start SD services:"
    if [ -s /var/run/sdmgr.pid ] && \
        kill -0 `cat /var/run/sdmgr.pid` 2>/dev/null ; then
	msg -n " running."
    else
	if [ -f /sbin/sdmgr ]; then
	    daemon --survive=5 /sbin/sdmgr
	    touch /var/lock/subsys/sd
	fi
    fi
    msg
    sleep 1
    ;;

stop)
    msg -n "Stop SD services:"
    if [ -f /var/lock/subsys/sd ]; then
	killproc /sbin/sdmgr
	rm -f /var/lock/subsys/sd
    fi
    msg
    for f in $MODS_UNLOAD; do rmmod $f ; done
    ;;

status)
    ;;

restart|reload)
    $0 stop
    $0 start_save
    ;;

*)
    usage
    ;;

esac

exit 0
