#!/bin/sh

knmtest () {
  if modprobe $1 >/dev/null 2>&1;then :;else rmmod $1;return 1;fi
  if ifconfig eth0 127.0.0.1;then
	ifconfig eth0 down
	return 0
  fi
  if ifconfig eth2 127.0.0.1;then
	ifconfig eth2 down
	return 0
  fi
  rmmod $1
  return 1
}

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/mnt/bin:/mnt/sbin:/mnt/usr/bin:/mnt/usr/sbin:/afs/mcc/ftp/beta/cluster
export PATH VISUAL=emacs TERM=linux HOME=/root
mount -n -t proc proc /proc
mount -n -t tmpfs tmpfs /tmp
(cd /tmp;tar xzfp /T.tgz)

disk="`fdisk -l|egrep 'Disk /dev/.da'|sed -e 's,.*Disk /dev/,,' -e 's,:.*,,'`"
if [ -z "$disk" ];then
 modprobe sd_mod
 for i in `cat /tmp/etc/scsi.try`;do
  modprobe "$i" 2>/dev/null
  disk="`fdisk -l|egrep 'Disk /dev/.da'|sed -e 's,.*Disk /dev/,,' -e 's,:.*,,'`"
  if [ -n "$disk" ];then break;fi
  rmmod "$i" 2>/dev/null
 done
fi
if `cat /proc/cmdline|grep -q network`;then
  openvt -c 2 /bin/sh
fi
while read a;do
 knmtest $a && break
done </tmp/etc/net.try
if ifconfig eth0 127.0.0.1 >/dev/null 2>&1;then
 ifconfig eth0 down
 /usr/sbin/install.net eth0
fi
if ifconfig eth0|grep -q Bcast;then :
else
 ifconfig eth0 down
 if ifconfig eth2 127.0.0.1 >/dev/null 2>&1;then
  ifconfig eth2 down
  /usr/sbin/install.net eth2
  if ifconfig eth2|grep -q Bcast;then :
  else ifconfig eth2 down
  fi
 fi
fi

for i in `cat /proc/cmdline`;do
  case "$i" in
  network )
until [ ! 0 ];do openvt -w -f -c 10 /bin/sh;done
	;;
  config|configure )
openvt -w -s -f -c 1 /usr/sbin/config
	;;
  xpsave )
openvt -w -s -f -c 1 nst xpsave
	;;
  restore|xprest )
openvt -w -s -f -c 1 nst xprest
	;;
  * )
	;;
  esac
done
cp -p /proc/mounts /etc/mtab
grep /mnt /proc/mounts && umount /mnt || mount -n -o,remount,ro /mnt
grep /boot /proc/mounts && umount /boot || mount -n -o,remount,ro /boot
echo 'Type Ctrl-Alt-Del to reboot.'
until [ ! 0 ];do sleep 10;done
