summaryrefslogtreecommitdiffstats
path: root/etc/rc.initdiskless
blob: 6b306ba3046ee1178ba7665ea9ff421ac8b6b05f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# $FreeBSD$
#
# /etc/rc.diskless1 - general BOOTP startup
#
# BOOTP has mounted / for us.  Assume a read-only mount.  We must then
# - figure out our IP by querying the interface
# - fill /conf/etc (writable) with files from /etc, and then update
#   per-machine files from /conf/*/ where * is the IP of the host,
#   the IP of the subnet, "default", or nothing.
# - mount /conf/etc over /etc so we can see the new files.
#
# WARNING: i thing you should not change /etc/rc or strange things could
# happen.
#
# The operator is in charge of setting /conf/*/etc/* things as appropriate.
# Typically rc.conf and fstab need to be changed, but possibly
# also other files such as inetd.conf etc.

# 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.
#
chkerr() {
	case $1 in
	0)
		;;
	*)
		echo "$2 failed: dropping into /bin/sh"
		/bin/sh
		# RESUME
		;;
	esac
}

# DEBUGGING
#
# set -v

# Figure out our interface and IP.
#
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}"
 
# Files in /etc are copied to /conf/etc which is writable. Then
# per-machine configs from /conf/ip.address/etc are copied onto this
# directory. First choice is using the client's IP, then the client's
# broadcast address, then a default configuration.
# This way we have some flexibility to handle clusters of machines
# on separate subnets.
#
# WARNING! null mounts cannot handle mmap, and since many programs
# use mmap (such as 'cp'), we have to copy.
#
mount_mfs -s 2048 -T qp120at dummy /conf/etc
cp -Rp /etc/* /conf/etc
chkerr $? "MFS mount on /conf/etc"

if [ -d /conf/${bootp_ipa} ] ; then
        cp -Rp /conf/${bootp_ipa}/etc/* /conf/etc
elif [ -d /conf/${bootp_ipbca} ] ; then
        cp -Rp /conf/${bootp_ipbca}/etc/* /conf/etc
else
        cp -Rp /conf/default/etc/* /conf/etc
fi

# Make the new directory available as /etc
#
mount_null /conf/etc /etc

# Tell /etc/rc to run the specified script after
# it does its mounts but before it does anything
# else.
#
# This script is responsible for setting up the
# diskless mount environment.  This can be
# overriden by /conf/ME/rc.conf.local if, for
# example, you do not want to run the standard
# system /etc/rc.diskless2

diskless_mount="/etc/rc.diskless2"
OpenPOWER on IntegriCloud