rc.initdiskless revision 66830
1# Copyright (c) 1999  Matt Dillion
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8#    notice, this list of conditions and the following disclaimer.
9# 2. Redistributions in binary form must reproduce the above copyright
10#    notice, this list of conditions and the following disclaimer in the
11#    documentation and/or other materials provided with the distribution.
12#
13# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23# SUCH DAMAGE.
24#
25# $FreeBSD: head/etc/rc.initdiskless 66830 2000-10-08 19:20:36Z obrien $
26#
27
28#
29# /etc/rc.diskless1 - general BOOTP startup
30#
31# BOOTP has mounted / for us.  Assume a read-only mount.  We must then
32# - figure out our IP by querying the interface
33# - fill /conf/etc (writable) with files from /etc, and then update
34#   per-machine files from /conf/*/ where * is the IP of the host,
35#   the IP of the subnet, "default", or nothing.
36# - mount /conf/etc over /etc so we can see the new files.
37#
38# WARNING: i thing you should not change /etc/rc or strange things could
39# happen.
40#
41# The operator is in charge of setting /conf/*/etc/* things as appropriate.
42# Typically rc.conf and fstab need to be changed, but possibly
43# also other files such as inetd.conf etc.
44
45# chkerr:
46#
47# Routine to check for error
48#
49#	checks error code and drops into shell on failure.
50#	if shell exits, terminates script as well as /etc/rc.
51#
52chkerr() {
53	case $1 in
54	0)
55		;;
56	*)
57		echo "$2 failed: dropping into /bin/sh"
58		/bin/sh
59		# RESUME
60		;;
61	esac
62}
63
64# DEBUGGING
65#
66# set -v
67
68# Figure out our interface and IP.
69#
70bootp_ifc=""
71bootp_ipa=""
72bootp_ipbca=""
73iflist=`ifconfig -l`
74for i in ${iflist} ; do
75    set `ifconfig ${i}`
76    while [ $# -ge 1 ] ; do
77        if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
78            bootp_ifc=${i} ; bootp_ipa=${2} ; shift
79        fi
80        if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
81            bootp_ipbca=$2; shift
82        fi
83        shift
84    done
85    if [ "${bootp_ifc}" != "" ] ; then
86        break
87    fi
88done
89echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
90 
91# Files in /etc are copied to /conf/etc which is writable. Then
92# per-machine configs from /conf/ip.address/etc are copied onto this
93# directory. First choice is using the client's IP, then the client's
94# broadcast address, then a default configuration.
95# This way we have some flexibility to handle clusters of machines
96# on separate subnets.
97#
98# WARNING! null mounts cannot handle mmap, and since many programs
99# use mmap (such as 'cp'), we have to copy.
100#
101mount_mfs -s 2048 -T qp120at dummy /conf/etc
102cp -Rp /etc/* /conf/etc
103chkerr $? "MFS mount on /conf/etc"
104
105if [ -d /conf/${bootp_ipa} ] ; then
106        cp -Rp /conf/${bootp_ipa}/etc/* /conf/etc
107elif [ -d /conf/${bootp_ipbca} ] ; then
108        cp -Rp /conf/${bootp_ipbca}/etc/* /conf/etc
109else
110        cp -Rp /conf/default/etc/* /conf/etc
111fi
112
113# Make the new directory available as /etc
114#
115mount_null /conf/etc /etc
116
117# Tell /etc/rc to run the specified script after
118# it does its mounts but before it does anything
119# else.
120#
121# This script is responsible for setting up the
122# diskless mount environment.  This can be
123# overriden by /conf/ME/rc.conf.local if, for
124# example, you do not want to run the standard
125# system /etc/rc.diskless2
126
127diskless_mount="/etc/rc.diskless2"
128