rc revision 84332
1139823Simp#!/bin/sh
221259Swollman#
321259Swollman# Copyright (c) 2000  The FreeBSD Project
421259Swollman# All rights reserved.
521259Swollman#
621259Swollman# Redistribution and use in source and binary forms, with or without
721259Swollman# modification, are permitted provided that the following conditions
821259Swollman# are met:
921259Swollman# 1. Redistributions of source code must retain the above copyright
1021259Swollman#    notice, this list of conditions and the following disclaimer.
1121259Swollman# 2. Redistributions in binary form must reproduce the above copyright
1221259Swollman#    notice, this list of conditions and the following disclaimer in the
1321259Swollman#    documentation and/or other materials provided with the distribution.
1421259Swollman#
1521259Swollman# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1621259Swollman# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1721259Swollman# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1821259Swollman# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1921259Swollman# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2021259Swollman# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2121259Swollman# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2221259Swollman# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2321259Swollman# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2421259Swollman# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2521259Swollman# SUCH DAMAGE.
2621259Swollman#
2721259Swollman#	@(#)rc	5.27 (Berkeley) 6/5/91
2821259Swollman# $FreeBSD: head/etc/rc 84332 2001-10-01 22:52:32Z obrien $
2921259Swollman#
3050477Speter
3121259Swollman# System startup script run by init on autoboot
3221259Swollman# or after single-user.
3321259Swollman# Output and error are redirected to console by init,
3421259Swollman# and the console is the controlling terminal.
3521259Swollman
3621259Swollman# Note that almost all of the user-configurable behavior is no longer in
3721259Swollman# this file, but rather in /etc/defaults/rc.conf.  Please check that file
3821259Swollman# first before contemplating any changes here.  If you do need to change
3921259Swollman# this file for some reason, we would like to know about it.
4021259Swollman
4121259Swollmanstty status '^T'
4221259Swollman
4321259Swollman# Set shell to ignore SIGINT (2), but not children;
4421259Swollman# shell catches SIGQUIT (3) and returns to single user after fsck.
4521259Swollman#
4621259Swollmantrap : 2
4721259Swollmantrap : 3	# shouldn't be needed
4821259Swollman
4921259Swollmanbootmode=$1
5021259Swollman
51108533SschweikhHOME=/
5221259SwollmanPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
5321259Swollmanexport HOME PATH
5421259Swollman
5521259Swollman# BOOTP diskless boot.  We have to run the rc file early in order to
56108533Sschweikh# retarget various config files.
5721259Swollman#
5821259Swollmanif [ -r /etc/rc.diskless1 ]; then
5921259Swollman	dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
6021259Swollman	if [ ${dlv:=0} != 0 ]; then
6121259Swollman		. /etc/rc.diskless1
6221259Swollman	fi
6321259Swollmanfi
6421259Swollman
6521259Swollman# If there is a global system configuration file, suck it in.
6683366Sjulian#
6721259Swollmanif [ -r /etc/defaults/rc.conf ]; then
6885074Sru	. /etc/defaults/rc.conf
6921259Swollman	source_rc_confs
7021259Swollmanelif [ -r /etc/rc.conf ]; then
71142215Sglebius	. /etc/rc.conf
72155051Sglebiusfi
7321259Swollman
7421259Swollmanfeed_dev_random() {
7521259Swollman	if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then
7621259Swollman#		echo "Using ${1} as an entropy file"
7769224Sjlemon		cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null
7869152Sjlemon	fi
79126264Smlaier}
8069224Sjlemon
8174914Sjhbchkdepend() {
8274914Sjhb	svc=$1
8383130Sjlemon	svc_var=$2
84132712Srwatson	dep=$3
8569152Sjlemon	dep_var=$4
86121816Sbrooks
87121816Sbrooks	eval svc_val=\${$svc_var}
88130416Smlaier	eval dep_val=\${$dep_var}
89130416Smlaier
9060938Sjake	case ${svc_val} in
9160938Sjake	[Yy][Ee][Ss])
9260938Sjake		case ${dep_val} in
9372084Sphk		[Yy][Ee][Ss])
94159781Smlaier		    ;;
9521259Swollman		*)
9621259Swollman		    eval ${dep_var}="YES"
9721259Swollman		    echo "DEPENDENCY NOTE: ${dep} will be enabled" \
9821259Swollman			 "to support ${svc}"
9921259Swollman		    ;;
10021259Swollman		esac
10121259Swollman		;;
10221259Swollman	esac
10321259Swollman}
10421259Swollman
10569152Sjlemonchkdepend amd amd_enable        portmap portmap_enable
10621259Swollmanchkdepend NFS nfs_server_enable portmap portmap_enable
10721259Swollmanchkdepend NIS nis_server_enable portmap portmap_enable
10821259Swollmanchkdepend NIS nis_client_enable portmap portmap_enable
10921259Swollman
11021259Swollman# Enable harvesting of entropy via devices.  The sooner this happens the
11121259Swollman# better so that we can take advantage of the boot process.
11221259Swollman#
11384380Smjacobecho -n 'Entropy harvesting:'
11421259Swollman
11521259Swollmancase ${harvest_interrupt} in
116147256Sbrooks[Nn][Oo])
11760938Sjake	;;
118121816Sbrooks*)
119121816Sbrooks	if [ -w /dev/random ]; then
120121816Sbrooks		/sbin/sysctl -w kern.random.sys.harvest.interrupt=1 >/dev/null
12121259Swollman		echo -n ' interrupts'
122128291Sluigi	fi
123128291Sluigi	;;
124128315Sluigiesac
125128315Sluigi
126128315Sluigicase ${harvest_ethernet} in
127128315Sluigi[Nn][Oo])
128128291Sluigi	;;
129128315Sluigi*)
130152315Sru	if [ -w /dev/random ]; then
131128291Sluigi		/sbin/sysctl -w kern.random.sys.harvest.ethernet=1 >/dev/null
132133741Sjmg		echo -n ' ethernet'
13383130Sjlemon	fi
134142901Sglebius	;;
13521259Swollmanesac
13621259Swollman
13721259Swollmancase ${harvest_p_to_p} in
138155051Sglebius[Nn][Oo])
139102052Ssobomax	;;
140162070Sandre*)
141162070Sandre	if [ -w /dev/random ]; then
14221259Swollman	/sbin/sysctl -w kern.random.sys.harvest.point_to_point=1 >/dev/null
14321259Swollman		echo -n ' point_to_point'
14421259Swollman	fi
14521404Swollman	;;
14621404Swollmanesac
14721259Swollman
14821259Swollmanecho '.'
14992725Salfred
15092725Salfred# First pass at reseeding /dev/random.
151106931Ssam#
152106931Ssamcase ${entropy_file} in
15321259Swollman[Nn][Oo] | '')
15492725Salfred	;;
15521259Swollman*)
15692725Salfred	if [ -w /dev/random ]; then
15721259Swollman		feed_dev_random "${entropy_file}"
15892725Salfred	fi
15921259Swollman	;;
16092725Salfredesac
16121404Swollman
16292725Salfred# XXX temporary until we can get the entropy
163152315Sru# harvesting rate up
164137062Srwatson# Entropy below is not great,
165137062Srwatson# but better than nothing.
166148265Srwatson( ps -efauxww; sysctl -a; date; df -ib; dmesg; ps -efauxww; ) \
167137062Srwatson    | dd of=/dev/random bs=8k 2>/dev/null
168130416Smlaiercat /bin/ls | dd of=/dev/random bs=8k 2>/dev/null
169123220Simp
170127828Sluigi# Configure ccd devices.
171146986Sthompsa#
172146986Sthompsaif [ -r /etc/ccd.conf ]; then
173127828Sluigi	ccdconfig -C
174127828Sluigifi
175122524Srwatson
176121161Sumecase ${start_vinum} in
177127828Sluigi[Yy][Ee][Ss])
178127828Sluigi	vinum start
179121161Sume	;;
180121470Sumeesac
181121470Sume
182132712Srwatsonswapon -a
183145320Sglebius
184148640Srwatson# Last chance to do things before potentially waiting for
185152209Sthompsa# operator to do fsck related tasks
186159781Smlaierif [ -r /etc/rc.early ]; then
187159781Smlaier	. /etc/rc.early
188159781Smlaierfi
18921259Swollman
19069152Sjlemoncase ${bootmode} in
19192725Salfredautoboot)
19221259Swollman	echo 'Automatic boot in progress...'
193128376Sluigi	case ${background_fsck} in
194128376Sluigi	[Yy][Ee][Ss])
195128376Sluigi		fsck -F -p
196128376Sluigi		;;
19721259Swollman	*)
19821259Swollman		fsck -p
19921259Swollman		;;
20021259Swollman	esac
20121259Swollman	case $? in
20221259Swollman	0)
203128871Sandre		;;
20421259Swollman	2)
20558698Sjlemon		exit 1
20621259Swollman		;;
20721259Swollman	4)
20821259Swollman		reboot
20921259Swollman		echo 'Reboot failed... help!'
21021259Swollman		exit 1
21121259Swollman		;;
21221259Swollman	8)
21321259Swollman		case ${fsck_y_enable} in
21421259Swollman		[Yy][Ee][Ss])
21521259Swollman			echo 'File system preen failed, trying fsck -y . . .'
21621259Swollman			fsck -y
21721259Swollman			case $? in
21821259Swollman			0)
21921259Swollman				;;
220136950Sjmg			*)
22121259Swollman			echo 'Automatic file system check failed . . . help!'
22253541Sshin				exit 1
22353541Sshin				;;
22453541Sshin			esac
225160981Sbrooks			;;
22653541Sshin		*)
22721259Swollman			echo 'Automatic file system check failed . . . help!'
228148640Srwatson			exit 1
229148640Srwatson			;;
230148640Srwatson		esac
231148640Srwatson		;;
232148640Srwatson	12)
233148640Srwatson		echo 'Reboot interrupted'
234148640Srwatson		exit 1
235148640Srwatson		;;
236148640Srwatson	130)
237148640Srwatson		# interrupt before catcher installed
23821259Swollman		exit 1
23921259Swollman		;;
24021259Swollman	*)
24121259Swollman		echo 'Unknown error in reboot'
24221259Swollman		exit 1
24372200Sbmilekic		;;
24472200Sbmilekic	esac
245130416Smlaier	;;
24669152Sjlemon*)
24769152Sjlemon	echo 'Skipping disk checks ...'
24869152Sjlemon	;;
24921259Swollmanesac
25069152Sjlemon
25169152Sjlemonset -T
25269152Sjlemontrap "echo 'Reboot interrupted'; exit 1" 3
25369152Sjlemon
25469152Sjlemon# root normally must be read/write, but if this is a BOOTP NFS
25569152Sjlemon# diskless boot it does not have to be.
25669152Sjlemon#
25769152Sjlemoncase ${root_rw_mount} in
25869152Sjlemon[Nn][Oo] | '')
25969152Sjlemon	;;
26069152Sjlemon*)
26169152Sjlemon	if ! mount -u -o rw / ; then
26269152Sjlemon		echo 'Mounting root filesystem rw failed, startup aborted'
26369152Sjlemon		exit 1
26469152Sjlemon	fi
26569152Sjlemon	;;
26669152Sjlemonesac
26769152Sjlemon
26869152Sjlemonumount -a >/dev/null 2>&1
26969152Sjlemon
27069152Sjlemon# Mount everything except nfs filesystems.
27169152Sjlemonmount -a -t nonfs
27269152Sjlemon
27369152Sjlemoncase $? in
27469152Sjlemon0)
27569152Sjlemon	;;
27669152Sjlemon*)
27769152Sjlemon	echo 'Mounting /etc/fstab filesystems failed, startup aborted'
27869152Sjlemon	exit 1
27969152Sjlemon	;;
28069152Sjlemonesac
28169152Sjlemon
28269152Sjlemon# Run custom disk mounting function here
283136950Sjmg#
28469152Sjlemonif [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
28569152Sjlemon		sh ${diskless_mount}
28669152Sjlemonfi
28769152Sjlemon
28869152Sjlemon# Reseed /dev/random with previously stored entropy.
28969152Sjlemoncase ${entropy_dir} in
29069152Sjlemon[Nn][Oo])
29169152Sjlemon	;;
29269152Sjlemon*)
29369152Sjlemon	entropy_dir=${entropy_dir:-/var/db/entropy}
29469152Sjlemon	if [ -d "${entropy_dir}" ]; then
29569152Sjlemon		if [ -w /dev/random ]; then
296130416Smlaier			for seedfile in ${entropy_dir}/*; do
297130416Smlaier				feed_dev_random "${seedfile}"
298130416Smlaier			done
299130416Smlaier		fi
30069152Sjlemon	fi
30169152Sjlemon	;;
30269152Sjlemonesac
30369152Sjlemon
30469152Sjlemoncase ${entropy_file} in
30569152Sjlemon[Nn][Oo] | '')
30669152Sjlemon	;;
30769152Sjlemon*)
30869152Sjlemon	if [ -w /dev/random ]; then
309130416Smlaier		feed_dev_random "${entropy_file}"
310130416Smlaier	fi
311130416Smlaier	;;
312130416Smlaieresac
313130416Smlaier
314130416Smlaieradjkerntz -i
31555205Speter
316126264Smlaierpurgedir() {
317126264Smlaier	local dir file
318126264Smlaier
319126264Smlaier	if [ $# -eq 0 ]; then
320126264Smlaier		purgedir .
321126264Smlaier	else
322126264Smlaier		for dir
323126264Smlaier		do
324126264Smlaier		(
325126264Smlaier			cd "$dir" && for file in .* *
326159781Smlaier			do
327159781Smlaier				[ ."$file" = .. -o ."$file" = ... ] && continue
328159781Smlaier				if [ -d "$file" -a ! -L "$file" ]
329159781Smlaier				then
330159781Smlaier					purgedir "$file"
331159781Smlaier				else
332159781Smlaier					rm -f -- "$file"
333159781Smlaier				fi
334159781Smlaier			done
335159781Smlaier		)
336159781Smlaier		done
337159781Smlaier	fi
338159781Smlaier}
339159781Smlaier
340159781Smlaierclean_var() {
341159781Smlaier	if [ ! -f /var/run/clean_var ]; then
342159781Smlaier		purgedir /var/run /var/spool/lock
343159781Smlaier		rm -rf /var/spool/uucp/.Temp/*
344159781Smlaier		# Keep a copy of the boot messages around
345159781Smlaier		dmesg >/var/run/dmesg.boot
346159781Smlaier		# And an initial utmp file
347159781Smlaier		(cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
348159781Smlaier		>/var/run/clean_var
349159781Smlaier	fi
350159781Smlaier}
351159781Smlaier
352159781Smlaierif [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
353159781Smlaier	# network_pass1() *may* end up writing stuff to /var - we don't want to
354159781Smlaier	# remove it immediately afterwards - *nor* to we want to fail to clean
355159781Smlaier	# an nfs-mounted /var.
356159781Smlaier	clean_var
357121470Sumefi
358121470Sume
359121470Sume# Add additional swapfile, if configured.
360121470Sume#
361121470Sumecase ${swapfile} in
362121470Sume[Nn][Oo] | '')
363121470Sume	;;
364136704Srwatson*)
365136704Srwatson	if [ -w "${swapfile}" -a -c /dev/mdctl ]; then
366136704Srwatson		echo "Adding ${swapfile} as additional swap"
367136704Srwatson		mdev=`mdconfig -a -t vnode -f ${swapfile}` && swapon /dev/${mdev}
368136704Srwatson	fi
369136704Srwatson	;;
370136704Srwatsonesac
371136704Srwatson
372136704Srwatson# Set sysctl variables as early as we can
373136704Srwatson#
374137065Srwatsonif [ -r /etc/rc.sysctl ]; then
375137065Srwatson	. /etc/rc.sysctl
376130416Smlaierfi
377130416Smlaier
378130416Smlaier# Configure serial devices
379130416Smlaier#
38021259Swollmanif [ -r /etc/rc.serial ]; then
381132712Srwatson	. /etc/rc.serial
382132712Srwatsonfi
383130416Smlaier
384130416Smlaier# Start up PC-card configuration
385130416Smlaier#
386130416Smlaierif [ -r /etc/rc.pccard ]; then
387130416Smlaier	. /etc/rc.pccard
388130416Smlaierfi
389130416Smlaier
390130416Smlaier# Start up the initial network configuration.
391130416Smlaier#
392130416Smlaierif [ -r /etc/rc.network ]; then
393130416Smlaier	. /etc/rc.network	# We only need to do this once.
394130416Smlaier	network_pass1
395130416Smlaierfi
396130416Smlaier
397130416Smlaiercase ${ipv6_enable} in
398130416Smlaier[Yy][Ee][Ss])
399130416Smlaier	if [ -r /etc/rc.network6 ]; then
400130416Smlaier		. /etc/rc.network6	# We only need to do this once also.
40121259Swollman		network6_pass1
402130416Smlaier	fi
403130416Smlaier	;;
404130416Smlaieresac
405130508Smlaier
406130416Smlaier# Mount NFS filesystems if present in /etc/fstab
407130416Smlaiercase "`mount -d -a -t nfs 2> /dev/null`" in
408130416Smlaier*mount_nfs*)
409130416Smlaier	echo -n 'Mounting NFS file systems:'
410130416Smlaier	mount -a -t nfs
411130416Smlaier	echo '.'
412130416Smlaier	;;
413130416Smlaieresac
414130416Smlaier
415130416Smlaier# Whack the pty perms back into shape.
416130416Smlaier#
417130416Smlaierif ls /dev/tty[pqrsPQRS]* > /dev/null 2>&1; then
418130416Smlaier	chflags 0 /dev/tty[pqrsPQRS]*
419130416Smlaier	chmod 666 /dev/tty[pqrsPQRS]*
420130416Smlaier	chown root:wheel /dev/tty[pqrsPQRS]*
421130416Smlaierfi
422130508Smlaier
423130416Smlaier# Clean up left-over files
424130416Smlaier#
425130416Smlaierclean_var			# If it hasn't already been done
426130416Smlaierrm /var/run/clean_var
427130416Smlaier
428130416Smlaier# Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
429130416Smlaier# help in any way for long-living systems, and it might accidentally
430130416Smlaier# clobber files you would rather like to have preserved after a crash
431130416Smlaier# (if not using mfs /tmp anyway).
432130416Smlaier#
433130416Smlaier# See also the example of another cleanup policy in /etc/periodic/daily.
434130416Smlaier#
435130416Smlaiercase ${clear_tmp_enable} in
436130416Smlaier[Yy][Ee][Ss])
437130416Smlaier	echo -n 'Clearing /tmp:'
438130416Smlaier	# prune quickly with one rm, then use find to clean up /tmp/[lq]*
439130416Smlaier	# (not needed with mfs /tmp, but doesn't hurt there...)
440130416Smlaier	(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
441130416Smlaier		find -d . ! -name . ! -name lost+found ! -name quota.user \
442130416Smlaier		! -name quota.group -exec rm -rf -- {} \;)
443130416Smlaier	echo '.'
444130416Smlaier	;;
445130416Smlaieresac
446130416Smlaier
447130416Smlaier# Remove X lock files, since they will prevent you from restarting X11
448130416Smlaier# after a system crash.
449130416Smlaier#
450130416Smlaierrm -f /tmp/.X*-lock /tmp/.X11-unix/*
451130416Smlaier
452130416Smlaier# Snapshot any kernel -c changes back to disk here <someday>.
453130416Smlaier# This has changed with ELF and /kernel.config.
454130416Smlaier
455130416Smlaierecho -n 'Additional daemons:'
456130416Smlaier
457130416Smlaier# Start system logging and name service.  Named needs to start before syslogd
458130416Smlaier# if you don't have a /etc/resolv.conf.
459130416Smlaier#
460130416Smlaiercase ${syslogd_enable} in
461130416Smlaier[Yy][Ee][Ss])
462130416Smlaier	# Transitional symlink (for the next couple of years :) until all
463148886Srwatson	# binaries have had a chance to move towards /var/run/log.
464148886Srwatson	if [ ! -L /dev/log ]; then
465148886Srwatson		# might complain for r/o root f/s
466148886Srwatson		ln -sf /var/run/log /dev/log
467130416Smlaier	fi
468130416Smlaier
469130416Smlaier	rm -f /var/run/log
470130416Smlaier	echo -n ' syslogd';
471130416Smlaier	${syslogd_program:-/usr/sbin/syslogd} ${syslogd_flags}
472130416Smlaier	;;
473130416Smlaieresac
474130416Smlaier
475130416Smlaierecho '.'
476130416Smlaier
477130416Smlaier# Build device name databases if we are not using DEVFS
478130416Smlaier#
479148886Srwatsonif sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
480132712Srwatson	rm -f /var/run/dev.db
481130416Smlaierelse
482130416Smlaier	dev_mkdb
483130416Smlaierfi
484130416Smlaier
485130512Smlaier# Enable dumpdev so that savecore can see it.
486130416Smlaier# /var/crash should be a directory or a symbolic link
487130416Smlaier# to the crash directory if core dumps are to be saved.
488130416Smlaier#
489130416Smlaiercase ${dumpdev} in
490130416Smlaier[Nn][Oo] | '')
491130416Smlaier	;;
492130416Smlaier*)
493130416Smlaier	if [ -e "${dumpdev}" -a -d /var/crash ]; then
494130416Smlaier		/sbin/dumpon -v ${dumpdev}
495130416Smlaier		echo -n 'Checking for core dump: '
496130416Smlaier		/sbin/savecore ${savecore_flags} /var/crash
497130416Smlaier	fi
498130416Smlaier	;;
499130416Smlaieresac
500130416Smlaier
501130416Smlaierif [ -n "${network_pass1_done}" ]; then
502130416Smlaier	network_pass2
503130416Smlaierfi
504130416Smlaier
505130416Smlaier# Enable/Check the quotas (must be after ypbind if using NIS)
506130416Smlaier#
507130416Smlaiercase ${enable_quotas} in
508130416Smlaier[Yy][Ee][Ss])
509130416Smlaier	case ${check_quotas} in
510130416Smlaier	[Yy][Ee][Ss])
511130416Smlaier		echo -n 'Checking quotas:'
512130416Smlaier		quotacheck -a
513130416Smlaier		echo ' done.'
514130416Smlaier		;;
515130416Smlaier	esac
516130416Smlaier
517130416Smlaier	echo -n 'Enabling quotas:'
518132152Smlaier	quotaon -a
519132152Smlaier	echo ' done.'
520130416Smlaier	;;
521130416Smlaieresac
522130416Smlaier
523130416Smlaierif [ -n "${network_pass2_done}" ]; then
524130416Smlaier	network_pass3
525130416Smlaierfi
526130416Smlaier
527130416Smlaier# Check the password temp/lock file
528130416Smlaier#
529132152Smlaierif [ -e /etc/ptmp ]; then
530132152Smlaier	logger -s -p auth.err \
531132152Smlaier	"password file may be incorrect -- /etc/ptmp exists"
532130416Smlaierfi
533130416Smlaier
534130416Smlaiercase ${accounting_enable} in
535130416Smlaier[Yy][Ee][Ss])
536130416Smlaier	if [ -d /var/account ]; then
537130416Smlaier		echo 'Turning on accounting:'
538130416Smlaier		if [ ! -e /var/account/acct ]; then
53949459Sbrian			touch /var/account/acct
54049459Sbrian		fi
54149459Sbrian		accton /var/account/acct
54249459Sbrian	fi
54349459Sbrian	;;
54449459Sbrianesac
54549459Sbrian
54655205Speter# Make shared lib searching a little faster.  Leave /usr/lib first if you
54721259Swollman# add your own entries or you may come to grief.
54821259Swollman#
54921259Swollmanldconfig="/sbin/ldconfig"
55021259Swollmancase ${ldconfig_insecure} in
55121259Swollman[Yy][Ee][Ss])
55221259Swollman	ldconfig="${ldconfig} -i"
553128291Sluigi	;;
554128291Sluigiesac
555128291Sluigiif [ -x /sbin/ldconfig ]; then
556128291Sluigi	case `/usr/bin/objformat` in
55721259Swollman	elf)
55821259Swollman		_LDC=/usr/lib
55921259Swollman		for i in ${ldconfig_paths}; do
56021259Swollman			if [ -d "${i}" ]; then
56121259Swollman				_LDC="${_LDC} ${i}"
56221259Swollman			fi
56367334Sjoe		done
56421259Swollman		echo 'ELF ldconfig path:' ${_LDC}
56560938Sjake		${ldconfig} -elf ${_LDC}
56621259Swollman		;;
56792725Salfred	esac
56821259Swollman
56947254Spb	# Legacy aout support for i386 only
57021259Swollman	case `sysctl -n hw.machine` in
57128845Sjulian	i386)
57292725Salfred		# Default the a.out ldconfig path.
573108033Shsu		: ${ldconfig_paths_aout=${ldconfig_paths}}
57421259Swollman		_LDC=/usr/lib/aout
57521259Swollman		for i in ${ldconfig_paths_aout}; do
57621259Swollman			if [ -d "${i}" ]; then
57753541Sshin				_LDC="${_LDC} ${i}"
57853541Sshin			fi
57953541Sshin		done
580108033Shsu		echo 'a.out ldconfig path:' ${_LDC}
581108033Shsu		${ldconfig} -aout ${_LDC}
582108033Shsu		;;
583108033Shsu	esac
584108033Shsufi
585108033Shsu
58621404Swollman# Now start up miscellaneous daemons that don't belong anywhere else
58752904Sshin#
58852904Sshinecho -n 'Starting standard daemons:'
589108470Sschweikhcase ${inetd_enable} in
59053541Sshin[Nn][Oo])
59152904Sshin	;;
59252904Sshin*)
59352904Sshin	echo -n ' inetd'; ${inetd_program:-/usr/sbin/inetd} ${inetd_flags}
59452904Sshin	;;
59560938Sjakeesac
59652904Sshin
59752904Sshincase ${cron_enable} in
59852904Sshin[Nn][Oo])
59952904Sshin	;;
60052904Sshin*)
60121404Swollman	echo -n ' cron';	${cron_program:-/usr/sbin/cron} ${cron_flags}
60221404Swollman	;;
60321404Swollmanesac
60421404Swollman
60572084Sphkcase ${lpd_enable} in
60621434Swollman[Yy][Ee][Ss])
60721434Swollman	echo -n ' printer';	${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
60821434Swollman	;;
60921434Swollmanesac
61021434Swollman
611167729Sbmscase ${sshd_enable} in
61221404Swollman[Yy][Ee][Ss])
61321404Swollman	if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then
61455205Speter		echo -n ' sshd';
615108036Shsu		${sshd_program:-/usr/sbin/sshd} ${sshd_flags}
616108036Shsu	fi
617108036Shsu	;;
618108036Shsuesac
619108036Shsu
620108036Shsucase ${usbd_enable} in
621108036Shsu[Yy][Ee][Ss])
622108036Shsu	echo -n ' usbd';	/usr/sbin/usbd ${usbd_flags}
623108036Shsu	;;
624108036Shsuesac
62546568Speter
62621259Swollmanif [ -r /etc/mail/sendmail.cf ]; then
627108036Shsu	case ${sendmail_enable} in
628108036Shsu	[Yy][Ee][Ss])
629108036Shsu		echo -n ' sendmail'
630108036Shsu		/usr/sbin/sendmail ${sendmail_flags}
631108036Shsu		;;
632108033Shsu	*)
633108033Shsu		case ${sendmail_outbound_enable} in
634108172Shsu		[Yy][Ee][Ss])
635108298Shsu			echo -n ' sendmail'
636108298Shsu			/usr/sbin/sendmail ${sendmail_outbound_flags}
637108172Shsu			;;
638108172Shsu		esac
639108172Shsu		;;
640108172Shsu	esac
641108172Shsufi
64283130Sjlemon
64387914Sjlemonecho '.'
644130585Sphk
64583130Sjlemon# Recover vi editor files.
64683130Sjlemonfind /var/tmp/vi.recover ! -type f -a ! -type d -delete
64783130Sjlemonvibackup=`echo /var/tmp/vi.recover/vi.*`
648128315Sluigiif [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
649128315Sluigi	echo -n 'Recovering vi editor sessions:'
650128315Sluigi	for i in /var/tmp/vi.recover/vi.*; do
651128315Sluigi		# Only test files that are readable.
652128315Sluigi		if [ ! -r "${i}" ]; then
653152315Sru			continue
65483130Sjlemon		fi
65583130Sjlemon
65621259Swollman		# Unmodified nvi editor backup files either have the
65783130Sjlemon		# execute bit set or are zero length.  Delete them.
65821259Swollman		if [ -x "${i}" -o ! -s "${i}" ]; then
65971791Speter			rm -f "${i}"
66021259Swollman		fi
66121259Swollman	done
662159781Smlaier
663159781Smlaier	# It is possible to get incomplete recovery files, if the editor
66492725Salfred	# crashes at the right time.
66592725Salfred	virecovery=`echo /var/tmp/vi.recover/recover.*`
666147256Sbrooks	if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
66792725Salfred		for i in /var/tmp/vi.recover/recover.*; do
66892725Salfred			# Only test files that are readable.
669167729Sbms			if [ ! -r "${i}" ]; then
67092725Salfred				continue
671146620Speadar			fi
67292725Salfred
673147256Sbrooks			# Delete any recovery files that are zero length,
674147256Sbrooks			# corrupted, or that have no corresponding backup file.
675121816Sbrooks			# Else send mail to the user.
676138542Ssam			recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
677103900Sbrooks			if [ -n "${recfile}" -a -s "${recfile}" ]; then
67892725Salfred				sendmail -t < "${i}"
67992725Salfred			else
68092725Salfred				rm -f "${i}"
68192725Salfred			fi
68292725Salfred		done
68392725Salfred	fi
68421259Swollman	echo '.'
68592725Salfredfi
686162068Sandre
68792725Salfred# Make a bounds file for msgs(1) if there isn't one already
68892725Salfred#
68992725Salfredif [ -d /var/msgs -a ! -f /var/msgs/bounds -a ! -L /var/msgs/bounds ]; then
69092725Salfred	echo 0 > /var/msgs/bounds
69121259Swollmanfi
69292725Salfred
69321434Swollmancase ${update_motd} in
694147256Sbrooks[Nn][Oo] | '')
695147256Sbrooks	;;
696147256Sbrooks*)
697147256Sbrooks	if T=`mktemp /tmp/_motd.XXXXXX`; then
698147256Sbrooks		uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
69984931Sfjoe		awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
700152315Sru		cmp -s ${T} /etc/motd || {
70184931Sfjoe			cp ${T} /etc/motd
70287902Sluigi			chmod 644 /etc/motd
703150789Sglebius		}
70487902Sluigi		rm -f ${T}
70592725Salfred	fi
70692725Salfred	;;
70792725Salfredesac
70887902Sluigi
70987902Sluigi# Run rc.devfs if readable to customize devfs
71055205Speter#
71121259Swollmanif [ -r /etc/rc.devfs ]; then
71221259Swollman	sh /etc/rc.devfs
713fi
714
715# Configure implementation specific stuff
716#
717arch=`uname -m`
718if [ -r /etc/rc.${arch} ]; then
719	. /etc/rc.${arch}
720fi
721
722# Configure the system console
723#
724if [ -r /etc/rc.syscons ]; then
725	. /etc/rc.syscons
726fi
727
728echo -n 'Additional ABI support:'
729
730# Load the SysV IPC API if requested.
731case ${sysvipc_enable} in
732[Yy][Ee][Ss])
733	echo -n ' sysvipc'
734	kldload sysvmsg >/dev/null 2>&1
735	kldload sysvsem >/dev/null 2>&1
736	kldload sysvshm >/dev/null 2>&1
737	;;
738esac
739
740# Start the Linux binary compatibility if requested.
741#
742case ${linux_enable} in
743[Yy][Ee][Ss])
744	echo -n ' linux'
745	if ! kldstat -v | grep -E 'linux(aout|elf)' > /dev/null; then
746		kldload linux > /dev/null 2>&1
747	fi
748	if [ -x /compat/linux/sbin/ldconfig ]; then
749		/compat/linux/sbin/ldconfig
750	fi
751	;;
752esac
753
754# Start the SysVR4 binary emulation if requested.
755#
756case ${svr4_enable} in
757[Yy][Ee][Ss])
758	echo -n ' svr4';	kldload svr4 > /dev/null 2>&1
759	;;
760esac
761
762echo '.'
763
764# Do traditional (but rather obsolete) rc.local file if it exists.  If you
765# use this file and want to make it programmatic, source /etc/defaults/rc.conf
766# in /etc/rc.local and add your custom variables to /etc/rc.conf, as
767# shown below.  Please do not put local extensions into /etc/rc itself.
768# Use /etc/rc.local
769#
770# ---- rc.local ----
771#	if [ -r /etc/defaults/rc.conf ]; then
772#		. /etc/defaults/rc.conf
773#		source_rc_confs
774#	elif [ -r /etc/rc.conf ]; then
775#		. /etc/rc.conf
776#	fi
777#
778#	... additional startup conditionals ...
779# ---- rc.local ----
780#
781if [ -r /etc/rc.local ]; then
782	echo -n 'Starting local daemons:'
783	sh /etc/rc.local
784	echo '.'
785fi
786
787# For each valid dir in $local_startup, search for init scripts matching *.sh
788#
789case ${local_startup} in
790[Nn][Oo] | '')
791	;;
792*)
793	echo -n 'Local package initialization:'
794	slist=""
795	for dir in ${local_startup}; do
796		if [ -d "${dir}" ]; then
797			for script in ${dir}/*.sh; do
798				slist="${slist}${script_name_sep}${script}"
799			done
800		fi
801	done
802	script_save_sep="$IFS"
803	IFS="${script_name_sep}"
804	for script in ${slist}; do
805		if [ -x "${script}" ]; then
806			(set -T
807			trap 'exit 1' 2
808			${script} start)
809		elif [ -f "${script}" -or -l "${script}" ]; then
810			echo -n " (skipping ${script##*/}, not executable)"
811		fi
812	done
813	IFS="${script_save_sep}"
814	echo '.'
815	;;
816esac
817
818if [ -n "${network_pass3_done}" ]; then
819	network_pass4
820fi
821
822# Raise kernel security level.  This should be done only after `fsck' has
823# repaired local file systems if you want the securelevel to be greater than 1.
824#
825case ${kern_securelevel_enable} in
826[Yy][Ee][Ss])
827	if [ "${kern_securelevel}" -ge 0 ]; then
828		echo 'Raising kernel security level: '
829		sysctl -w kern.securelevel=${kern_securelevel}
830	fi
831	;;
832esac
833
834# Start background fsck checks if necessary
835case ${background_fsck} in
836[Yy][Ee][Ss])
837	echo 'Starting background filesystem checks'
838	nice -4 fsck -B -p 2>&1 | logger -p daemon.notice &
839	;;
840esac
841
842echo ''
843
844date
845
846exit 0
847
848