Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[games.git] / etc / rc.diskless2
1 # Copyright (c) 1999  Matt Dillon
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: src/etc/rc.diskless2,v 1.5.2.14 2002/12/23 17:39:06 dillon Exp $
26 # $DragonFly: src/etc/Attic/rc.diskless2,v 1.2 2003/06/17 04:24:45 dillon Exp $
27 #
28
29 #
30 # rc.diskless2
31 #
32
33 # Provide a function for normalizing the mounting of memory
34 # filesystems.  This should allow the rest of the code here to remain
35 # as close as possible between 5-current and 4-stable.
36 #   $1 = size
37 #   $2 = mount point
38 #   $3 = (optional) bytes-per-inode
39 mount_md() {
40         if [ -n "$3" ]; then
41                 bpi="-i $3"
42         fi
43         /sbin/mount_mfs -s $1 -T qp120at -b 8192 -f 1024 $bpi dummy $2
44 }
45
46 # If there is a global system configuration file, suck it in.
47 #
48 if [ -r /etc/defaults/rc.conf ]; then
49         . /etc/defaults/rc.conf
50         source_rc_confs
51 elif [ -r /etc/rc.conf ]; then
52         . /etc/rc.conf
53 fi
54
55 # If we do not have a writable /var, create a memory
56 # filesystem for /var.  We don't have /usr yet so
57 # use mkdir instead of touch to test.  We want mount
58 # to record its mounts so we have to make sure /var/db
59 # exists before doing the mount -a.
60 #
61 if (/bin/mkdir /var/.diskless 2> /dev/null); then
62         rmdir /var/.diskless
63 else
64         echo "+++ mfs_mount of /var"
65         mount_md ${varsize:=65536} /var
66 fi
67
68 if [ ! -d /var/db ]; then
69         mkdir /var/db
70 fi
71
72 # Now we need the rest of our mounts, particularly /usr.
73 #
74 mount -a
75
76 # Populate /var
77 #
78 echo "+++ populate /var using /etc/mtree/BSD.var.dist"
79 /usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var > /dev/null
80
81 case ${sendmail_enable} in
82 [Nn][Oo][Nn][Ee])
83         ;;
84 *)
85         /usr/sbin/mtree -deU -f /etc/mtree/BSD.sendmail.dist -p / > /dev/null
86         ;;
87 esac
88
89 echo "+++ create log files based on the contents of /etc/newsyslog.conf"
90 LOGFILES=`/usr/bin/awk '$1 != "#" { printf "%s ", $1 } ' /etc/newsyslog.conf`
91 if [ -n "$LOGFILES" ]; then
92         /usr/bin/touch $LOGFILES
93 fi
94
95 echo "+++ create lastlog"
96 /usr/bin/touch /var/log/lastlog
97
98 # Make sure our aliases database is uptodate, the aliases may have
99 # been overriden in /conf.
100 #
101 /usr/bin/newaliases
102
103 #
104 # XXX make sure to create one dir for each printer as requested by lpd
105 #
106 # If we do not have a writable /tmp, create a memory
107 # filesystem for /tmp.  If /tmp is a symlink (e.g. to /var/tmp,
108 # then it should already be writable).
109 #
110 if (/bin/mkdir /tmp/.diskless 2> /dev/null); then
111         rmdir /tmp/.diskless
112 else
113         if [ -h /tmp ]; then
114                 echo "*** /tmp is a symlink to a non-writable area!"
115                 echo "dropping into shell, ^D to continue anyway."
116                 /bin/sh
117         else
118                 mount_md ${tmpsize:=20480} /tmp
119                 chmod 01777 /tmp
120         fi
121 fi
122
123 # If /dev has already been created in rc.diskless1 it will be writable
124 # and we do nothing.  If /dev is not writable then we have to dup it as
125 # a memory filesystem.
126 #
127 # note: /conf/dev.cpio.gz is no longer valid.  Use /conf/base/dev.cpio.gz
128 # instead and it will be handled in rc.diskless1
129
130 if (/bin/mkdir /dev/.diskless 2> /dev/null); then
131         rmdir /dev/.diskless
132 else
133         (cd /; find -x dev | cpio --create -H newc | gzip) > /tmp/dev.cpio.gz
134         mount_md 4096 /dev 512
135         (cd /; gzip -dc /tmp/dev.cpio.gz | cpio --extract -H newc -d )
136         rm -f /tmp/dev.cpio.gz
137 fi
138