#!/bin/sh
#
# se30acfg - SE/30 Carrera040.  At every startup /etc/sysinitrc runs
# "autoconfig -a": when the cards the kernel found in the slot scan don't match its
# drivers (an Ethernet card it hasn't got ae6 for), autoconfig builds a new /unix and
# restarts with it.  That kernel has no SE/30 Carrera040 patches and wouldn't start.
# se30patch -A made autoconfig run this in place of /etc/macquery just before the
# restart: patch the new kernel with the settings the old one had (saved by
# sysinitrc in /etc/se30patch.boot before autoconfig ran), then show autoconfig's
# message as before.
#
PATH=/bin:/usr/bin:/etc
K=${SE30ACFG_UNIX:-/unix}
C=/etc/se30patch.boot

if [ -x /etc/se30patch ]; then
    opts=""
    if [ -f $C ]; then
	mode=`sed -n 's/.*Carrera040 mode: \([a-z0-9]*\) .*/\1/p' $C`
	nid=`sed -n 's/.*nuCF card as SCSI ID \([0-6]\).*/\1/p' $C`
	nunused=`sed -n 's/.*nuCF card unused.*/yes/p' $C`
	scan=`sed -n 's/.*SCSI bus scan at startup: //p' $C`
	slots=`sed -n 's/.*cards in occupied slots in the slot scan: //p' $C`
	case "$mode" in 030|med|fast) opts="$opts -m $mode" ;; *) opts="$opts -m med" ;; esac
	[ -n "$nid" ] && opts="$opts -i $nid"
	[ -n "$nunused" ] && opts="$opts -i -1"
	case "$scan" in on|off) opts="$opts -s $scan" ;; esac
	case "$slots" in no) opts="$opts -l off" ;; *) opts="$opts -l on" ;; esac
    else
	opts="-m med -l on"
    fi
    echo ""
    echo "se30acfg: autoconfig built a new $K; applying the SE/30 Carrera040 patches"
    echo "se30acfg: /etc/se30patch$opts $K"
    /etc/se30patch $opts $K
    if [ $? != 0 ]; then
	echo "se30acfg: *** COULD NOT PATCH $K: it won't start on this Macintosh. ***"
    fi
    sync
fi
[ -n "$SE30ACFG_UNIX" ] && exit 0
exec /etc/macquery "$@"
