resolv revision 124149
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 124149 2004-01-05 19:14:47Z brooks $ 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# 110case ${sendmail_enable} in 111[Nn][Oo][Nn][Ee]) 112 ;; 113*) 114 /usr/bin/newaliases 115 ;; 116esac 117 118# XXX make sure to create one dir for each printer as requested by lpd 119# 120# If we do not have a writable /tmp, create a memory 121# filesystem for /tmp. If /tmp is a symlink (e.g. to /var/tmp, 122# then it should already be writable). 123# 124if (/bin/mkdir /tmp/.diskless 2> /dev/null); then 125 rmdir /tmp/.diskless 126else 127 if [ -h /tmp ]; then 128 echo "*** /tmp is a symlink to a non-writable area!" 129 echo "dropping into shell, ^D to continue anyway." 130 /bin/sh 131 else 132 mount_md ${tmpsize:=20480} /tmp 133 chmod 01777 /tmp 134 fi 135fi 136 137if sysctl vfs.devfs.generation > /dev/null 2>&1 ; then 138 # we have DEVFS, no worries... 139 true 140elif (/bin/mkdir /dev/.diskless 2> /dev/null); then 141 # if /dev is writable assume it has already been populated 142 # via /etc/rc.d/initdiskless 143 # 144 rmdir /dev/.diskless 145else 146 (cd /; find -x dev | cpio -o -H newc) > /tmp/dev.tmp 147 mount_md 4096 /dev 512 148 (cd /; cpio -i -H newc -d < /tmp/dev.tmp) 149 rm -f /tmp/dev.tmp 150fi 151 152# generate our hostname 153# 154if [ -z "`hostname -s`" -a \ 155 "x`/bin/kenv dhcp.host-name`" != "x" ]; then 156 hostname=`/bin/kenv dhcp.host-name` 157 hostname $hostname 158 echo "Hostname is $hostname" 159fi 160 161# if the info is available via dhcp/kenv 162# build the resolv.conf 163# 164if [ ! -e /etc/resolv.conf -a \ 165 "x`/bin/kenv dhcp.domain-name-servers`" != "x" ]; then 166 echo domain `/bin/kenv dhcp.domain-name` > /etc/resolv.conf 167 168 set `/bin/kenv dhcp.domain-name-servers` 169 for ns in `IFS=','; echo $*`; do 170 echo nameserver $ns >> /etc/resolv.conf; 171 done 172fi 173 174