rc.initdiskless revision 55520
151231Ssheldonh# $FreeBSD: head/etc/rc.initdiskless 55520 2000-01-06 18:17:38Z luigi $
251231Ssheldonh#
355520Sluigi# /etc/rc.diskless1 - general BOOTP startup
443803Sdillon#
555520Sluigi# BOOTP has mounted / for us.  Assume a read-only mount.  We must then
655520Sluigi# - figure out our IP by querying the interface
755520Sluigi# - fill /conf/etc (writable) with files from /etc, and then update
855520Sluigi#   per-machine files from /conf/*/ where * is the IP of the host,
955520Sluigi#   the IP of the subnet, "default", or nothing.
1055520Sluigi# - mount /conf/etc over /etc so we can see the new files.
1143803Sdillon#
1255520Sluigi# WARNING: i thing you should not change /etc/rc or strange things could
1355520Sluigi# happen.
1443803Sdillon#
1555520Sluigi# The operator is in charge of setting /conf/*/etc/* things as appropriate.
1655520Sluigi# Typically rc.conf and fstab need to be changed, but possibly
1755520Sluigi# also other files such as inetd.conf etc.
1843803Sdillon
1943803Sdillon# chkerr:
2043803Sdillon#
2143803Sdillon# Routine to check for error
2243803Sdillon#
2343803Sdillon#	checks error code and drops into shell on failure.
2443803Sdillon#	if shell exits, terminates script as well as /etc/rc.
2551231Ssheldonh#
2643803Sdillonchkerr() {
2751231Ssheldonh	case $1 in
2851231Ssheldonh	0)
2951231Ssheldonh		;;
3051231Ssheldonh	*)
3143803Sdillon		echo "$2 failed: dropping into /bin/sh"
3243803Sdillon		/bin/sh
3343803Sdillon		# RESUME
3451231Ssheldonh		;;
3551231Ssheldonh	esac
3643803Sdillon}
3743803Sdillon
3843803Sdillon# DEBUGGING
3943803Sdillon#
4055520Sluigi# set -v
4143803Sdillon
4251231Ssheldonh# Figure out our interface and IP.
4343803Sdillon#
4455520Sluigibootp_ifc=""
4555520Sluigibootp_ipa=""
4655520Sluigibootp_ipbca=""
4755520Sluigiiflist=`ifconfig -l`
4855520Sluigifor i in ${iflist} ; do
4955520Sluigi    set `ifconfig ${i}`
5055520Sluigi    while [ $# -ge 1 ] ; do
5155520Sluigi        if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
5255520Sluigi            bootp_ifc=${i} ; bootp_ipa=${2} ; shift
5355520Sluigi        fi
5455520Sluigi        if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
5555520Sluigi            bootp_ipbca=$2; shift
5655520Sluigi        fi
5755520Sluigi        shift
5855520Sluigi    done
5955520Sluigi    if [ "${bootp_ifc}" != "" ] ; then
6055520Sluigi        break
6155520Sluigi    fi
6255520Sluigidone
6355520Sluigiecho "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
6455520Sluigi 
6555520Sluigi# Files in /etc are copied to /conf/etc which is writable. Then
6655520Sluigi# per-machine configs from /conf/ip.address/etc are copied onto this
6755520Sluigi# directory. First choice is using the client's IP, then the client's
6855520Sluigi# broadcast address, then a default configuration.
6955520Sluigi# This way we have some flexibility to handle clusters of machines
7055520Sluigi# on separate subnets.
7143803Sdillon#
7243803Sdillon# WARNING! null mounts cannot handle mmap, and since many programs
7343803Sdillon# use mmap (such as 'cp'), we have to copy.
7451231Ssheldonh#
7555520Sluigimount_mfs -s 2048 -T qp120at dummy /conf/etc
7655520Sluigicp -Rp /etc/* /conf/etc
7755520Sluigichkerr $? "MFS mount on /conf/etc"
7843803Sdillon
7955520Sluigiif [ -d /conf/${bootp_ipa} ] ; then
8055520Sluigi        cp -Rp /conf/${bootp_ipa}/etc/* /conf/etc
8155520Sluigielif [ -d /conf/${bootp_ipbca} ] ; then
8255520Sluigi        cp -Rp /conf/${bootp_ipbca}/etc/* /conf/etc
8355520Sluigielse
8455520Sluigi        cp -Rp /conf/default/etc/* /conf/etc
8555520Sluigifi
8643803Sdillon
8755520Sluigi# Make the new directory available as /etc
8843803Sdillon#
8955520Sluigimount_null /conf/etc /etc
9043803Sdillon
9143803Sdillon# Tell /etc/rc to run the specified script after
9243803Sdillon# it does its mounts but before it does anything
9343803Sdillon# else.
9443803Sdillon#
9543803Sdillon# This script is responsible for setting up the
9651231Ssheldonh# diskless mount environment.  This can be
9743803Sdillon# overriden by /conf/ME/rc.conf.local if, for
9843803Sdillon# example, you do not want to run the standard
9943803Sdillon# system /etc/rc.diskless2
10043803Sdillon
10143803Sdillondiskless_mount="/etc/rc.diskless2"
102