#! /bin/sh
#
# Copyright (c) 2001 SuSE GmbH Nuernberg, Germany.  All rights reserved.
#
# /etc/init.d/boot.md
#
### BEGIN INIT INFO
# Provides:          boot.md
# Required-Start:    boot.proc 
# X-SuSE-Should-Start: boot.ibmsis boot.scsidev
# Default-Start:     B
# Default-Stop:
# Description:       start multiple devices
### END INIT INFO

. /etc/rc.status

rc_reset

case "$1" in
    start)
	#
	# maybe we use "Multiple devices".  So initialize MD.
	#
	if test -f /etc/raidtab -a -x /sbin/raid0run ; then
	    echo "Initializing Multiple Devices..."
	    /sbin/raid0run -a
	    if test -x /sbin/raidstart ; then
		/sbin/raidstart -a
	    fi
	elif test -f /etc/mdtab -a -x /sbin/mdadd ; then
	    echo "Initializing Multiple Devices..."
	    /sbin/mdadd -ar && MDADD_RETURN=0 || MDADD_RETURN=1
	    if test $MDADD_RETURN -ne 0 ; then
	        if test  -x /sbin/ckraid ; then
	            echo "Initializing Multiple Devices failed.  Trying to recover it..."
		    /sbin/mdstop -a	
	            for i in /etc/raid?.conf ; do
	                /sbin/ckraid --fix $i
	            done
	            /sbin/mdadd -ar
		    rc_status -v1 -r
	        else
	            rc_status -v1 -r
	        fi
	    fi
	fi
	if test -f /sbin/raidautorun ; then
	    /sbin/raidautorun
	fi
	
	rc_splash "early stop"
	;;
    stop)
	# maybe we use Multiple devices
	if test -f /etc/mdtab -a -x /sbin/mdstop ; then
	    echo -n "Disable Multiple Devices"
	    /sbin/mdstop -a
	    rc_status -v1 -r
	fi
	# commented out since raidstop needs an argument
	# normal shutdown is done automatically
	#if test -f /etc/raidtab -a -x /sbin/raidstop ; then
	#    echo -n "Disable Multiple Devices"
	#    /sbin/raidstop --all
	#    rc_status -v1 -r
	#fi
	;;
    status)
	rc_failed 4
	rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status}"
	exit 1
	;;
esac

rc_exit
	
