#!/bin/sh

. /etc/profile
# Start all init scripts in /etc/init.d
# executing them in numerical order.
#

waitrc()
{
	if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ];then
		return 1
	fi
	cnt=$1
	while [ $cnt -lt $2 ]; do
		/bin/ps | grep "$3" | grep -v grep >/dev/null
		if [ $? = 0 ]; then
			sleep 2
		else
			cnt=$2
		fi
		cnt=$(($cnt+1))
	done
	return 0
}
w=0
for i in /etc/rcS.d/S[0-5]?* ;do
     # Ignore dangling symlinks (if any).
     #[ ! -f "$i" ] && continue

     case "$i" in
	*.sh)
	    # Source shell script for speed.
	    (
		trap - INT QUIT TSTP
		set start
		. $i
	    )
	    ;;
	*)
	    # No sh extension, so fork subprocess.
	    $i start
	    ;;
    esac
done

for i in /etc/rcS.d/S[6-8]?* ;do
	[ -f "$i" ] || continue
	case "$i" in
	*.sh)
	    # Source shell script for speed.
	    (
		trap - INT QUIT TSTP
		set start
		. $i
	    )
	    ;;
	*httpd)
	    $i start
	    ;;
	*Qthttpd)
	    $i start
	    ;;
	*cupsd)
	    $i start
	    ;;
	*smb)
	    $i start
	    ;;
	*ftp)
	    $i start
	    ;;
	*nfs)
	    $i start
	    ;;
	*recycled)
	    $i start
	    ;;
	*nvrd)
	    $i start
	    ;;
	*)
	    # No sh extension, so fork subprocess.
	    $i start &
	    ;;
    esac
done
waitrc $w 40 "/etc/rcS.d/S"

for i in /etc/rcS.d/S9?* ;do
	[ -f "$i" ] || continue
	case "$i" in
	*.sh)
	    # Source shell script for speed.
	    (
		trap - INT QUIT TSTP
		set start
		. $i
	    )
	    ;;
	*init_nas)
	    # No sh extension, so fork subprocess.
		waitrc $w 10 "/etc/rcS.d/S9"
	    $i start
	    ;;
	*)
	    # No sh extension, so fork subprocess.
	    $i start &
	    ;;
    esac
done
waitrc $w 20 "/etc/rcS.d/S9"

#for QPKG
for i in /etc/rcS.d/QS??* ;do
     # Ignore dangling symlinks (if any).
     [ -f "$i" ] || continue
     case "$i" in
	*.sh)
	    # Source shell script for speed.
	    (
		trap - INT QUIT TSTP
		set start
		. $i
	    )
	    ;;
	*)
	    # No sh extension, so fork subprocess.
	    $i start
	    ;;
    esac
done
