#!/bin/sh

/bin/busybox test ! -e /proc/cpuinfo && /bin/busybox mount -t proc none /proc
/bin/busybox test ! -e /sys/kernel && /bin/busybox mount -t sysfs none /sys
/bin/busybox test ! -e /bin/cp && /bin/busybox --install -s

progress() {
  if test -f /proc/splash; then
    echo "show $1" > /proc/splash
  fi
}

count=0
for script in /etc/init.d/*; do
  grep -q -e "^# runlevels:.*$1" $script && count=$(($count+1));
done

pos=47000
step=$(((65535-$pos)/$count))

RET=0

for script in /etc/init.d/*; do
  if grep -q -e "^# runlevels:.*$1" $script; then
    pos=$(($pos+$step))
    progress $pos
    /bin/sh $script
    S_RET=$?
    test $S_RET -ge $RET && RET=$S_RET
  fi
done

exit $RET
