]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.diskless1
This commit was generated by cvs2svn to compensate for changes in r107937,
[FreeBSD/FreeBSD.git] / etc / rc.diskless1
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$
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 # - mount /etc as an MFS
34 # - populate /etc from /conf/default version
35 # - override files in /etc with files from /conf/*/etc where
36 #   '*' is default, netmask of client, ip-address of client
37 #
38 # The operator is in charge of setting /conf/*/etc/* things as appropriate.
39 # Typically rc.conf and fstab need to be changed, but possibly also other
40 # files such as inetd.conf etc.
41
42 # chkerr:
43 #
44 # Routine to check for error
45 #
46 #       checks error code and drops into shell on failure.
47 #       if shell exits, terminates script as well as /etc/rc.
48 #
49 chkerr() {
50         case $1 in
51         0)
52                 ;;
53         *)
54                 echo "$2 failed: dropping into /bin/sh"
55                 /bin/sh
56                 # RESUME
57                 ;;
58         esac
59 }
60
61 mount_md() {
62         /sbin/mdconfig -a -t malloc -s $1 -u $3
63         /sbin/disklabel -r -w md$3 auto
64         /sbin/newfs -i 4096 /dev/md$3c
65         /sbin/mount /dev/md$3c $2
66 }
67
68 # DEBUGGING
69 #
70 # set -v
71
72 # Figure out our interface and IP.
73 #
74 bootp_ifc=""
75 bootp_ipa=""
76 bootp_ipbca=""
77 iflist=`ifconfig -l`
78 for i in ${iflist} ; do
79     set `ifconfig ${i}`
80     while [ $# -ge 1 ] ; do
81         if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
82             bootp_ifc=${i} ; bootp_ipa=${2} ; shift
83         fi
84         if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
85             bootp_ipbca=$2; shift
86         fi
87         shift
88     done
89     if [ "${bootp_ifc}" != "" ] ; then
90         break
91     fi
92 done
93 echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
94
95 if [ -z "`hostname -s`" ]; then
96         hostname=`kenv dhcp.host-name`
97         hostname $hostname
98         echo "Hostname is $hostname"
99 fi
100
101 if [ -d /conf/default/etc ]; then
102         mount_md 4096 /etc 0
103         chkerr $? "MFS mount on /etc"
104         /bin/chmod 755 /etc
105
106         /bin/cp -Rp /conf/default/etc/* /etc
107         chkerr $? "cp /conf/default/etc to /etc MFS"
108 fi
109
110 # Allow for override files to replace files in /etc.  Use /conf/*/etc to find
111 # the override files.  First choice is default files that # always override,
112 # then files that from the directory that matches the client's broadcast
113 # address, finally followed by overrides that match the client's IP address.
114 #
115 # This way we have some flexibility to handle clusters of machines on
116 # separate subnets.
117
118 for i in ${bootp_ipbca} ${bootp_ipa} ${hostname} ; do
119         if [ -d /conf/${i}/etc ]; then
120                 cp -Rp /conf/${i}/etc/* /etc
121         fi
122 done
123
124 #
125 # if the info is available via dhcp/kenv
126 # build the resolv.conf
127 #
128 if [ ! -e /etc/resolv.conf ]; then
129         echo domain `kenv dhcp.domain-name` > /etc/resolv.conf
130
131         set `kenv dhcp.domain-name-servers`
132         for ns in `IFS=','; echo $*`; do
133                 echo nameserver $ns >> /etc/resolv.conf;
134         done
135 fi
136
137 # Tell /etc/rc to run the specified script after it does its mounts but
138 # before it does anything else.
139 #
140 # This script is responsible for setting up the diskless mount environment.
141 # This can be overriden by /conf/ME/rc.conf.local if, for example, you do not
142 # want to run the standard system /etc/rc.diskless2
143
144 diskless_mount="/etc/rc.diskless2"