Remove UUCP support. Note: /usr/src/gnu/libexec/uucp and /usr/src/libexec/uucpd
[dragonfly.git] / etc / rc.diskless1
1 # Copyright (c) 1999-2002  Matt Dillion.  Terms and conditions based on
2 # the FreeBSD copyright as found at the base of the source distribution.
3 #
4 # $FreeBSD: src/etc/rc.diskless1,v 1.5.2.11 2003/04/14 18:12:05 jhay Exp $
5 # $DragonFly: src/etc/Attic/rc.diskless1,v 1.2 2003/06/17 04:24:45 dillon Exp $
6 #
7 # /etc/rc.diskless1 - general BOOTP startup
8 #
9 # On entry to this script the entire system consists of a read-only root
10 # mounted via NFS.  We use the contents of /conf to create and populate
11 # memory filesystems.  The kernel has run BOOTP and configured an interface
12 # (otherwise it would not have been able to mount the NFS root!)
13 #
14 # The following directories are scanned.  Each sucessive directory overrides
15 # (is merged into) the previous one.
16 #
17 #       /conf/base              universal base
18 #       /conf/default           modified by a secondary universal base
19 #       /conf/${ipba}           modified based on the assigned broadcast IP
20 #       /conf/${ip}             modified based on the machine's assigned IP
21 #
22 # Each of these directories may contain any number of subdirectories which
23 # represent directories in / on the diskless machine.  The existance of
24 # these subdirectories causes this script to create a MEMORY FILESYSTEM for
25 # /<sub_directory_name>.  For example, if /conf/base/etc exists then a
26 # memory filesystem will be created for /etc.
27 #
28 # If a subdirectory contains the file 'diskless_remount' the contents of
29 # the file is used to remount the subdirectory prior to it being copied to
30 # the memory filesystem.  For example, if /conf/base/etc/diskless_remount
31 # contains the string 'my.server.com:/etc' then my.server.com:/etc will be
32 # mounted in place of the subdirectory.  This allows you to avoid making
33 # duplicates of system directories in /conf.
34 #
35 # If a subdirectory contains the file 'md_size', the contents of the
36 # file is used to determine the size of the memory filesystem, in 512
37 # byte sectors.  The default is 8192 (4MB).  You only have to specify an
38 # md_size if the default doesn't work for you (i.e. if it is too big or
39 # too small).  Note that in -current the default is 4096 (2MB).  For
40 # example, /conf/base/etc/md_size might contain '16384'.
41 #
42 # If /conf/<special_dir>/SUBDIR.cpio.gz exists, the file is cpio'd into
43 # the specified /SUBDIR (and a memory filesystem is created for /SUBDIR
44 # if necessary).
45 #
46 # If /conf/<special_dir>/SUBDIR.remove exists, the file contains a list
47 # of paths which are rm -rf'd relative to /SUBDIR.
48 #
49 # You will almost universally want to create a /conf/base/etc containing
50 # a diskless_remount and possibly an md_size file.  You will then almost
51 # universally want to override rc.conf, rc.local, and fstab by creating
52 # /conf/default/etc/{rc.conf,rc.local,fstab}.  Your fstab should be sure
53 # to mount a /usr... typically an NFS readonly /usr.
54 #
55 # NOTE!  rc.diskless2 will create /var, /tmp, and /dev.  Those filesystems
56 # should not be specified in /conf.  At least not yet.
57
58 # chkerr:
59 #
60 # Routine to check for error
61 #
62 #       checks error code and drops into shell on failure.
63 #       if shell exits, terminates script as well as /etc/rc.
64 #
65 chkerr() {
66     case $1 in
67     0)
68         ;;
69     *)
70         echo "$2 failed: dropping into /bin/sh"
71         /bin/sh
72         # RESUME
73         ;;
74     esac
75 }
76
77 # Create a generic memory disk
78 #
79 mount_md() {
80     /sbin/mount_mfs -s $1 -T qp120at -b 8192 -f 1024 dummy $2
81 }
82
83 # Create the memory filesystem if it has not already been created
84 #
85 create_md() {
86     if [ "x`eval echo \\$md_created_$1`" = "x" ]; then
87         if [ "x`eval echo \\$md_size_$1`" = "x" ]; then
88             md_size=8192
89         else
90             md_size=`eval echo \\$md_size_$1`
91         fi
92         mount_md $md_size /$1
93         /bin/chmod 755 /$1
94         eval md_created_$1=created
95     fi
96 }
97
98 # DEBUGGING
99 #
100 # set -v
101
102 # Figure out our interface and IP.
103 #
104 bootp_ifc=""
105 bootp_ipa=""
106 bootp_ipbca=""
107 iflist=`ifconfig -l`
108 for i in ${iflist} ; do
109     set `ifconfig ${i}`
110     while [ $# -ge 1 ] ; do
111         if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
112             bootp_ifc=${i} ; bootp_ipa=${2} ; shift
113         fi
114         if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
115             bootp_ipbca=$2; shift
116         fi
117         shift
118     done
119     if [ "${bootp_ifc}" != "" ] ; then
120         break
121     fi
122 done
123 echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
124
125 # Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca},
126 # and /conf/${bootp_ipa}.  For each subdirectory found within these 
127 # directories:
128 #
129 # - calculate memory filesystem sizes.  If the subdirectory (prior to
130 #   NFS remounting) contains the file 'md_size', the contents specified
131 #   in 512 byte sectors will be used to size the memory filesystem.  Otherwise
132 #   8192 sectors (4MB) is used.
133 #
134 # - handle NFS remounts.  If the subdirectory contains the file
135 #   diskless_remount, the contents of the file is NFS mounted over
136 #   the directory.  For example /conf/base/etc/diskless_remount
137 #   might contain 'myserver:/etc'.  NFS remounts allow you to avoid
138 #   having to dup your system directories in /conf.  Your server must
139 #   be sure to export those filesystems -alldirs, however.
140 #
141 for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
142     for j in /conf/$i/* ; do
143         # memory filesystem size specification
144         #
145         subdir=${j##*/}
146         if [ -d $j -a -f $j/md_size ]; then
147             eval md_size_$subdir=`cat $j/md_size`
148         fi
149
150         # NFS remount
151         #
152         if [ -d $j -a -f $j/diskless_remount ]; then
153             nfspt=`/bin/cat $j/diskless_remount`
154             mount_nfs $nfspt $j
155             chkerr $? "mount_nfs $nfspt $j"
156         fi
157     done
158 done
159
160 # - Create all required MFS filesystems and populate them from
161 #   our templates.  Support both a direct template and a dir.cpio.gz
162 #   archive.  Support dir.remove files containing a list of relative
163 #   paths to remove.
164 #
165 # TODO:
166 #   + find a way to assign a 'group' identifier to a machine
167 #       so we can use group-specific configurations;
168
169 for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
170     for j in /conf/$i/* ; do
171         subdir=${j##*/}
172         if [ -d $j ]; then
173             create_md $subdir
174             cp -Rp $j/* /$subdir
175         fi
176     done
177     for j in /conf/$i/*.cpio.gz ; do
178         subdir=${j%*.cpio.gz}
179         subdir=${subdir##*/}
180         if [ -f $j ]; then
181             create_md $subdir
182             echo "Loading /$subdir from cpio archive $j"
183             (cd / ; /stand/gzip -d < $j | /stand/cpio --extract -d )
184         fi
185     done
186     for j in /conf/$i/*.remove ; do
187         subdir=${j%*.remove}
188         subdir=${subdir##*/}
189         if [ -f $j ]; then
190             # doubly sure it is a memory disk before rm -rf'ing
191             create_md $subdir
192             (cd /$subdir; rm -rf `/bin/cat $j`)
193         fi
194     done
195 done
196
197 # Tell /etc/rc to run the specified script after
198 # it does its mounts but before it does anything
199 # else.
200 #
201 # This script is responsible for setting up the
202 # diskless mount environment.
203
204 diskless_mount="/etc/rc.diskless2"
205