resolv revision 108191
1#!/bin/sh 2# 3# Copyright (c) 1999 Matt Dillon 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# 27# $FreeBSD: head/etc/rc.d/resolv 108191 2002-12-22 22:18:41Z dillon $ 28# 29 30# PROVIDE: diskless 31# REQUIRE: initdiskless rcconf mountcritlocal 32# BEFORE: addswap random 33# KEYWORD: FreeBSD 34 35dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 36[ ${dlv:=0} -eq 0 ] && exit 0 37 38name="diskless2" 39 40# Provide a function for normalizing the mounting of memory 41# filesystems. This should allow the rest of the code here to remain 42# as close as possible between 5-current and 4-stable. 43# $1 = size 44# $2 = mount point 45# $3 = (optional) bytes-per-inode 46mount_md() { 47 if [ -n "$3" ]; then 48 bpi="-i $3" 49 fi 50 /sbin/mdmfs $bpi -s $1 -M md $2 51} 52 53# If there is a global system configuration file, suck it in. 54# 55if [ -r /etc/rc.subr ]; then 56 . /etc/rc.subr 57 load_rc_config $name 58elif [ -r /etc/defaults/rc.conf ]; then 59 . /etc/defaults/rc.conf 60 source_rc_confs 61elif [ -r /etc/rc.conf ]; then 62 . /etc/rc.conf 63fi 64 65# If we do not have a writable /var, create a memory 66# filesystem for /var. We don't have /usr yet so 67# use mkdir instead of touch to test. We want mount 68# to record its mounts so we have to make sure /var/db 69# exists before doing the mount -a. 70# 71if (/bin/mkdir /var/.diskless 2> /dev/null); then 72 rmdir /var/.diskless 73else 74 echo "+++ mount_md of /var" 75 mount_md ${varsize:=32m} /var 76fi 77 78if [ ! -d /var/db ]; then 79 mkdir /var/db 80fi 81 82# Now we need the rest of our mounts, particularly /usr 83# 84mount -a # chown and chgrp are in /usr 85 86# Populate /var 87# 88echo "+++ populate /var using /etc/mtree/BSD.var.dist" 89/usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var > /dev/null 90case ${sendmail_enable} in 91[Nn][Oo][Nn][Ee]) 92 ;; 93*) 94 /usr/sbin/mtree -deU -f /etc/mtree/BSD.sendmail.dist -p / > /dev/null 95 ;; 96esac 97 98echo "+++ create log files based on the contents of /etc/newsyslog.conf" 99LOGFILES=`/usr/bin/awk '$1 != "#" { printf "%s ", $1 } ' /etc/newsyslog.conf` 100if [ -n "$LOGFILES" ]; then 101 /usr/bin/touch $LOGFILES 102fi 103 104echo "+++ create lastlog" 105/usr/bin/touch /var/log/lastlog 106 107# Make sure our aliases database is uptodate, the aliases may have 108# been overriden in /conf. 109# 110/usr/bin/newaliases 111 112# XXX make sure to create one dir for each printer as requested by lpd 113# 114# If we do not have a writable /tmp, create a memory 115# filesystem for /tmp. If /tmp is a symlink (e.g. to /var/tmp, 116# then it should already be writable). 117# 118if (/bin/mkdir /tmp/.diskless 2> /dev/null); then 119 rmdir /tmp/.diskless 120else 121 if [ -h /tmp ]; then 122 echo "*** /tmp is a symlink to a non-writable area!" 123 echo "dropping into shell, ^D to continue anyway." 124 /bin/sh 125 else 126 mount_md ${tmpsize:=20480} /tmp 127 chmod 01777 /tmp 128 fi 129fi 130 131if sysctl vfs.devfs.generation > /dev/null 2>&1 ; then 132 # we have DEVFS, no worries... 133 true 134elif (/bin/mkdir /dev/.diskless 2> /dev/null); then 135 # if /dev is writable assume it has already been populated 136 # via rc.diskless1 137 # 138 rmdir /dev/.diskless 139else 140 (cd /; find -x dev | cpio -o -H newc) > /tmp/dev.tmp 141 mount_md 4096 /dev 512 142 (cd /; cpio -i -H newc -d < /tmp/dev.tmp) 143 rm -f /tmp/dev.tmp 144fi 145 146# generate our hostname 147# 148if [ -z "`hostname -s`" ]; then 149 hostname=`/usr/bin/kenv dhcp.host-name` 150 hostname $hostname 151 echo "Hostname is $hostname" 152fi 153 154# if the info is available via dhcp/kenv 155# build the resolv.conf 156# 157if [ ! -e /etc/resolv.conf ]; then 158 echo domain `/usr/bin/kenv dhcp.domain-name` > /etc/resolv.conf 159 160 set `/usr/bin/kenv dhcp.domain-name-servers` 161 for ns in `IFS=','; echo $*`; do 162 echo nameserver $ns >> /etc/resolv.conf; 163 done 164fi 165 166