2002-07-18 05:00:17 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2000-10-08 19:20:36 +00:00
|
|
|
# Copyright (c) 1999 Matt Dillion
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
# SUCH DAMAGE.
|
|
|
|
#
|
1999-09-13 15:44:20 +00:00
|
|
|
# $FreeBSD$
|
2000-10-08 19:20:36 +00:00
|
|
|
#
|
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
# PROVIDE: initdiskless
|
|
|
|
# KEYWORD: FreeBSD
|
|
|
|
|
|
|
|
dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
|
|
|
|
[ ${dlv:=0} -eq 0 ] && exit 0
|
|
|
|
|
1999-02-09 17:17:18 +00:00
|
|
|
#
|
2000-01-06 18:17:38 +00:00
|
|
|
# BOOTP has mounted / for us. Assume a read-only mount. We must then
|
|
|
|
# - figure out our IP by querying the interface
|
2001-04-20 23:10:11 +00:00
|
|
|
# - mount /etc as an MFS
|
2001-12-26 17:00:55 +00:00
|
|
|
# - populate /etc from /conf/default version
|
2001-04-20 23:10:11 +00:00
|
|
|
# - override files in /etc with files from /conf/*/etc where
|
|
|
|
# '*' is default, netmask of client, ip-address of client
|
1999-02-09 17:17:18 +00:00
|
|
|
#
|
2000-01-06 18:17:38 +00:00
|
|
|
# The operator is in charge of setting /conf/*/etc/* things as appropriate.
|
2002-01-17 00:08:44 +00:00
|
|
|
# Typically rc.conf and fstab need to be changed, but possibly also other
|
|
|
|
# files such as inetd.conf etc.
|
1999-02-09 17:17:18 +00:00
|
|
|
|
|
|
|
# chkerr:
|
|
|
|
#
|
|
|
|
# Routine to check for error
|
|
|
|
#
|
|
|
|
# checks error code and drops into shell on failure.
|
|
|
|
# if shell exits, terminates script as well as /etc/rc.
|
1999-09-13 15:44:20 +00:00
|
|
|
#
|
2002-07-18 05:00:17 +00:00
|
|
|
chkerr()
|
|
|
|
{
|
1999-09-13 15:44:20 +00:00
|
|
|
case $1 in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
*)
|
1999-02-09 17:17:18 +00:00
|
|
|
echo "$2 failed: dropping into /bin/sh"
|
|
|
|
/bin/sh
|
|
|
|
# RESUME
|
1999-09-13 15:44:20 +00:00
|
|
|
;;
|
|
|
|
esac
|
1999-02-09 17:17:18 +00:00
|
|
|
}
|
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
mount_md()
|
|
|
|
{
|
2002-09-22 09:48:02 +00:00
|
|
|
/sbin/mdmfs -i 4096 -s $1 -M md$3 $2
|
2001-04-25 05:46:40 +00:00
|
|
|
}
|
|
|
|
|
1999-02-09 17:17:18 +00:00
|
|
|
# DEBUGGING
|
|
|
|
#
|
2000-01-06 18:17:38 +00:00
|
|
|
# set -v
|
1999-02-09 17:17:18 +00:00
|
|
|
|
1999-09-13 15:44:20 +00:00
|
|
|
# Figure out our interface and IP.
|
1999-02-09 17:17:18 +00:00
|
|
|
#
|
2000-01-06 18:17:38 +00:00
|
|
|
bootp_ifc=""
|
|
|
|
bootp_ipa=""
|
|
|
|
bootp_ipbca=""
|
|
|
|
iflist=`ifconfig -l`
|
|
|
|
for i in ${iflist} ; do
|
|
|
|
set `ifconfig ${i}`
|
|
|
|
while [ $# -ge 1 ] ; do
|
|
|
|
if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
|
|
|
|
bootp_ifc=${i} ; bootp_ipa=${2} ; shift
|
|
|
|
fi
|
|
|
|
if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
|
|
|
|
bootp_ipbca=$2; shift
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
if [ "${bootp_ifc}" != "" ] ; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
|
1999-02-09 17:17:18 +00:00
|
|
|
|
2002-04-22 21:42:18 +00:00
|
|
|
if [ -z "`hostname -s`" ]; then
|
2002-07-18 05:00:17 +00:00
|
|
|
hostname=`kenv dhcp.host-name`
|
|
|
|
hostname $hostname
|
2002-04-22 21:42:18 +00:00
|
|
|
echo "Hostname is $hostname"
|
|
|
|
fi
|
|
|
|
|
2002-02-22 19:05:22 +00:00
|
|
|
if [ -d /conf/default/etc ]; then
|
|
|
|
mount_md 4096 /etc 0
|
|
|
|
chkerr $? "MFS mount on /etc"
|
|
|
|
/bin/chmod 755 /etc
|
2001-04-03 00:24:01 +00:00
|
|
|
|
2002-02-22 19:05:22 +00:00
|
|
|
/bin/cp -Rp /conf/default/etc/* /etc
|
|
|
|
chkerr $? "cp /conf/default/etc to /etc MFS"
|
|
|
|
fi
|
2001-04-20 23:10:11 +00:00
|
|
|
|
2002-01-17 00:10:28 +00:00
|
|
|
# Allow for override files to replace files in /etc. Use /conf/*/etc to find
|
|
|
|
# the override files. First choice is default files that # always override,
|
|
|
|
# then files that from the directory that matches the client's broadcast
|
|
|
|
# address, finally followed by overrides that match the client's IP address.
|
1999-02-09 17:17:18 +00:00
|
|
|
#
|
2002-01-17 00:10:28 +00:00
|
|
|
# This way we have some flexibility to handle clusters of machines on
|
|
|
|
# separate subnets.
|
2001-04-20 23:10:11 +00:00
|
|
|
|
2002-04-22 21:42:18 +00:00
|
|
|
for i in ${bootp_ipbca} ${bootp_ipa} ${hostname} ; do
|
2001-04-20 23:10:11 +00:00
|
|
|
if [ -d /conf/${i}/etc ]; then
|
|
|
|
cp -Rp /conf/${i}/etc/* /etc
|
|
|
|
fi
|
|
|
|
done
|
1999-02-09 17:17:18 +00:00
|
|
|
|
2002-04-22 21:42:18 +00:00
|
|
|
#
|
|
|
|
# if the info is available via dhcp/kenv
|
|
|
|
# build the resolv.conf
|
|
|
|
#
|
|
|
|
if [ ! -e /etc/resolv.conf ]; then
|
2002-07-18 05:00:17 +00:00
|
|
|
echo domain `kenv dhcp.domain-name` > /etc/resolv.conf
|
2002-04-22 21:42:18 +00:00
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
set `kenv dhcp.domain-name-servers`
|
|
|
|
for ns in `IFS=','; echo $*`; do
|
|
|
|
echo nameserver $ns >> /etc/resolv.conf;
|
|
|
|
done
|
2002-04-22 21:42:18 +00:00
|
|
|
fi
|