xref: /minix/usr.sbin/postinstall/postinstall (revision 0a6a1f1d)
123a61ee0SLionel Sambuc#!/bin/sh
223a61ee0SLionel Sambuc#
3*0a6a1f1dSLionel Sambuc# $NetBSD: postinstall,v 1.201 2015/08/24 07:21:14 christos Exp $
423a61ee0SLionel Sambuc#
5*0a6a1f1dSLionel Sambuc# Copyright (c) 2002-2015 The NetBSD Foundation, Inc.
623a61ee0SLionel Sambuc# All rights reserved.
723a61ee0SLionel Sambuc#
823a61ee0SLionel Sambuc# This code is derived from software contributed to The NetBSD Foundation
923a61ee0SLionel Sambuc# by Luke Mewburn.
1023a61ee0SLionel Sambuc#
1123a61ee0SLionel Sambuc# Redistribution and use in source and binary forms, with or without
1223a61ee0SLionel Sambuc# modification, are permitted provided that the following conditions
1323a61ee0SLionel Sambuc# are met:
1423a61ee0SLionel Sambuc# 1. Redistributions of source code must retain the above copyright
1523a61ee0SLionel Sambuc#    notice, this list of conditions and the following disclaimer.
1623a61ee0SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright
1723a61ee0SLionel Sambuc#    notice, this list of conditions and the following disclaimer in the
1823a61ee0SLionel Sambuc#    documentation and/or other materials provided with the distribution.
1923a61ee0SLionel Sambuc#
2023a61ee0SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2123a61ee0SLionel Sambuc# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2223a61ee0SLionel Sambuc# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2323a61ee0SLionel Sambuc# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2423a61ee0SLionel Sambuc# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2523a61ee0SLionel Sambuc# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2623a61ee0SLionel Sambuc# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2723a61ee0SLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2823a61ee0SLionel Sambuc# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2923a61ee0SLionel Sambuc# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3023a61ee0SLionel Sambuc# POSSIBILITY OF SUCH DAMAGE.
3123a61ee0SLionel Sambuc#
3223a61ee0SLionel Sambuc# postinstall
3323a61ee0SLionel Sambuc#	Check for or fix configuration changes that occur
3423a61ee0SLionel Sambuc#	over time as NetBSD evolves.
3523a61ee0SLionel Sambuc#
3623a61ee0SLionel Sambuc
3723a61ee0SLionel Sambuc#
3823a61ee0SLionel Sambuc# XXX BE SURE TO USE ${DEST_DIR} PREFIX BEFORE ALL REAL FILE OPERATIONS XXX
3923a61ee0SLionel Sambuc#
4023a61ee0SLionel Sambuc
4123a61ee0SLionel Sambuc#
4223a61ee0SLionel Sambuc# checks to add:
4323a61ee0SLionel Sambuc#	- sysctl(8) renames (net.inet6.ip6.bindv6only -> net.inet6.ip6.v6only)
4423a61ee0SLionel Sambuc#	- de* -> tlp* migration (/etc/ifconfig.de*, $ifconfig_de*,
4523a61ee0SLionel Sambuc#	  dhclient.conf, ...) ?
4623a61ee0SLionel Sambuc#	- support quiet/verbose mode ?
4723a61ee0SLionel Sambuc#	- differentiate between failures caused by missing source
4823a61ee0SLionel Sambuc#	  and real failures
4923a61ee0SLionel Sambuc#	- install moduli into usr/share/examples/ssh and use from there?
5023a61ee0SLionel Sambuc#	- differentiate between "needs fix" versus "can't fix" issues
5123a61ee0SLionel Sambuc#
5223a61ee0SLionel Sambuc
5323a61ee0SLionel Sambuc# This script is executed as part of a cross build.  Allow the build
5423a61ee0SLionel Sambuc# environment to override the locations of some tools.
5523a61ee0SLionel Sambuc: ${AWK:=awk}
5623a61ee0SLionel Sambuc: ${DB:=db}
5723a61ee0SLionel Sambuc: ${GREP:=grep}
5823a61ee0SLionel Sambuc: ${HOST_SH:=sh}
5923a61ee0SLionel Sambuc: ${MAKE:=make}
6023a61ee0SLionel Sambuc: ${PWD_MKDB:=/usr/sbin/pwd_mkdb}
61*0a6a1f1dSLionel Sambuc: ${SED:=sed}
62*0a6a1f1dSLionel Sambuc: ${SORT:=sort}
6323a61ee0SLionel Sambuc: ${STAT:=stat}
6423a61ee0SLionel Sambuc
6523a61ee0SLionel Sambuc#
6623a61ee0SLionel Sambuc#	helper functions
6723a61ee0SLionel Sambuc#
6823a61ee0SLionel Sambuc
6923a61ee0SLionel Sambucerr()
7023a61ee0SLionel Sambuc{
7123a61ee0SLionel Sambuc	exitval=$1
7223a61ee0SLionel Sambuc	shift
7323a61ee0SLionel Sambuc	echo 1>&2 "${PROGNAME}: $*"
7423a61ee0SLionel Sambuc	if [ -n "${SCRATCHDIR}" ]; then
7523a61ee0SLionel Sambuc	    /bin/rm -rf "${SCRATCHDIR}"
7623a61ee0SLionel Sambuc	fi
7723a61ee0SLionel Sambuc	exit ${exitval}
7823a61ee0SLionel Sambuc}
7923a61ee0SLionel Sambuc
8023a61ee0SLionel Sambucwarn()
8123a61ee0SLionel Sambuc{
8223a61ee0SLionel Sambuc	echo 1>&2 "${PROGNAME}: $*"
8323a61ee0SLionel Sambuc}
8423a61ee0SLionel Sambuc
8523a61ee0SLionel Sambucmsg()
8623a61ee0SLionel Sambuc{
8723a61ee0SLionel Sambuc	echo "	$*"
8823a61ee0SLionel Sambuc}
8923a61ee0SLionel Sambuc
9023a61ee0SLionel Sambucmkdtemp()
9123a61ee0SLionel Sambuc{
9223a61ee0SLionel Sambuc	# Make sure we don't loop forever if mkdir will always fail.
9323a61ee0SLionel Sambuc	[ -d /tmp ] || err 2 /tmp is not a directory
9423a61ee0SLionel Sambuc	[ -w /tmp ] || err 2 /tmp is not writable
9523a61ee0SLionel Sambuc
9623a61ee0SLionel Sambuc	_base="/tmp/_postinstall.$$"
9723a61ee0SLionel Sambuc	_serial=0
9823a61ee0SLionel Sambuc
9923a61ee0SLionel Sambuc	while true; do
10023a61ee0SLionel Sambuc		_dir="${_base}.${_serial}"
10123a61ee0SLionel Sambuc		mkdir -m 0700 "${_dir}" && break
10223a61ee0SLionel Sambuc		_serial=$((${_serial} + 1))
10323a61ee0SLionel Sambuc	done
10423a61ee0SLionel Sambuc	echo "${_dir}"
10523a61ee0SLionel Sambuc}
10623a61ee0SLionel Sambuc
10723a61ee0SLionel Sambuc# Quote args to make them safe in the shell.
10823a61ee0SLionel Sambuc# Usage: quotedlist="$(shell_quote args...)"
10923a61ee0SLionel Sambuc#
11023a61ee0SLionel Sambuc# After building up a quoted list, use it by evaling it inside
11123a61ee0SLionel Sambuc# double quotes, like this:
11223a61ee0SLionel Sambuc#    eval "set -- $quotedlist"
11323a61ee0SLionel Sambuc# or like this:
11423a61ee0SLionel Sambuc#    eval "\$command $quotedlist \$filename"
115*0a6a1f1dSLionel Sambuc#
11623a61ee0SLionel Sambucshell_quote()
117*0a6a1f1dSLionel Sambuc{(
11823a61ee0SLionel Sambuc	local result=''
119*0a6a1f1dSLionel Sambuc	local arg qarg
120*0a6a1f1dSLionel Sambuc	LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
12123a61ee0SLionel Sambuc	for arg in "$@" ; do
122*0a6a1f1dSLionel Sambuc		case "${arg}" in
123*0a6a1f1dSLionel Sambuc		'')
124*0a6a1f1dSLionel Sambuc			qarg="''"
125*0a6a1f1dSLionel Sambuc			;;
126*0a6a1f1dSLionel Sambuc		*[!-./a-zA-Z0-9]*)
12723a61ee0SLionel Sambuc			# Convert each embedded ' to '\'',
12823a61ee0SLionel Sambuc			# then insert ' at the beginning of the first line,
12923a61ee0SLionel Sambuc			# and append ' at the end of the last line.
130*0a6a1f1dSLionel Sambuc			# Finally, elide unnecessary '' pairs at the
131*0a6a1f1dSLionel Sambuc			# beginning and end of the result and as part of
132*0a6a1f1dSLionel Sambuc			# '\'''\'' sequences that result from multiple
133*0a6a1f1dSLionel Sambuc			# adjacent quotes in he input.
134*0a6a1f1dSLionel Sambuc			qarg="$(printf "%s\n" "$arg" | \
135*0a6a1f1dSLionel Sambuc			    ${SED:-sed} -e "s/'/'\\\\''/g" \
136*0a6a1f1dSLionel Sambuc				-e "1s/^/'/" -e "\$s/\$/'/" \
137*0a6a1f1dSLionel Sambuc				-e "1s/^''//" -e "\$s/''\$//" \
138*0a6a1f1dSLionel Sambuc				-e "s/'''/'/g"
139*0a6a1f1dSLionel Sambuc				)"
140*0a6a1f1dSLionel Sambuc			;;
141*0a6a1f1dSLionel Sambuc		*)
142*0a6a1f1dSLionel Sambuc			# Arg is not the empty string, and does not contain
143*0a6a1f1dSLionel Sambuc			# any unsafe characters.  Leave it unchanged for
144*0a6a1f1dSLionel Sambuc			# readability.
145*0a6a1f1dSLionel Sambuc			qarg="${arg}"
146*0a6a1f1dSLionel Sambuc			;;
147*0a6a1f1dSLionel Sambuc		esac
148*0a6a1f1dSLionel Sambuc		result="${result}${result:+ }${qarg}"
14923a61ee0SLionel Sambuc	done
15023a61ee0SLionel Sambuc	printf "%s\n" "$result"
151*0a6a1f1dSLionel Sambuc)}
152*0a6a1f1dSLionel Sambuc
153*0a6a1f1dSLionel Sambuc# Convert arg $1 to a basic regular expression (as in sed)
154*0a6a1f1dSLionel Sambuc# that will match the arg.  This works by inserting backslashes
155*0a6a1f1dSLionel Sambuc# before characters that are special in basic regular expressions.
156*0a6a1f1dSLionel Sambuc# It also inserts backslashes before the extra characters specified
157*0a6a1f1dSLionel Sambuc# in $2 (which defaults to "/,").
158*0a6a1f1dSLionel Sambuc# XXX: Does not handle embedded newlines.
159*0a6a1f1dSLionel Sambuc# Usage: regex="$(bre_quote "${string}")"
160*0a6a1f1dSLionel Sambucbre_quote()
161*0a6a1f1dSLionel Sambuc{
162*0a6a1f1dSLionel Sambuc	local arg="$1"
163*0a6a1f1dSLionel Sambuc	local extra="${2-/,}"
164*0a6a1f1dSLionel Sambuc	printf "%s\n" "${arg}" | ${SED} -e 's/[][^$.*\\'"${extra}"']/\\&/g'
16523a61ee0SLionel Sambuc}
16623a61ee0SLionel Sambuc
167*0a6a1f1dSLionel Sambuc# unprefix dir
168*0a6a1f1dSLionel Sambuc#	Remove any dir prefix from a list of paths on stdin,
169*0a6a1f1dSLionel Sambuc#	and write the result to stdout.  Useful for converting
170*0a6a1f1dSLionel Sambuc#	from ${DEST_DIR}/path to /path.
171*0a6a1f1dSLionel Sambuc#
172*0a6a1f1dSLionel Sambucunprefix()
173*0a6a1f1dSLionel Sambuc{
174*0a6a1f1dSLionel Sambuc	[ $# -eq 1 ] || err 3 "USAGE: unprefix dir"
175*0a6a1f1dSLionel Sambuc	local prefix="${1%/}"
176*0a6a1f1dSLionel Sambuc	prefix="$(bre_quote "${prefix}")"
177*0a6a1f1dSLionel Sambuc
178*0a6a1f1dSLionel Sambuc	${SED} -e "s,^${prefix}/,/,"
179*0a6a1f1dSLionel Sambuc}
18023a61ee0SLionel Sambuc
18123a61ee0SLionel Sambuc# additem item description
18223a61ee0SLionel Sambuc#	Add item to list of supported items to check/fix,
18323a61ee0SLionel Sambuc#	which are checked/fixed by default if no item is requested by user.
18423a61ee0SLionel Sambuc#
18523a61ee0SLionel Sambucadditem()
18623a61ee0SLionel Sambuc{
18723a61ee0SLionel Sambuc	[ $# -eq 2 ] || err 3 "USAGE: additem item description"
18823a61ee0SLionel Sambuc	defaultitems="${defaultitems}${defaultitems:+ }$1"
189*0a6a1f1dSLionel Sambuc	eval desc_$1=\"\$2\"
19023a61ee0SLionel Sambuc}
19123a61ee0SLionel Sambuc
19223a61ee0SLionel Sambuc# adddisableditem item description
19323a61ee0SLionel Sambuc#	Add item to list of supported items to check/fix,
19423a61ee0SLionel Sambuc#	but execute the item only if the user asks for it explicitly.
19523a61ee0SLionel Sambuc#
19623a61ee0SLionel Sambucadddisableditem()
19723a61ee0SLionel Sambuc{
19823a61ee0SLionel Sambuc	[ $# -eq 2 ] || err 3 "USAGE: adddisableditem item description"
19923a61ee0SLionel Sambuc	otheritems="${otheritems}${otheritems:+ }$1"
200*0a6a1f1dSLionel Sambuc	eval desc_$1=\"\$2\"
20123a61ee0SLionel Sambuc}
20223a61ee0SLionel Sambuc
20323a61ee0SLionel Sambuc# checkdir op dir mode
20423a61ee0SLionel Sambuc#	Ensure dir exists, and if not, create it with the appropriate mode.
20523a61ee0SLionel Sambuc#	Returns 0 if ok, 1 otherwise.
20623a61ee0SLionel Sambuc#
20723a61ee0SLionel Sambuccheck_dir()
20823a61ee0SLionel Sambuc{
20923a61ee0SLionel Sambuc	[ $# -eq 3 ] || err 3 "USAGE: check_dir op dir mode"
21023a61ee0SLionel Sambuc	_cdop="$1"
21123a61ee0SLionel Sambuc	_cddir="$2"
21223a61ee0SLionel Sambuc	_cdmode="$3"
21323a61ee0SLionel Sambuc	[ -d "${_cddir}" ] && return 0
21423a61ee0SLionel Sambuc	if [ "${_cdop}" = "check" ]; then
21523a61ee0SLionel Sambuc		msg "${_cddir} is not a directory"
21623a61ee0SLionel Sambuc		return 1
21723a61ee0SLionel Sambuc	elif ! mkdir -m "${_cdmode}" "${_cddir}" ; then
21823a61ee0SLionel Sambuc		msg "Can't create missing ${_cddir}"
21923a61ee0SLionel Sambuc		return 1
22023a61ee0SLionel Sambuc	else
22123a61ee0SLionel Sambuc		msg "Missing ${_cddir} created"
22223a61ee0SLionel Sambuc	fi
22323a61ee0SLionel Sambuc	return 0
22423a61ee0SLionel Sambuc}
22523a61ee0SLionel Sambuc
226*0a6a1f1dSLionel Sambuc# check_ids op type file srcfile start id [...]
227*0a6a1f1dSLionel Sambuc#	Check if file of type "users" or "groups" contains the relevant IDs.
228*0a6a1f1dSLionel Sambuc#	Use srcfile as a reference for the expected contents.
229*0a6a1f1dSLionel Sambuc#	The specified "id" names should be given in numerical order,
230*0a6a1f1dSLionel Sambuc#	with the first name corresponding to numerical value "start",
231*0a6a1f1dSLionel Sambuc#	and with the special name "SKIP" being used to mark gaps in the
232*0a6a1f1dSLionel Sambuc#	sequence.
23323a61ee0SLionel Sambuc#	Returns 0 if ok, 1 otherwise.
23423a61ee0SLionel Sambuc#
23523a61ee0SLionel Sambuccheck_ids()
23623a61ee0SLionel Sambuc{
237*0a6a1f1dSLionel Sambuc	[ $# -ge 6 ] || err 3 "USAGE: checks_ids op type file start srcfile id [...]"
23823a61ee0SLionel Sambuc	_op="$1"
23923a61ee0SLionel Sambuc	_type="$2"
24023a61ee0SLionel Sambuc	_file="$3"
241*0a6a1f1dSLionel Sambuc	_srcfile="$4"
242*0a6a1f1dSLionel Sambuc	_start="$5"
243*0a6a1f1dSLionel Sambuc	shift 5
24423a61ee0SLionel Sambuc	#_ids="$@"
24523a61ee0SLionel Sambuc
24623a61ee0SLionel Sambuc	if [ ! -f "${_file}" ]; then
24723a61ee0SLionel Sambuc		msg "${_file} doesn't exist; can't check for missing ${_type}"
24823a61ee0SLionel Sambuc		return 1
24923a61ee0SLionel Sambuc	fi
25023a61ee0SLionel Sambuc	if [ ! -r "${_file}" ]; then
25123a61ee0SLionel Sambuc		msg "${_file} is not readable; can't check for missing ${_type}"
25223a61ee0SLionel Sambuc		return 1
25323a61ee0SLionel Sambuc	fi
25423a61ee0SLionel Sambuc	_notfixed=""
25523a61ee0SLionel Sambuc	if [ "${_op}" = "fix" ]; then
25623a61ee0SLionel Sambuc		_notfixed="${NOT_FIXED}"
25723a61ee0SLionel Sambuc	fi
25884d9c625SLionel Sambuc	_missing="$(${AWK} -v start=$_start -F: '
25923a61ee0SLionel Sambuc		BEGIN {
26084d9c625SLionel Sambuc			for (x = 1; x < ARGC; x++) {
26184d9c625SLionel Sambuc				if (ARGV[x] == "SKIP")
26284d9c625SLionel Sambuc					continue;
26384d9c625SLionel Sambuc				idlist[ARGV[x]]++;
26484d9c625SLionel Sambuc				value[ARGV[x]] = start + x - 1;
26584d9c625SLionel Sambuc			}
26623a61ee0SLionel Sambuc			ARGC=1
26723a61ee0SLionel Sambuc		}
26823a61ee0SLionel Sambuc		{
26923a61ee0SLionel Sambuc			found[$1]++
27084d9c625SLionel Sambuc			number[$1] = $3
27123a61ee0SLionel Sambuc		}
27223a61ee0SLionel Sambuc		END {
27323a61ee0SLionel Sambuc			for (id in idlist) {
27423a61ee0SLionel Sambuc				if (!(id in found))
27584d9c625SLionel Sambuc					printf("%s (missing)\n", id)
27684d9c625SLionel Sambuc				else if (number[id] != value[id])
27784d9c625SLionel Sambuc					printf("%s (%d != %d)\n", id,
27884d9c625SLionel Sambuc					    number[id], value[id])
27984d9c625SLionel Sambuc				start++;
28023a61ee0SLionel Sambuc			}
28123a61ee0SLionel Sambuc		}
28223a61ee0SLionel Sambuc	' "$@" < "${_file}")"	|| return 1
28323a61ee0SLionel Sambuc	if [ -n "${_missing}" ]; then
28484d9c625SLionel Sambuc		msg "Error ${_type}${_notfixed}:" $(echo ${_missing})
285*0a6a1f1dSLionel Sambuc		msg "Use the following as a template:"
286*0a6a1f1dSLionel Sambuc		set -- ${_missing}
287*0a6a1f1dSLionel Sambuc		while [ $# -gt 0 ]
288*0a6a1f1dSLionel Sambuc		do
289*0a6a1f1dSLionel Sambuc			${GREP} -E "^${1}:" ${_srcfile}
290*0a6a1f1dSLionel Sambuc			shift 2
291*0a6a1f1dSLionel Sambuc		done
292*0a6a1f1dSLionel Sambuc		msg "and adjust if necessary."
29323a61ee0SLionel Sambuc		return 1
29423a61ee0SLionel Sambuc	fi
29523a61ee0SLionel Sambuc	return 0
29623a61ee0SLionel Sambuc}
29723a61ee0SLionel Sambuc
29823a61ee0SLionel Sambuc# populate_dir op onlynew src dest mode file [file ...]
29923a61ee0SLionel Sambuc#	Perform op ("check" or "fix") on files in src/ against dest/
30023a61ee0SLionel Sambuc#	If op = "check" display missing or changed files, optionally with diffs.
30123a61ee0SLionel Sambuc#	If op != "check" copies any missing or changed files.
30223a61ee0SLionel Sambuc#	If onlynew evaluates to true, changed files are ignored.
30323a61ee0SLionel Sambuc#	Returns 0 if ok, 1 otherwise.
30423a61ee0SLionel Sambuc#
30523a61ee0SLionel Sambucpopulate_dir()
30623a61ee0SLionel Sambuc{
30723a61ee0SLionel Sambuc	[ $# -ge 5 ] || err 3 "USAGE: populate_dir op onlynew src dest mode file [...]"
30823a61ee0SLionel Sambuc	_op="$1"
30923a61ee0SLionel Sambuc	_onlynew="$2"
31023a61ee0SLionel Sambuc	_src="$3"
31123a61ee0SLionel Sambuc	_dest="$4"
31223a61ee0SLionel Sambuc	_mode="$5"
31323a61ee0SLionel Sambuc	shift 5
31423a61ee0SLionel Sambuc	#_files="$@"
31523a61ee0SLionel Sambuc
31623a61ee0SLionel Sambuc	if [ ! -d "${_src}" ]; then
31723a61ee0SLionel Sambuc		msg "${_src} is not a directory; skipping check"
31823a61ee0SLionel Sambuc		return 1
31923a61ee0SLionel Sambuc	fi
32023a61ee0SLionel Sambuc	check_dir "${_op}" "${_dest}" 755 || return 1
32123a61ee0SLionel Sambuc
32223a61ee0SLionel Sambuc	_cmpdir_rv=0
32323a61ee0SLionel Sambuc	for f in "$@"; do
32423a61ee0SLionel Sambuc		fs="${_src}/${f}"
32523a61ee0SLionel Sambuc		fd="${_dest}/${f}"
32623a61ee0SLionel Sambuc		_error=""
32723a61ee0SLionel Sambuc		if [ ! -f "${fd}" ]; then
32823a61ee0SLionel Sambuc			_error="${fd} does not exist"
32923a61ee0SLionel Sambuc		elif ! cmp -s "${fs}" "${fd}" ; then
33023a61ee0SLionel Sambuc			if $_onlynew; then	# leave existing ${fd} alone
33123a61ee0SLionel Sambuc				continue;
33223a61ee0SLionel Sambuc			fi
33323a61ee0SLionel Sambuc			_error="${fs} != ${fd}"
33423a61ee0SLionel Sambuc		else
33523a61ee0SLionel Sambuc			continue
33623a61ee0SLionel Sambuc		fi
33723a61ee0SLionel Sambuc		if [ "${_op}" = "check" ]; then
33823a61ee0SLionel Sambuc			msg "${_error}"
33923a61ee0SLionel Sambuc			if [ -n "${DIFF_STYLE}" -a -f "${fd}" ]; then
34023a61ee0SLionel Sambuc				diff -${DIFF_STYLE} ${DIFF_OPT} "${fd}" "${fs}"
34123a61ee0SLionel Sambuc			fi
34223a61ee0SLionel Sambuc			_cmpdir_rv=1
34323a61ee0SLionel Sambuc		elif ! rm -f "${fd}" ||
34423a61ee0SLionel Sambuc		     ! cp -f "${fs}" "${fd}"; then
34523a61ee0SLionel Sambuc			msg "Can't copy ${fs} to ${fd}"
34623a61ee0SLionel Sambuc			_cmpdir_rv=1
34723a61ee0SLionel Sambuc		elif ! chmod "${_mode}" "${fd}"; then
34823a61ee0SLionel Sambuc			msg "Can't change mode of ${fd} to ${_mode}"
34923a61ee0SLionel Sambuc			_cmpdir_rv=1
35023a61ee0SLionel Sambuc		else
35123a61ee0SLionel Sambuc			msg "Copied ${fs} to ${fd}"
35223a61ee0SLionel Sambuc		fi
35323a61ee0SLionel Sambuc	done
35423a61ee0SLionel Sambuc	return ${_cmpdir_rv}
35523a61ee0SLionel Sambuc}
35623a61ee0SLionel Sambuc
35723a61ee0SLionel Sambuc# compare_dir op src dest mode file [file ...]
35823a61ee0SLionel Sambuc#	Perform op ("check" or "fix") on files in src/ against dest/
35923a61ee0SLionel Sambuc#	If op = "check" display missing or changed files, optionally with diffs.
36023a61ee0SLionel Sambuc#	If op != "check" copies any missing or changed files.
36123a61ee0SLionel Sambuc#	Returns 0 if ok, 1 otherwise.
36223a61ee0SLionel Sambuc#
36323a61ee0SLionel Sambuccompare_dir()
36423a61ee0SLionel Sambuc{
36523a61ee0SLionel Sambuc	[ $# -ge 4 ] || err 3 "USAGE: compare_dir op src dest mode file [...]"
36623a61ee0SLionel Sambuc	_op="$1"
36723a61ee0SLionel Sambuc	_src="$2"
36823a61ee0SLionel Sambuc	_dest="$3"
36923a61ee0SLionel Sambuc	_mode="$4"
37023a61ee0SLionel Sambuc	shift 4
37123a61ee0SLionel Sambuc	#_files="$@"
37223a61ee0SLionel Sambuc
37323a61ee0SLionel Sambuc	populate_dir "$_op" false "$_src" "$_dest" "$_mode" "$@"
37423a61ee0SLionel Sambuc}
37523a61ee0SLionel Sambuc
37623a61ee0SLionel Sambuc# move_file op src dest --
37723a61ee0SLionel Sambuc#	Check (op == "check") or move (op != "check") from src to dest.
37823a61ee0SLionel Sambuc#	Returns 0 if ok, 1 otherwise.
37923a61ee0SLionel Sambuc#
38023a61ee0SLionel Sambucmove_file()
38123a61ee0SLionel Sambuc{
38223a61ee0SLionel Sambuc	[ $# -eq 3 ] || err 3 "USAGE: move_file op src dest"
38323a61ee0SLionel Sambuc	_fm_op="$1"
38423a61ee0SLionel Sambuc	_fm_src="$2"
38523a61ee0SLionel Sambuc	_fm_dest="$3"
38623a61ee0SLionel Sambuc
38723a61ee0SLionel Sambuc	if [ -f "${_fm_src}" -a ! -f "${_fm_dest}" ]; then
38823a61ee0SLionel Sambuc		if [ "${_fm_op}" = "check" ]; then
38923a61ee0SLionel Sambuc			msg "Move ${_fm_src} to ${_fm_dest}"
39023a61ee0SLionel Sambuc			return 1
39123a61ee0SLionel Sambuc		fi
39223a61ee0SLionel Sambuc		if ! mv "${_fm_src}" "${_fm_dest}"; then
39323a61ee0SLionel Sambuc			msg "Can't move ${_fm_src} to ${_fm_dest}"
39423a61ee0SLionel Sambuc			return 1
39523a61ee0SLionel Sambuc		fi
39623a61ee0SLionel Sambuc		msg "Moved ${_fm_src} to ${_fm_dest}"
39723a61ee0SLionel Sambuc	fi
39823a61ee0SLionel Sambuc	return 0
39923a61ee0SLionel Sambuc}
40023a61ee0SLionel Sambuc
40123a61ee0SLionel Sambuc# rcconf_is_set op name var [verbose] --
40223a61ee0SLionel Sambuc#	Load the rcconf for name, and check if obsolete rc.conf(5) variable
40323a61ee0SLionel Sambuc#	var is defined or not.
40423a61ee0SLionel Sambuc#	Returns 0 if defined (even to ""), otherwise 1.
40523a61ee0SLionel Sambuc#	If verbose != "", print an obsolete warning if the var is defined.
40623a61ee0SLionel Sambuc#
40723a61ee0SLionel Sambucrcconf_is_set()
40823a61ee0SLionel Sambuc{
40923a61ee0SLionel Sambuc	[ $# -ge 3 ] || err 3 "USAGE: rcconf_is_set op name var [verbose]"
41023a61ee0SLionel Sambuc	_rcis_op="$1"
41123a61ee0SLionel Sambuc	_rcis_name="$2"
41223a61ee0SLionel Sambuc	_rcis_var="$3"
41323a61ee0SLionel Sambuc	_rcis_verbose="$4"
41423a61ee0SLionel Sambuc	_rcis_notfixed=""
41523a61ee0SLionel Sambuc	if [ "${_rcis_op}" = "fix" ]; then
41623a61ee0SLionel Sambuc		_rcis_notfixed="${NOT_FIXED}"
41723a61ee0SLionel Sambuc	fi
41823a61ee0SLionel Sambuc	(
41923a61ee0SLionel Sambuc		for f in \
42023a61ee0SLionel Sambuc		    "${DEST_DIR}/etc/rc.conf" \
42123a61ee0SLionel Sambuc		    "${DEST_DIR}/etc/rc.conf.d/${_rcis_name}"; do
42223a61ee0SLionel Sambuc			[ -f "${f}" ] && . "${f}"
42323a61ee0SLionel Sambuc		done
42423a61ee0SLionel Sambuc		eval echo -n \"\${${_rcis_var}}\" 1>&3
42523a61ee0SLionel Sambuc		if eval "[ -n \"\${${_rcis_var}}\" \
42623a61ee0SLionel Sambuc			    -o \"\${${_rcis_var}-UNSET}\" != \"UNSET\" ]"; then
42723a61ee0SLionel Sambuc			if [ -n "${_rcis_verbose}" ]; then
42823a61ee0SLionel Sambuc				msg \
42923a61ee0SLionel Sambuc    "Obsolete rc.conf(5) variable '\$${_rcis_var}' found.${_rcis_notfixed}"
43023a61ee0SLionel Sambuc			fi
43123a61ee0SLionel Sambuc			exit 0
43223a61ee0SLionel Sambuc		else
43323a61ee0SLionel Sambuc			exit 1
43423a61ee0SLionel Sambuc		fi
43523a61ee0SLionel Sambuc	)
43623a61ee0SLionel Sambuc}
43723a61ee0SLionel Sambuc
43823a61ee0SLionel Sambuc# rcvar_is_enabled var
43923a61ee0SLionel Sambuc#	Check if rcvar is enabled
44023a61ee0SLionel Sambuc#
44123a61ee0SLionel Sambucrcvar_is_enabled()
44223a61ee0SLionel Sambuc{
44323a61ee0SLionel Sambuc	[ $# -eq 1 ] || err 3 "USAGE: rcvar_is_enabled var"
44423a61ee0SLionel Sambuc	_rcie_var="$1"
44523a61ee0SLionel Sambuc	(
44623a61ee0SLionel Sambuc		[ -f "${DEST_DIR}/etc/rc.conf" ] && . "${DEST_DIR}/etc/rc.conf"
447*0a6a1f1dSLionel Sambuc		eval _rcie_val=\"\${${_rcie_var}}\"
44823a61ee0SLionel Sambuc		case $_rcie_val in
44923a61ee0SLionel Sambuc		#	"yes", "true", "on", or "1"
45023a61ee0SLionel Sambuc		[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
45123a61ee0SLionel Sambuc			exit 0
45223a61ee0SLionel Sambuc			;;
45323a61ee0SLionel Sambuc
45423a61ee0SLionel Sambuc		*)
45523a61ee0SLionel Sambuc			exit 1
45623a61ee0SLionel Sambuc			;;
45723a61ee0SLionel Sambuc		esac
45823a61ee0SLionel Sambuc	)
45923a61ee0SLionel Sambuc}
46023a61ee0SLionel Sambuc
46123a61ee0SLionel Sambuc# find_file_in_dirlist() file message dir1 [...] --
46223a61ee0SLionel Sambuc#	Find which directory file is in, and sets ${dir} to match.
46323a61ee0SLionel Sambuc#	Returns 0 if matched, otherwise 1 (and sets ${dir} to "").
46423a61ee0SLionel Sambuc#
46523a61ee0SLionel Sambuc#	Generally, check the directory for the "checking from source" case,
46623a61ee0SLionel Sambuc#	and then the directory for the "checking from extracted etc.tgz" case.
46723a61ee0SLionel Sambuc#
46823a61ee0SLionel Sambucfind_file_in_dirlist()
46923a61ee0SLionel Sambuc{
47023a61ee0SLionel Sambuc	[ $# -ge 3 ] || err 3 "USAGE: find_file_in_dirlist file msg dir1 [...]"
47123a61ee0SLionel Sambuc
47223a61ee0SLionel Sambuc	_file="$1" ; shift
47323a61ee0SLionel Sambuc	_msg="$1" ; shift
47423a61ee0SLionel Sambuc	_dir1st=	# first dir in list
47523a61ee0SLionel Sambuc	for dir in "$@"; do
47623a61ee0SLionel Sambuc		: ${_dir1st:="${dir}"}
47723a61ee0SLionel Sambuc		if [ -f "${dir}/${_file}" ]; then
47823a61ee0SLionel Sambuc			if [ "${_dir1st}" != "${dir}" ]; then
47923a61ee0SLionel Sambuc				msg \
48023a61ee0SLionel Sambuc    "(Checking for ${_msg} from ${dir} instead of ${_dir1st})"
48123a61ee0SLionel Sambuc			fi
48223a61ee0SLionel Sambuc			return 0
48323a61ee0SLionel Sambuc		fi
48423a61ee0SLionel Sambuc	done
48523a61ee0SLionel Sambuc	msg "Can't find source directory for ${_msg}"
48623a61ee0SLionel Sambuc	return 1
48723a61ee0SLionel Sambuc}
48823a61ee0SLionel Sambuc
48923a61ee0SLionel Sambuc# file_exists_exact path
49023a61ee0SLionel Sambuc#	Returns true if a file exists in the ${DEST_DIR} whose name
49123a61ee0SLionel Sambuc#	is exactly ${path}, interpreted in a case-sensitive way
49223a61ee0SLionel Sambuc#	even if the underlying file system is case-insensitive.
49323a61ee0SLionel Sambuc#
49423a61ee0SLionel Sambuc#	The path must begin with '/' or './', and is interpreted as
49523a61ee0SLionel Sambuc#	being relative to ${DEST_DIR}.
49623a61ee0SLionel Sambuc#
49723a61ee0SLionel Sambucfile_exists_exact()
49823a61ee0SLionel Sambuc{
49923a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: file_exists_exact path"
50023a61ee0SLionel Sambuc	_path="${1#.}"
50123a61ee0SLionel Sambuc	[ -h "${DEST_DIR}${_path}" ] || \
50223a61ee0SLionel Sambuc		[ -e "${DEST_DIR}${_path}" ] || return 1
503*0a6a1f1dSLionel Sambuc	while [ "${_path}" != "/" -a "${_path}" != "." ] ; do
50423a61ee0SLionel Sambuc		_dirname="$(dirname "${_path}" 2>/dev/null)"
50523a61ee0SLionel Sambuc		_basename="$(basename "${_path}" 2>/dev/null)"
50623a61ee0SLionel Sambuc		ls -fa "${DEST_DIR}${_dirname}" 2> /dev/null \
50723a61ee0SLionel Sambuc			| ${GREP} -F -x "${_basename}" >/dev/null \
50823a61ee0SLionel Sambuc			|| return 1
50923a61ee0SLionel Sambuc		_path="${_dirname}"
51023a61ee0SLionel Sambuc	done
51123a61ee0SLionel Sambuc	return 0
51223a61ee0SLionel Sambuc}
51323a61ee0SLionel Sambuc
51423a61ee0SLionel Sambuc# obsolete_paths op
51523a61ee0SLionel Sambuc#	Obsolete the list of paths provided on stdin.
516*0a6a1f1dSLionel Sambuc#	Each path should start with '/' or './', and
517*0a6a1f1dSLionel Sambuc#	will be interpreted relative to ${DEST_DIR}.
51823a61ee0SLionel Sambuc#
51923a61ee0SLionel Sambucobsolete_paths()
52023a61ee0SLionel Sambuc{
52123a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: obsolete_paths  fix|check"
52223a61ee0SLionel Sambuc	op="$1"
52323a61ee0SLionel Sambuc
52423a61ee0SLionel Sambuc	failed=0
52523a61ee0SLionel Sambuc	while read ofile; do
52623a61ee0SLionel Sambuc		if ! file_exists_exact "${ofile}"; then
52723a61ee0SLionel Sambuc			continue
52823a61ee0SLionel Sambuc		fi
52923a61ee0SLionel Sambuc		ofile="${DEST_DIR}${ofile#.}"
53023a61ee0SLionel Sambuc		cmd="rm"
53123a61ee0SLionel Sambuc		ftype="file"
53223a61ee0SLionel Sambuc		if [ -h "${ofile}" ]; then
53323a61ee0SLionel Sambuc			ftype="link"
53423a61ee0SLionel Sambuc		elif [ -d "${ofile}" ]; then
53523a61ee0SLionel Sambuc			ftype="directory"
53623a61ee0SLionel Sambuc			cmd="rmdir"
53723a61ee0SLionel Sambuc		fi
53823a61ee0SLionel Sambuc		if [ "${op}" = "check" ]; then
53923a61ee0SLionel Sambuc			msg "Remove obsolete ${ftype} ${ofile}"
54023a61ee0SLionel Sambuc			failed=1
541*0a6a1f1dSLionel Sambuc		elif ! eval "${cmd} \"\${ofile}\""; then
54223a61ee0SLionel Sambuc			msg "Can't remove obsolete ${ftype} ${ofile}"
54323a61ee0SLionel Sambuc			failed=1
54423a61ee0SLionel Sambuc		else
54523a61ee0SLionel Sambuc			msg "Removed obsolete ${ftype} ${ofile}"
54623a61ee0SLionel Sambuc		fi
54723a61ee0SLionel Sambuc	done
54823a61ee0SLionel Sambuc	return ${failed}
54923a61ee0SLionel Sambuc}
55023a61ee0SLionel Sambuc
55123a61ee0SLionel Sambuc# obsolete_libs dir
55223a61ee0SLionel Sambuc#	Display the minor/teeny shared libraries in dir that are considered
55323a61ee0SLionel Sambuc#	to be obsolete.
55423a61ee0SLionel Sambuc#
55523a61ee0SLionel Sambuc#	The implementation supports removing obsolete major libraries
55623a61ee0SLionel Sambuc#	if the awk variable AllLibs is set, although there is no way to
55723a61ee0SLionel Sambuc#	enable that in the enclosing shell function as this time.
55823a61ee0SLionel Sambuc#
55923a61ee0SLionel Sambucobsolete_libs()
56023a61ee0SLionel Sambuc{
56123a61ee0SLionel Sambuc	[ $# -eq 1 ] || err 3 "USAGE: obsolete_libs dir"
56223a61ee0SLionel Sambuc	dir="$1"
56323a61ee0SLionel Sambuc
56423a61ee0SLionel Sambuc	_obsolete_libs "${dir}"
56523a61ee0SLionel Sambuc	_obsolete_libs "/usr/libdata/debug/${dir}"
56623a61ee0SLionel Sambuc}
56723a61ee0SLionel Sambuc
56823a61ee0SLionel Sambuc_obsolete_libs()
56923a61ee0SLionel Sambuc{
57023a61ee0SLionel Sambuc	dir="$1"
57123a61ee0SLionel Sambuc
57223a61ee0SLionel Sambuc	(
57323a61ee0SLionel Sambuc
57423a61ee0SLionel Sambuc	if [ ! -e "${DEST_DIR}/${dir}" ]
57523a61ee0SLionel Sambuc	then
57623a61ee0SLionel Sambuc		return 0
57723a61ee0SLionel Sambuc	fi
57823a61ee0SLionel Sambuc
57923a61ee0SLionel Sambuc	cd "${DEST_DIR}/${dir}" || err 2 "can't cd to ${DEST_DIR}/${dir}"
58023a61ee0SLionel Sambuc	echo lib*.so.* \
58123a61ee0SLionel Sambuc	| tr ' ' '\n' \
58223a61ee0SLionel Sambuc	| ${AWK} -v LibDir="${dir}/" '
58323a61ee0SLionel Sambuc#{
58423a61ee0SLionel Sambuc
58523a61ee0SLionel Sambucfunction digit(v, c, n) { return (n <= c) ? v[n] : 0 }
58623a61ee0SLionel Sambuc
58723a61ee0SLionel Sambucfunction checklib(results, line, regex) {
58823a61ee0SLionel Sambuc	if (! match(line, regex))
58923a61ee0SLionel Sambuc		return
59023a61ee0SLionel Sambuc	lib = substr(line, RSTART, RLENGTH)
59123a61ee0SLionel Sambuc	rev = substr($0, RLENGTH+1)
59223a61ee0SLionel Sambuc	if (! (lib in results)) {
59323a61ee0SLionel Sambuc		results[lib] = rev
59423a61ee0SLionel Sambuc		return
59523a61ee0SLionel Sambuc	}
59623a61ee0SLionel Sambuc	orevc = split(results[lib], orev, ".")
59723a61ee0SLionel Sambuc	nrevc = split(rev, nrev, ".")
59823a61ee0SLionel Sambuc	maxc = (orevc > nrevc) ? orevc : nrevc
59923a61ee0SLionel Sambuc	for (i = 1; i <= maxc; i++) {
60023a61ee0SLionel Sambuc		res = digit(orev, orevc, i) - digit(nrev, nrevc, i)
60123a61ee0SLionel Sambuc		if (res < 0) {
60223a61ee0SLionel Sambuc			print LibDir lib results[lib]
60323a61ee0SLionel Sambuc			results[lib] = rev
60423a61ee0SLionel Sambuc			return
60523a61ee0SLionel Sambuc		} else if (res > 0) {
60623a61ee0SLionel Sambuc			print LibDir lib rev
60723a61ee0SLionel Sambuc			return
60823a61ee0SLionel Sambuc		}
60923a61ee0SLionel Sambuc	}
61023a61ee0SLionel Sambuc}
61123a61ee0SLionel Sambuc
61223a61ee0SLionel Sambuc/^lib.*\.so\.[0-9]+\.[0-9]+(\.[0-9]+)?(\.debug)?$/ {
61323a61ee0SLionel Sambuc	if (AllLibs)
61423a61ee0SLionel Sambuc		checklib(minor, $0, "^lib.*\\.so\\.")
61523a61ee0SLionel Sambuc	else
61623a61ee0SLionel Sambuc		checklib(found, $0, "^lib.*\\.so\\.[0-9]+\\.")
61723a61ee0SLionel Sambuc}
61823a61ee0SLionel Sambuc
61923a61ee0SLionel Sambuc/^lib.*\.so\.[0-9]+$/ {
62023a61ee0SLionel Sambuc	if (AllLibs)
62123a61ee0SLionel Sambuc		checklib(major, $0, "^lib.*\\.so\\.")
62223a61ee0SLionel Sambuc}
62323a61ee0SLionel Sambuc
62423a61ee0SLionel Sambuc#}'
62523a61ee0SLionel Sambuc
62623a61ee0SLionel Sambuc	)
62723a61ee0SLionel Sambuc}
62823a61ee0SLionel Sambuc
629*0a6a1f1dSLionel Sambuc# obsolete_stand dir
630*0a6a1f1dSLionel Sambuc#	Prints the names of all obsolete files and subdirs below the
631*0a6a1f1dSLionel Sambuc#	provided dir.  dir should be something like /stand/${MACHINE}.
632*0a6a1f1dSLionel Sambuc#	The input dir and all output paths are interpreted
633*0a6a1f1dSLionel Sambuc#	relative to ${DEST_DIR}.
634*0a6a1f1dSLionel Sambuc#
635*0a6a1f1dSLionel Sambuc#	Assumes that the numerically largest subdir is current, and all
636*0a6a1f1dSLionel Sambuc#	others are obsolete.
637*0a6a1f1dSLionel Sambuc#
638*0a6a1f1dSLionel Sambucobsolete_stand()
639*0a6a1f1dSLionel Sambuc{
640*0a6a1f1dSLionel Sambuc	[ $# -eq 1 ] || err 3 "USAGE: obsolete_stand dir"
641*0a6a1f1dSLionel Sambuc	local dir="$1"
642*0a6a1f1dSLionel Sambuc	local subdir
643*0a6a1f1dSLionel Sambuc
644*0a6a1f1dSLionel Sambuc	if ! [ -d "${DEST_DIR}${dir}" ]; then
645*0a6a1f1dSLionel Sambuc		msg "${DEST_DIR}${dir} doesn't exist; can't check for obsolete files"
646*0a6a1f1dSLionel Sambuc		return 1
647*0a6a1f1dSLionel Sambuc	fi
648*0a6a1f1dSLionel Sambuc
649*0a6a1f1dSLionel Sambuc	( cd "${DEST_DIR}${dir}" && ls -1d [0-9]*[0-9]/. ) \
650*0a6a1f1dSLionel Sambuc	| ${GREP} -v '[^0-9./]' \
651*0a6a1f1dSLionel Sambuc	| sort -t. -r -k1n -k2n -k3n \
652*0a6a1f1dSLionel Sambuc	| tail -n +2 \
653*0a6a1f1dSLionel Sambuc	| while read subdir ; do
654*0a6a1f1dSLionel Sambuc		subdir="${subdir%/.}"
655*0a6a1f1dSLionel Sambuc		find "${DEST_DIR}${dir}/${subdir}" -depth -print
656*0a6a1f1dSLionel Sambuc	done \
657*0a6a1f1dSLionel Sambuc	| unprefix "${DEST_DIR}"
658*0a6a1f1dSLionel Sambuc}
659*0a6a1f1dSLionel Sambuc
66023a61ee0SLionel Sambuc# modify_file op srcfile scratchfile awkprog
66123a61ee0SLionel Sambuc#	Apply awkprog to srcfile sending output to scratchfile, and
66223a61ee0SLionel Sambuc#	if appropriate replace srcfile with scratchfile.
66323a61ee0SLionel Sambuc#
66423a61ee0SLionel Sambucmodify_file()
66523a61ee0SLionel Sambuc{
66623a61ee0SLionel Sambuc	[ $# -eq 4 ] || err 3 "USAGE: modify_file op file scratch awkprog"
66723a61ee0SLionel Sambuc
66823a61ee0SLionel Sambuc	_mfop="$1"
66923a61ee0SLionel Sambuc	_mffile="$2"
67023a61ee0SLionel Sambuc	_mfscratch="$3"
67123a61ee0SLionel Sambuc	_mfprog="$4"
67223a61ee0SLionel Sambuc	_mffailed=0
67323a61ee0SLionel Sambuc
67423a61ee0SLionel Sambuc	${AWK} "${_mfprog}" < "${_mffile}" > "${_mfscratch}"
67523a61ee0SLionel Sambuc	if ! cmp -s "${_mffile}" "${_mfscratch}"; then
67623a61ee0SLionel Sambuc		diff "${_mffile}" "${_mfscratch}" > "${_mfscratch}.diffs"
67723a61ee0SLionel Sambuc		if [ "${_mfop}" = "check" ]; then
67823a61ee0SLionel Sambuc			msg "${_mffile} needs the following changes:"
67923a61ee0SLionel Sambuc			_mffailed=1
68023a61ee0SLionel Sambuc		elif ! rm -f "${_mffile}" ||
68123a61ee0SLionel Sambuc		     ! cp -f "${_mfscratch}" "${_mffile}"; then
68223a61ee0SLionel Sambuc			msg "${_mffile} changes not applied:"
68323a61ee0SLionel Sambuc			_mffailed=1
68423a61ee0SLionel Sambuc		else
68523a61ee0SLionel Sambuc			msg "${_mffile} changes applied:"
68623a61ee0SLionel Sambuc		fi
68723a61ee0SLionel Sambuc		while read _line; do
68823a61ee0SLionel Sambuc			msg "	${_line}"
68923a61ee0SLionel Sambuc		done < "${_mfscratch}.diffs"
69023a61ee0SLionel Sambuc	fi
69123a61ee0SLionel Sambuc	return ${_mffailed}
69223a61ee0SLionel Sambuc}
69323a61ee0SLionel Sambuc
69423a61ee0SLionel Sambuc
69523a61ee0SLionel Sambuc# contents_owner op directory user group
69623a61ee0SLionel Sambuc#	Make sure directory and contents are owned (and group-owned)
69723a61ee0SLionel Sambuc#	as specified.
69823a61ee0SLionel Sambuc#
69923a61ee0SLionel Sambuccontents_owner()
70023a61ee0SLionel Sambuc{
70123a61ee0SLionel Sambuc	[ $# -eq 4 ] || err 3 "USAGE: contents_owner op dir user group"
70223a61ee0SLionel Sambuc
70323a61ee0SLionel Sambuc	_op="$1"
70423a61ee0SLionel Sambuc	_dir="$2"
70523a61ee0SLionel Sambuc	_user="$3"
70623a61ee0SLionel Sambuc	_grp="$4"
70723a61ee0SLionel Sambuc
70823a61ee0SLionel Sambuc	if [ "${_op}" = "check" ]; then
70923a61ee0SLionel Sambuc		if [ ! -z "`find "${_dir}" \( ! -user "${_user}" \) -o \
71023a61ee0SLionel Sambuc		    \( ! -group "${_grp}" \)`" ]; then
71123a61ee0SLionel Sambuc			msg \
71223a61ee0SLionel Sambuc    "${_dir} and contents not all owned by ${_user}:${_grp}"
71323a61ee0SLionel Sambuc			return 1
71423a61ee0SLionel Sambuc		else
71523a61ee0SLionel Sambuc			return 0
71623a61ee0SLionel Sambuc		fi
71723a61ee0SLionel Sambuc	elif [ "${_op}" = "fix" ]; then
71823a61ee0SLionel Sambuc		find "${_dir}" \( \( ! -user "${_user}" \) -o \
71923a61ee0SLionel Sambuc		\( ! -group "${_grp}" \) \) -a -print0 \
72023a61ee0SLionel Sambuc		| xargs -0 chown "${_user}:${_grp}"
72123a61ee0SLionel Sambuc	fi
72223a61ee0SLionel Sambuc}
72323a61ee0SLionel Sambuc
72423a61ee0SLionel Sambuc# get_makevar var [var ...]
72523a61ee0SLionel Sambuc#	Retrieve the value of a user-settable system make variable
72623a61ee0SLionel Sambucget_makevar()
72723a61ee0SLionel Sambuc{
72823a61ee0SLionel Sambuc	$SOURCEMODE || err 3 "get_makevar must be used in source mode"
72923a61ee0SLionel Sambuc	[ $# -eq 0 ] && err 3 "USAGE: get_makevar var [var ...]"
73023a61ee0SLionel Sambuc
73123a61ee0SLionel Sambuc	for _var in "$@"; do
73223a61ee0SLionel Sambuc		_value="$(echo '.include <bsd.own.mk>' | \
733*0a6a1f1dSLionel Sambuc		    ${MAKE} -f - -V "\${${_var}}")"
73423a61ee0SLionel Sambuc
735*0a6a1f1dSLionel Sambuc		eval ${_var}=\"\${_value}\"
73623a61ee0SLionel Sambuc	done
73723a61ee0SLionel Sambuc}
73823a61ee0SLionel Sambuc
73923a61ee0SLionel Sambuc# detect_x11
74023a61ee0SLionel Sambuc#	Detect if X11 components should be analysed and set values of
74123a61ee0SLionel Sambuc#	relevant variables.
74223a61ee0SLionel Sambucdetect_x11()
74323a61ee0SLionel Sambuc{
74423a61ee0SLionel Sambuc	if $SOURCEMODE; then
74523a61ee0SLionel Sambuc		get_makevar MKX11 X11ROOTDIR X11SRCDIR
74623a61ee0SLionel Sambuc	else
74723a61ee0SLionel Sambuc		if [ -f "${SRC_DIR}/etc/mtree/set.xetc" ]; then
74823a61ee0SLionel Sambuc			MKX11=yes
74923a61ee0SLionel Sambuc			X11ROOTDIR=/this/value/isnt/used/yet
75023a61ee0SLionel Sambuc		else
75123a61ee0SLionel Sambuc			MKX11=no
75223a61ee0SLionel Sambuc			X11ROOTDIR=
75323a61ee0SLionel Sambuc		fi
75423a61ee0SLionel Sambuc		X11SRCDIR=/nonexistent/xsrc
75523a61ee0SLionel Sambuc	fi
75623a61ee0SLionel Sambuc}
75723a61ee0SLionel Sambuc
75823a61ee0SLionel Sambuc#
75923a61ee0SLionel Sambuc#	items
76023a61ee0SLionel Sambuc#	-----
76123a61ee0SLionel Sambuc#
76223a61ee0SLionel Sambuc
76323a61ee0SLionel Sambuc#
76423a61ee0SLionel Sambuc#	Bluetooth
76523a61ee0SLionel Sambuc#
76623a61ee0SLionel Sambuc
76723a61ee0SLionel Sambucadditem bluetooth "Bluetooth configuration is up to date"
76823a61ee0SLionel Sambucdo_bluetooth()
76923a61ee0SLionel Sambuc{
77023a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_bluetooth fix|check"
77123a61ee0SLionel Sambuc	op="$1"
77223a61ee0SLionel Sambuc	failed=0
77323a61ee0SLionel Sambuc
77423a61ee0SLionel Sambuc	populate_dir "${op}" true \
77523a61ee0SLionel Sambuc		"${SRC_DIR}/etc/bluetooth" "${DEST_DIR}/etc/bluetooth" 644 \
77623a61ee0SLionel Sambuc		hosts protocols btattach.conf btdevctl.conf
77723a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
77823a61ee0SLionel Sambuc
77923a61ee0SLionel Sambuc	move_file "${op}" "${DEST_DIR}/var/db/btdev.xml" \
78023a61ee0SLionel Sambuc			"${DEST_DIR}/var/db/btdevctl.plist"
78123a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
78223a61ee0SLionel Sambuc
78323a61ee0SLionel Sambuc	notfixed=""
78423a61ee0SLionel Sambuc	if [ "${op}" = "fix" ]; then
78523a61ee0SLionel Sambuc		notfixed="${NOT_FIXED}"
78623a61ee0SLionel Sambuc	fi
78723a61ee0SLionel Sambuc	for _v in btattach btconfig btdevctl; do
78823a61ee0SLionel Sambuc		if rcvar_is_enabled "${_v}"; then
78923a61ee0SLionel Sambuc			msg \
79023a61ee0SLionel Sambuc    "${_v} is obsolete in rc.conf(5)${notfixed}: use bluetooth=YES"
79123a61ee0SLionel Sambuc			failed=$(( ${failed} + 1 ))
79223a61ee0SLionel Sambuc		fi
79323a61ee0SLionel Sambuc	done
79423a61ee0SLionel Sambuc
79523a61ee0SLionel Sambuc	return ${failed}
79623a61ee0SLionel Sambuc}
79723a61ee0SLionel Sambuc
79823a61ee0SLionel Sambuc#
79923a61ee0SLionel Sambuc#	ddbonpanic
80023a61ee0SLionel Sambuc#
80123a61ee0SLionel Sambucadditem ddbonpanic "verify ddb.onpanic is configured in sysctl.conf"
80223a61ee0SLionel Sambucdo_ddbonpanic()
80323a61ee0SLionel Sambuc{
80423a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_ddbonpanic  fix|check"
80523a61ee0SLionel Sambuc
80623a61ee0SLionel Sambuc	if ${GREP} -E '^#*[[:space:]]*ddb\.onpanic[[:space:]]*\??=[[:space:]]*[[:digit:]]+' \
80723a61ee0SLionel Sambuc		"${DEST_DIR}/etc/sysctl.conf" >/dev/null 2>&1
80823a61ee0SLionel Sambuc	then
80923a61ee0SLionel Sambuc		result=0
81023a61ee0SLionel Sambuc	else
81123a61ee0SLionel Sambuc		if [ "$1" = check ]; then
81223a61ee0SLionel Sambuc			msg \
81323a61ee0SLionel Sambuc    "The ddb.onpanic behaviour is not explicitly specified in /etc/sysctl.conf"
81423a61ee0SLionel Sambuc			result=1
81523a61ee0SLionel Sambuc		else
81623a61ee0SLionel Sambuc			echo >> "${DEST_DIR}/etc/sysctl.conf"
817*0a6a1f1dSLionel Sambuc			${SED} < "${SRC_DIR}/etc/sysctl.conf" \
81823a61ee0SLionel Sambuc			   -e '/^ddb\.onpanic/q' | \
819*0a6a1f1dSLionel Sambuc			       ${SED} -e '1,/^$/d' >> \
82023a61ee0SLionel Sambuc			    "${DEST_DIR}/etc/sysctl.conf"
82123a61ee0SLionel Sambuc			result=$?
82223a61ee0SLionel Sambuc		fi
82323a61ee0SLionel Sambuc	fi
82423a61ee0SLionel Sambuc	return ${result}
82523a61ee0SLionel Sambuc}
82623a61ee0SLionel Sambuc
82723a61ee0SLionel Sambuc#
82823a61ee0SLionel Sambuc#	defaults
82923a61ee0SLionel Sambuc#
83023a61ee0SLionel Sambucadditem defaults "/etc/defaults/ being up to date"
83123a61ee0SLionel Sambucdo_defaults()
83223a61ee0SLionel Sambuc{
83323a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_defaults  fix|check"
83423a61ee0SLionel Sambuc	op="$1"
83523a61ee0SLionel Sambuc	failed=0
83623a61ee0SLionel Sambuc
83723a61ee0SLionel Sambuc	# Except for i386 and amd64, rc.conf(5) should be the same as the
83823a61ee0SLionel Sambuc	# one obtained from a source directory
83923a61ee0SLionel Sambuc	extra_scripts="rc.conf"
84023a61ee0SLionel Sambuc	if [ "$MACHINE" = "i386" -o "$MACHINE" = "amd64" ]; then
84123a61ee0SLionel Sambuc		if $SOURCEMODE; then
84223a61ee0SLionel Sambuc			extra_scripts=	# clear
84323a61ee0SLionel Sambuc
84423a61ee0SLionel Sambuc			# Generate and compare the correct rc.conf(5) file
84523a61ee0SLionel Sambuc			mkdir "${SCRATCHDIR}/defaults"
84623a61ee0SLionel Sambuc
84723a61ee0SLionel Sambuc			cat "${SRC_DIR}/etc/defaults/rc.conf" \
84823a61ee0SLionel Sambuc			    "${SRC_DIR}/etc/etc.${MACHINE}/rc.conf.append" \
84923a61ee0SLionel Sambuc			    > "${SCRATCHDIR}/defaults/rc.conf"
85023a61ee0SLionel Sambuc
85123a61ee0SLionel Sambuc			compare_dir "${op}" "${SCRATCHDIR}/defaults" \
85223a61ee0SLionel Sambuc			    "${DEST_DIR}/etc/defaults" \
85323a61ee0SLionel Sambuc			    444 \
85423a61ee0SLionel Sambuc			    "rc.conf"
85523a61ee0SLionel Sambuc			failed=$(( ${failed} + $? ))
85623a61ee0SLionel Sambuc		fi
85723a61ee0SLionel Sambuc	fi
85823a61ee0SLionel Sambuc
85923a61ee0SLionel Sambuc	compare_dir "$op" "${SRC_DIR}/etc/defaults" "${DEST_DIR}/etc/defaults" \
86023a61ee0SLionel Sambuc		444 \
86184d9c625SLionel Sambuc		daily.conf monthly.conf pkgpath.conf security.conf \
86223a61ee0SLionel Sambuc		weekly.conf ${extra_scripts}
86323a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
86423a61ee0SLionel Sambuc
86523a61ee0SLionel Sambuc	find_file_in_dirlist pf.boot.conf "pf.boot.conf" \
86623a61ee0SLionel Sambuc	    "${SRC_DIR}/usr.sbin/pf/etc/defaults" "${SRC_DIR}/etc/defaults" \
86723a61ee0SLionel Sambuc	    || return 1
86823a61ee0SLionel Sambuc			# ${dir} is set by find_file_in_dirlist()
86923a61ee0SLionel Sambuc	compare_dir "$op" "${dir}" "${DEST_DIR}/etc/defaults" 444 pf.boot.conf
87023a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
87123a61ee0SLionel Sambuc
87223a61ee0SLionel Sambuc	return ${failed}
87323a61ee0SLionel Sambuc}
87423a61ee0SLionel Sambuc
87523a61ee0SLionel Sambuc#
87623a61ee0SLionel Sambuc#	dhcpcd
87723a61ee0SLionel Sambuc#
87823a61ee0SLionel Sambucadditem dhcpcd "dhcpcd configuration is up to date"
87923a61ee0SLionel Sambucdo_dhcpcd()
88023a61ee0SLionel Sambuc{
88123a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_dhcpcd fix|check"
88223a61ee0SLionel Sambuc	op="$1"
88323a61ee0SLionel Sambuc	failed=0
88423a61ee0SLionel Sambuc
88523a61ee0SLionel Sambuc	find_file_in_dirlist dhcpcd.conf "dhcpcd.conf" \
88623a61ee0SLionel Sambuc	    "${SRC_DIR}/external/bsd/dhcpcd/dist" "${SRC_DIR}/etc" || return 1
88723a61ee0SLionel Sambuc			# ${dir} is set by find_file_in_dirlist()
88823a61ee0SLionel Sambuc	populate_dir "$op" true "${dir}" "${DEST_DIR}/etc" 644 dhcpcd.conf
88923a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
89023a61ee0SLionel Sambuc
89123a61ee0SLionel Sambuc	return ${failed}
89223a61ee0SLionel Sambuc}
89323a61ee0SLionel Sambuc
89423a61ee0SLionel Sambuc#
895*0a6a1f1dSLionel Sambuc#	dhcpcdrundir
896*0a6a1f1dSLionel Sambuc#
897*0a6a1f1dSLionel Sambucadditem dhcpcdrundir "accidentaly created /@RUNDIR@ does not exist"
898*0a6a1f1dSLionel Sambucdo_dhcpcdrundir()
899*0a6a1f1dSLionel Sambuc{
900*0a6a1f1dSLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_dhcpcdrundir fix|check"
901*0a6a1f1dSLionel Sambuc	op="$1"
902*0a6a1f1dSLionel Sambuc	failed=0
903*0a6a1f1dSLionel Sambuc
904*0a6a1f1dSLionel Sambuc	if [ -d "${DEST_DIR}/@RUNDIR@" ]; then
905*0a6a1f1dSLionel Sambuc		if [ "${op}" = "check" ]; then
906*0a6a1f1dSLionel Sambuc			msg "Remove eroneously created /@RUNDIR@"
907*0a6a1f1dSLionel Sambuc			failed=1
908*0a6a1f1dSLionel Sambuc		elif ! rm -r "${DEST_DIR}/@RUNDIR@"; then
909*0a6a1f1dSLionel Sambuc			msg "Failed to remove ${DEST_DIR}/@RUNDIR@"
910*0a6a1f1dSLionel Sambuc			failed=1
911*0a6a1f1dSLionel Sambuc		else
912*0a6a1f1dSLionel Sambuc			msg "Removed eroneously created ${DEST_DIR}/@RUNDIR@"
913*0a6a1f1dSLionel Sambuc		fi
914*0a6a1f1dSLionel Sambuc	fi
915*0a6a1f1dSLionel Sambuc	return ${failed}
916*0a6a1f1dSLionel Sambuc}
917*0a6a1f1dSLionel Sambuc
918*0a6a1f1dSLionel Sambuc#
91923a61ee0SLionel Sambuc#	envsys
92023a61ee0SLionel Sambuc#
92123a61ee0SLionel Sambucadditem envsys "envsys configuration is up to date"
92223a61ee0SLionel Sambucdo_envsys()
92323a61ee0SLionel Sambuc{
92423a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_envsys fix|check"
92523a61ee0SLionel Sambuc	op="$1"
92623a61ee0SLionel Sambuc	failed=0
92723a61ee0SLionel Sambuc
92823a61ee0SLionel Sambuc	populate_dir "$op" true "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
92923a61ee0SLionel Sambuc		envsys.conf
93023a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
93123a61ee0SLionel Sambuc
93223a61ee0SLionel Sambuc	populate_dir "$op" true "${SRC_DIR}/etc/powerd/scripts" \
93323a61ee0SLionel Sambuc		"${DEST_DIR}/etc/powerd/scripts" 555 sensor_battery \
93423a61ee0SLionel Sambuc		sensor_drive sensor_fan sensor_indicator sensor_power \
93523a61ee0SLionel Sambuc		sensor_resistance sensor_temperature sensor_voltage
93623a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
93723a61ee0SLionel Sambuc
93823a61ee0SLionel Sambuc	return ${failed}
93923a61ee0SLionel Sambuc}
94023a61ee0SLionel Sambuc
94123a61ee0SLionel Sambuc#
94223a61ee0SLionel Sambuc#	X11 fontconfig
94323a61ee0SLionel Sambuc#
94423a61ee0SLionel Sambucadditem fontconfig "X11 font configuration is up to date"
94523a61ee0SLionel Sambucdo_fontconfig()
94623a61ee0SLionel Sambuc{
94723a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_fontconfig fix|check"
94823a61ee0SLionel Sambuc	op="$1"
94923a61ee0SLionel Sambuc	failed=0
95023a61ee0SLionel Sambuc
95184d9c625SLionel Sambuc	# First, check for updates we can handle.
95284d9c625SLionel Sambuc	if ! $SOURCEMODE; then
95384d9c625SLionel Sambuc		FONTCONFIG_DIR="${SRC_DIR}/etc/fonts/conf.avail"
95484d9c625SLionel Sambuc	else
95584d9c625SLionel Sambuc		FONTCONFIG_DIR="${XSRC_DIR}/external/mit/fontconfig/dist/conf.d"
95623a61ee0SLionel Sambuc	fi
95723a61ee0SLionel Sambuc
958*0a6a1f1dSLionel Sambuc	if [ ! -d "${FONTCONFIG_DIR}" ]; then
959*0a6a1f1dSLionel Sambuc		msg "${FONTCONFIG_DIR} is not a directory; skipping check"
960*0a6a1f1dSLionel Sambuc		return 0
961*0a6a1f1dSLionel Sambuc	fi
962*0a6a1f1dSLionel Sambuc
96384d9c625SLionel Sambuc	populate_dir "$op" false "${FONTCONFIG_DIR}" "${DEST_DIR}/etc/fonts/conf.avail" 444 \
96484d9c625SLionel Sambuc		10-autohint.conf \
96584d9c625SLionel Sambuc		10-no-sub-pixel.conf \
96684d9c625SLionel Sambuc		10-scale-bitmap-fonts.conf \
96784d9c625SLionel Sambuc		10-sub-pixel-bgr.conf \
96884d9c625SLionel Sambuc		10-sub-pixel-rgb.conf \
96984d9c625SLionel Sambuc		10-sub-pixel-vbgr.conf \
97084d9c625SLionel Sambuc		10-sub-pixel-vrgb.conf \
97184d9c625SLionel Sambuc		10-unhinted.conf \
97284d9c625SLionel Sambuc		11-lcdfilter-default.conf \
97384d9c625SLionel Sambuc		11-lcdfilter-legacy.conf \
97484d9c625SLionel Sambuc		11-lcdfilter-light.conf \
97584d9c625SLionel Sambuc		20-unhint-small-vera.conf \
97684d9c625SLionel Sambuc		25-unhint-nonlatin.conf \
97784d9c625SLionel Sambuc		30-metric-aliases.conf \
97884d9c625SLionel Sambuc		30-urw-aliases.conf \
97984d9c625SLionel Sambuc		40-nonlatin.conf \
98084d9c625SLionel Sambuc		45-latin.conf \
98184d9c625SLionel Sambuc		49-sansserif.conf \
98284d9c625SLionel Sambuc		50-user.conf \
98384d9c625SLionel Sambuc		51-local.conf \
98484d9c625SLionel Sambuc		60-latin.conf \
98584d9c625SLionel Sambuc		65-fonts-persian.conf \
98684d9c625SLionel Sambuc		65-khmer.conf \
98784d9c625SLionel Sambuc		65-nonlatin.conf \
98884d9c625SLionel Sambuc		69-unifont.conf \
98984d9c625SLionel Sambuc		70-no-bitmaps.conf \
99084d9c625SLionel Sambuc		70-yes-bitmaps.conf \
99184d9c625SLionel Sambuc		80-delicious.conf \
99284d9c625SLionel Sambuc		90-synthetic.conf
99384d9c625SLionel Sambuc	failed=$(( ${failed} + $? ))
99484d9c625SLionel Sambuc
995*0a6a1f1dSLionel Sambuc	if ! $SOURCEMODE; then
996*0a6a1f1dSLionel Sambuc		FONTS_DIR="${SRC_DIR}/etc/fonts"
997*0a6a1f1dSLionel Sambuc	else
998*0a6a1f1dSLionel Sambuc		FONTS_DIR="${SRC_DIR}/external/mit/xorg/lib/fontconfig/etc"
999*0a6a1f1dSLionel Sambuc	fi
1000*0a6a1f1dSLionel Sambuc
1001*0a6a1f1dSLionel Sambuc	populate_dir "$op" false "${FONTS_DIR}" "${DEST_DIR}/etc/fonts" 444 \
1002*0a6a1f1dSLionel Sambuc		fonts.conf
1003*0a6a1f1dSLionel Sambuc	failed=$(( ${failed} + $? ))
1004*0a6a1f1dSLionel Sambuc
100584d9c625SLionel Sambuc	# We can't modify conf.d easily; someone might have removed a file.
100684d9c625SLionel Sambuc
100784d9c625SLionel Sambuc	conf_d_failed=0
100884d9c625SLionel Sambuc	# Look for old files that need to be deleted.
100984d9c625SLionel Sambuc	if [ -f "${DEST_DIR}/etc/fonts/conf.d/10-unhinted.conf" -a \
101084d9c625SLionel Sambuc	     -f "${DEST_DIR}/etc/fonts/conf.d/10-autohint.conf" ]; then
101184d9c625SLionel Sambuc		conf_d_failed=1
101284d9c625SLionel Sambuc		failed=$(( ${failed} + 1 ))
101384d9c625SLionel Sambuc	fi
101484d9c625SLionel Sambuc
101584d9c625SLionel Sambuc	if [ "$conf_d_failed" = 1 ]; then
101623a61ee0SLionel Sambuc		msg \
101723a61ee0SLionel Sambuc    "Broken fontconfig configuration found; please delete these files"
101823a61ee0SLionel Sambuc		msg \
1019*0a6a1f1dSLionel Sambuc    "in the ${DEST_DIR}/etc/fonts/conf.d/ subdirectory:"
102023a61ee0SLionel Sambuc		msg \
102123a61ee0SLionel Sambuc    "   10-autohint.conf 10-no-sub-pixel.conf 10-sub-pixel-bgr.conf"
102223a61ee0SLionel Sambuc		msg \
102323a61ee0SLionel Sambuc    "   10-sub-pixel-rgb.conf 10-sub-pixel-vbgr.conf"
102423a61ee0SLionel Sambuc		msg \
102523a61ee0SLionel Sambuc    "   10-sub-pixel-vrgb.conf 10-unhinted.conf 25-unhint-nonlatin.conf"
102623a61ee0SLionel Sambuc		msg \
102723a61ee0SLionel Sambuc    "   65-khmer.conf 70-no-bitmaps.conf 70-yes-bitmaps.conf"
102823a61ee0SLionel Sambuc		msg \
102923a61ee0SLionel Sambuc    "(This warning only appears if both the 10-unhinted.conf and"
103023a61ee0SLionel Sambuc		msg \
103123a61ee0SLionel Sambuc    "10-autohint.conf files are present."
103223a61ee0SLionel Sambuc	fi
103323a61ee0SLionel Sambuc
103423a61ee0SLionel Sambuc	return ${failed}
103523a61ee0SLionel Sambuc}
103623a61ee0SLionel Sambuc
103723a61ee0SLionel Sambuc#
103823a61ee0SLionel Sambuc#	gid
103923a61ee0SLionel Sambuc#
104023a61ee0SLionel Sambucadditem gid "required groups in /etc/group"
104123a61ee0SLionel Sambucdo_gid()
104223a61ee0SLionel Sambuc{
104323a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_gid  fix|check"
104423a61ee0SLionel Sambuc
1045*0a6a1f1dSLionel Sambuc	check_ids "$1" groups "${DEST_DIR}/etc/group" \
1046*0a6a1f1dSLionel Sambuc	    "${SRC_DIR}/etc/group" 14 \
104784d9c625SLionel Sambuc	    named ntpd sshd SKIP _pflogd _rwhod staff _proxy _timedc \
104884d9c625SLionel Sambuc	    _sdpd _httpd _mdnsd _tests _tcpdump _tss _gpio _rtadvd
104923a61ee0SLionel Sambuc}
105023a61ee0SLionel Sambuc
105123a61ee0SLionel Sambuc#
105223a61ee0SLionel Sambuc#	gpio
105323a61ee0SLionel Sambuc#
105423a61ee0SLionel Sambucadditem gpio "gpio configuration is up to date"
105523a61ee0SLionel Sambucdo_gpio()
105623a61ee0SLionel Sambuc{
105723a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_gpio fix|check"
105823a61ee0SLionel Sambuc	op="$1"
105923a61ee0SLionel Sambuc	failed=0
106023a61ee0SLionel Sambuc
106123a61ee0SLionel Sambuc	populate_dir "$op" true "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
106223a61ee0SLionel Sambuc		gpio.conf
106323a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
106423a61ee0SLionel Sambuc
106523a61ee0SLionel Sambuc	return ${failed}
106623a61ee0SLionel Sambuc}
106723a61ee0SLionel Sambuc
106823a61ee0SLionel Sambuc#
106923a61ee0SLionel Sambuc#	hosts
107023a61ee0SLionel Sambuc#
107123a61ee0SLionel Sambucadditem hosts "/etc/hosts being up to date"
107223a61ee0SLionel Sambucdo_hosts()
107323a61ee0SLionel Sambuc{
107423a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_hosts  fix|check"
107523a61ee0SLionel Sambuc
107623a61ee0SLionel Sambuc	modify_file "$1" "${DEST_DIR}/etc/hosts" "${SCRATCHDIR}/hosts" '
107723a61ee0SLionel Sambuc		/^(127\.0\.0\.1|::1)[ 	]+[^\.]*$/ {
107823a61ee0SLionel Sambuc			print $0, "localhost."
107923a61ee0SLionel Sambuc			next
108023a61ee0SLionel Sambuc		}
108123a61ee0SLionel Sambuc		{ print }
108223a61ee0SLionel Sambuc	'
108323a61ee0SLionel Sambuc	return $?
108423a61ee0SLionel Sambuc}
108523a61ee0SLionel Sambuc
108623a61ee0SLionel Sambuc#
108723a61ee0SLionel Sambuc#	iscsi
108823a61ee0SLionel Sambuc#
108923a61ee0SLionel Sambucadditem iscsi "/etc/iscsi is populated"
109023a61ee0SLionel Sambucdo_iscsi()
109123a61ee0SLionel Sambuc{
109223a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_iscsi  fix|check"
109323a61ee0SLionel Sambuc
109423a61ee0SLionel Sambuc	populate_dir "${op}" true \
109523a61ee0SLionel Sambuc	    "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 600 auths
109623a61ee0SLionel Sambuc	populate_dir "${op}" true \
109723a61ee0SLionel Sambuc	    "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 644 targets
109823a61ee0SLionel Sambuc	return $?
109923a61ee0SLionel Sambuc}
110023a61ee0SLionel Sambuc
110123a61ee0SLionel Sambuc#
110223a61ee0SLionel Sambuc#	makedev
110323a61ee0SLionel Sambuc#
110423a61ee0SLionel Sambucadditem makedev "/dev/MAKEDEV being up to date"
110523a61ee0SLionel Sambucdo_makedev()
110623a61ee0SLionel Sambuc{
110723a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_makedev   fix|check"
110823a61ee0SLionel Sambuc	failed=0
110923a61ee0SLionel Sambuc
111023a61ee0SLionel Sambuc	if [ -f "${SRC_DIR}/etc/MAKEDEV.tmpl" ]; then
111123a61ee0SLionel Sambuc			# generate MAKEDEV from source if source is available
111223a61ee0SLionel Sambuc		env MACHINE="${MACHINE}" \
111323a61ee0SLionel Sambuc		    MACHINE_ARCH="${MACHINE_ARCH}" \
111423a61ee0SLionel Sambuc		    NETBSDSRCDIR="${SRC_DIR}" \
111523a61ee0SLionel Sambuc		    ${AWK} -f "${SRC_DIR}/etc/MAKEDEV.awk" \
111623a61ee0SLionel Sambuc		    "${SRC_DIR}/etc/MAKEDEV.tmpl" > "${SCRATCHDIR}/MAKEDEV"
111723a61ee0SLionel Sambuc	fi
111823a61ee0SLionel Sambuc
111923a61ee0SLionel Sambuc	find_file_in_dirlist MAKEDEV "MAKEDEV" \
112023a61ee0SLionel Sambuc	    "${SCRATCHDIR}" "${SRC_DIR}/dev" \
112123a61ee0SLionel Sambuc	    || return 1
112223a61ee0SLionel Sambuc			# ${dir} is set by find_file_in_dirlist()
112323a61ee0SLionel Sambuc	compare_dir "$1" "${dir}" "${DEST_DIR}/dev" 555 MAKEDEV
112423a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
112523a61ee0SLionel Sambuc
112623a61ee0SLionel Sambuc	find_file_in_dirlist MAKEDEV.local "MAKEDEV.local" \
112723a61ee0SLionel Sambuc	    "${SRC_DIR}/etc" "${SRC_DIR}/dev" \
112823a61ee0SLionel Sambuc	    || return 1
112923a61ee0SLionel Sambuc			# ${dir} is set by find_file_in_dirlist()
113023a61ee0SLionel Sambuc	compare_dir "$1" "${dir}" "${DEST_DIR}/dev" 555 MAKEDEV.local
113123a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
113223a61ee0SLionel Sambuc
113323a61ee0SLionel Sambuc	return ${failed}
113423a61ee0SLionel Sambuc}
113523a61ee0SLionel Sambuc
113623a61ee0SLionel Sambuc#
113723a61ee0SLionel Sambuc#	motd
113823a61ee0SLionel Sambuc#
113923a61ee0SLionel Sambucadditem motd "contents of motd"
114023a61ee0SLionel Sambucdo_motd()
114123a61ee0SLionel Sambuc{
114223a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_motd  fix|check"
114323a61ee0SLionel Sambuc
114423a61ee0SLionel Sambuc	if ${GREP} -i 'http://www.NetBSD.org/Misc/send-pr.html' \
114523a61ee0SLionel Sambuc		"${DEST_DIR}/etc/motd" >/dev/null 2>&1 \
114623a61ee0SLionel Sambuc	    || ${GREP} -i 'http://www.NetBSD.org/support/send-pr.html' \
114723a61ee0SLionel Sambuc		"${DEST_DIR}/etc/motd" >/dev/null 2>&1
114823a61ee0SLionel Sambuc	then
114923a61ee0SLionel Sambuc		tmp1="$(mktemp /tmp/postinstall.motd.XXXXXXXX)"
115023a61ee0SLionel Sambuc		tmp2="$(mktemp /tmp/postinstall.motd.XXXXXXXX)"
1151*0a6a1f1dSLionel Sambuc		${SED} '1,2d' <"${SRC_DIR}/etc/motd" >"${tmp1}"
1152*0a6a1f1dSLionel Sambuc		${SED} '1,2d' <"${DEST_DIR}/etc/motd" >"${tmp2}"
115323a61ee0SLionel Sambuc
115423a61ee0SLionel Sambuc		if [ "$1" = check ]; then
115523a61ee0SLionel Sambuc			cmp -s "${tmp1}" "${tmp2}"
115623a61ee0SLionel Sambuc			result=$?
115723a61ee0SLionel Sambuc			if [ "${result}" -ne 0 ]; then
115823a61ee0SLionel Sambuc				msg \
115923a61ee0SLionel Sambuc    "Bug reporting messages do not seem to match the installed release"
116023a61ee0SLionel Sambuc			fi
116123a61ee0SLionel Sambuc		else
116223a61ee0SLionel Sambuc			head -n 2 "${DEST_DIR}/etc/motd" >"${tmp1}"
1163*0a6a1f1dSLionel Sambuc			${SED} '1,2d' <"${SRC_DIR}/etc/motd" >>"${tmp1}"
116423a61ee0SLionel Sambuc			cp "${tmp1}" "${DEST_DIR}/etc/motd"
116523a61ee0SLionel Sambuc			result=0
116623a61ee0SLionel Sambuc		fi
116723a61ee0SLionel Sambuc
116823a61ee0SLionel Sambuc		rm -f "${tmp1}" "${tmp2}"
116923a61ee0SLionel Sambuc	else
117023a61ee0SLionel Sambuc		result=0
117123a61ee0SLionel Sambuc	fi
117223a61ee0SLionel Sambuc
117323a61ee0SLionel Sambuc	return ${result}
117423a61ee0SLionel Sambuc}
117523a61ee0SLionel Sambuc
117623a61ee0SLionel Sambuc#
117723a61ee0SLionel Sambuc#	mtree
117823a61ee0SLionel Sambuc#
117923a61ee0SLionel Sambucadditem mtree "/etc/mtree/ being up to date"
118023a61ee0SLionel Sambucdo_mtree()
118123a61ee0SLionel Sambuc{
118223a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_mtree  fix|check"
118323a61ee0SLionel Sambuc	failed=0
118423a61ee0SLionel Sambuc
118523a61ee0SLionel Sambuc	compare_dir "$1" "${SRC_DIR}/etc/mtree" "${DEST_DIR}/etc/mtree" 444 special
118623a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
118723a61ee0SLionel Sambuc
118823a61ee0SLionel Sambuc	if ! $SOURCEMODE; then
118923a61ee0SLionel Sambuc		MTREE_DIR="${SRC_DIR}/etc/mtree"
119023a61ee0SLionel Sambuc	else
1191*0a6a1f1dSLionel Sambuc		/bin/rm -rf "${SCRATCHDIR}/obj"
1192*0a6a1f1dSLionel Sambuc		mkdir "${SCRATCHDIR}/obj"
1193*0a6a1f1dSLionel Sambuc		${MAKE} -s -C "${SRC_DIR}/etc/mtree" TOOL_AWK="${AWK}" \
1194*0a6a1f1dSLionel Sambuc		    MAKEOBJDIR="${SCRATCHDIR}/obj" emit_dist_file > \
119523a61ee0SLionel Sambuc		    "${SCRATCHDIR}/NetBSD.dist"
119623a61ee0SLionel Sambuc		MTREE_DIR="${SCRATCHDIR}"
1197*0a6a1f1dSLionel Sambuc		/bin/rm -rf "${SCRATCHDIR}/obj"
119823a61ee0SLionel Sambuc	fi
119923a61ee0SLionel Sambuc	compare_dir "$1" "${MTREE_DIR}" "${DEST_DIR}/etc/mtree" 444 NetBSD.dist
120023a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
120123a61ee0SLionel Sambuc
120223a61ee0SLionel Sambuc	return ${failed}
120323a61ee0SLionel Sambuc}
120423a61ee0SLionel Sambuc
120523a61ee0SLionel Sambuc#
120623a61ee0SLionel Sambuc#	named
120723a61ee0SLionel Sambuc#
120823a61ee0SLionel Sambucadditem named "named configuration update"
120923a61ee0SLionel Sambucdo_named()
121023a61ee0SLionel Sambuc{
121123a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_named  fix|check"
121223a61ee0SLionel Sambuc	op="$1"
121323a61ee0SLionel Sambuc
121423a61ee0SLionel Sambuc	move_file "${op}" \
121523a61ee0SLionel Sambuc		"${DEST_DIR}/etc/namedb/named.conf" \
121623a61ee0SLionel Sambuc		"${DEST_DIR}/etc/named.conf"
121723a61ee0SLionel Sambuc
121823a61ee0SLionel Sambuc	compare_dir "${op}" "${SRC_DIR}/etc/namedb" "${DEST_DIR}/etc/namedb" \
121923a61ee0SLionel Sambuc		644 \
122023a61ee0SLionel Sambuc		root.cache
122123a61ee0SLionel Sambuc}
122223a61ee0SLionel Sambuc
122323a61ee0SLionel Sambuc#
122423a61ee0SLionel Sambuc#	pam
122523a61ee0SLionel Sambuc#
122623a61ee0SLionel Sambucadditem pam "/etc/pam.d is populated"
122723a61ee0SLionel Sambucdo_pam()
122823a61ee0SLionel Sambuc{
122923a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_pam  fix|check"
123023a61ee0SLionel Sambuc	op="$1"
123123a61ee0SLionel Sambuc	failed=0
123223a61ee0SLionel Sambuc
123323a61ee0SLionel Sambuc	populate_dir "${op}" true "${SRC_DIR}/etc/pam.d" \
123423a61ee0SLionel Sambuc		"${DEST_DIR}/etc/pam.d" 644 \
123523a61ee0SLionel Sambuc		README display_manager ftpd gdm imap kde login other passwd \
123623a61ee0SLionel Sambuc		pop3 ppp rexecd rsh sshd su system telnetd xdm xserver
123723a61ee0SLionel Sambuc
123823a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
123923a61ee0SLionel Sambuc
124023a61ee0SLionel Sambuc	return ${failed}
124123a61ee0SLionel Sambuc}
124223a61ee0SLionel Sambuc
124323a61ee0SLionel Sambuc#
124423a61ee0SLionel Sambuc#	periodic
124523a61ee0SLionel Sambuc#
124623a61ee0SLionel Sambucadditem periodic "/etc/{daily,weekly,monthly,security} being up to date"
124723a61ee0SLionel Sambucdo_periodic()
124823a61ee0SLionel Sambuc{
124923a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_periodic  fix|check"
125023a61ee0SLionel Sambuc
125123a61ee0SLionel Sambuc	compare_dir "$1" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
125223a61ee0SLionel Sambuc		daily weekly monthly security
125323a61ee0SLionel Sambuc}
125423a61ee0SLionel Sambuc
125523a61ee0SLionel Sambuc#
125623a61ee0SLionel Sambuc#	pf
125723a61ee0SLionel Sambuc#
125823a61ee0SLionel Sambucadditem pf "pf configuration being up to date"
125923a61ee0SLionel Sambucdo_pf()
126023a61ee0SLionel Sambuc{
126123a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_pf  fix|check"
126223a61ee0SLionel Sambuc	op="$1"
126323a61ee0SLionel Sambuc	failed=0
126423a61ee0SLionel Sambuc
126523a61ee0SLionel Sambuc	find_file_in_dirlist pf.os "pf.os" \
126623a61ee0SLionel Sambuc	    "${SRC_DIR}/dist/pf/etc" "${SRC_DIR}/etc" \
126723a61ee0SLionel Sambuc	    || return 1
126823a61ee0SLionel Sambuc			# ${dir} is set by find_file_in_dirlist()
126923a61ee0SLionel Sambuc	populate_dir "${op}" true \
127023a61ee0SLionel Sambuc	    "${dir}" "${DEST_DIR}/etc" 644 \
127123a61ee0SLionel Sambuc	    pf.conf
127223a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
127323a61ee0SLionel Sambuc
127423a61ee0SLionel Sambuc	compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 pf.os
127523a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
127623a61ee0SLionel Sambuc
127723a61ee0SLionel Sambuc	return ${failed}
127823a61ee0SLionel Sambuc}
127923a61ee0SLionel Sambuc
128023a61ee0SLionel Sambuc#
128123a61ee0SLionel Sambuc#	pwd_mkdb
128223a61ee0SLionel Sambuc#
128323a61ee0SLionel Sambucadditem pwd_mkdb "passwd database version"
128423a61ee0SLionel Sambucdo_pwd_mkdb()
128523a61ee0SLionel Sambuc{
128623a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_pwd_mkdb  fix|check"
128723a61ee0SLionel Sambuc	op="$1"
128823a61ee0SLionel Sambuc	failed=0
128923a61ee0SLionel Sambuc
129023a61ee0SLionel Sambuc	# XXX Ideally, we should figure out the endianness of the
129123a61ee0SLionel Sambuc	# target machine, and add "-E B"/"-E L" to the db(1) flags,
129223a61ee0SLionel Sambuc	# and "-B"/"-L" to the pwd_mkdb(8) flags if the target is not
129323a61ee0SLionel Sambuc	# the same as the host machine.  It probably doesn't matter,
129423a61ee0SLionel Sambuc	# because we don't expect "postinstall fix pwd_mkdb" to be
129523a61ee0SLionel Sambuc	# invoked during a cross build.
129623a61ee0SLionel Sambuc
129723a61ee0SLionel Sambuc	set -- $(${DB} -q -Sb -Ub -To -N hash "${DEST_DIR}/etc/pwd.db" \
129823a61ee0SLionel Sambuc		'VERSION\0')
129923a61ee0SLionel Sambuc	case "$2" in
130023a61ee0SLionel Sambuc	'\001\000\000\000') return 0 ;; # version 1, little-endian
130123a61ee0SLionel Sambuc	'\000\000\000\001') return 0 ;; # version 1, big-endian
130223a61ee0SLionel Sambuc	esac
130323a61ee0SLionel Sambuc
130423a61ee0SLionel Sambuc	if [ "${op}" = "check" ]; then
130523a61ee0SLionel Sambuc		msg "Update format of passwd database"
130623a61ee0SLionel Sambuc		failed=1
130723a61ee0SLionel Sambuc	elif ! ${PWD_MKDB} -V 1 -d "${DEST_DIR:-/}" \
130823a61ee0SLionel Sambuc			"${DEST_DIR}/etc/master.passwd";
130923a61ee0SLionel Sambuc	then
131023a61ee0SLionel Sambuc		msg "Can't update format of passwd database"
131123a61ee0SLionel Sambuc		failed=1
131223a61ee0SLionel Sambuc	else
131323a61ee0SLionel Sambuc		msg "Updated format of passwd database"
131423a61ee0SLionel Sambuc	fi
131523a61ee0SLionel Sambuc
131623a61ee0SLionel Sambuc	return ${failed}
131723a61ee0SLionel Sambuc}
131823a61ee0SLionel Sambuc
131923a61ee0SLionel Sambuc#
132023a61ee0SLionel Sambuc#	rc
132123a61ee0SLionel Sambuc#
1322*0a6a1f1dSLionel Sambuc
1323*0a6a1f1dSLionel Sambuc# XXX Generate these from ../../distrib/sets/lists
1324*0a6a1f1dSLionel Sambucrc_644_files="
1325*0a6a1f1dSLionel Sambucrc
1326*0a6a1f1dSLionel Sambucrc.subr
1327*0a6a1f1dSLionel Sambucrc.shutdown
1328*0a6a1f1dSLionel Sambuc"
1329*0a6a1f1dSLionel Sambucrc_555_files="
1330*0a6a1f1dSLionel SambucDAEMON
1331*0a6a1f1dSLionel SambucDISKS
1332*0a6a1f1dSLionel SambucLOGIN
1333*0a6a1f1dSLionel SambucNETWORKING
1334*0a6a1f1dSLionel SambucSERVERS
1335*0a6a1f1dSLionel Sambucaccounting
1336*0a6a1f1dSLionel Sambucaltqd
1337*0a6a1f1dSLionel Sambucamd
1338*0a6a1f1dSLionel Sambucapmd
1339*0a6a1f1dSLionel Sambucbluetooth
1340*0a6a1f1dSLionel Sambucbootconf.sh
1341*0a6a1f1dSLionel Sambucbootparams
1342*0a6a1f1dSLionel Sambucccd
1343*0a6a1f1dSLionel Sambuccgd
1344*0a6a1f1dSLionel Sambuccleartmp
1345*0a6a1f1dSLionel Sambuccron
1346*0a6a1f1dSLionel Sambucdevpubd
1347*0a6a1f1dSLionel Sambucdhclient
1348*0a6a1f1dSLionel Sambucdhcpcd
1349*0a6a1f1dSLionel Sambucdhcpd
1350*0a6a1f1dSLionel Sambucdhcrelay
1351*0a6a1f1dSLionel Sambucdmesg
1352*0a6a1f1dSLionel Sambucdowninterfaces
1353*0a6a1f1dSLionel Sambucenvsys
1354*0a6a1f1dSLionel Sambucfsck
1355*0a6a1f1dSLionel Sambucfsck_root
1356*0a6a1f1dSLionel Sambucftp_proxy
1357*0a6a1f1dSLionel Sambucftpd
1358*0a6a1f1dSLionel Sambucgpio
1359*0a6a1f1dSLionel Sambuchostapd
1360*0a6a1f1dSLionel Sambuchttpd
1361*0a6a1f1dSLionel Sambucidentd
1362*0a6a1f1dSLionel Sambucifwatchd
1363*0a6a1f1dSLionel Sambucinetd
1364*0a6a1f1dSLionel Sambucipfilter
1365*0a6a1f1dSLionel Sambucipfs
1366*0a6a1f1dSLionel Sambucipmon
1367*0a6a1f1dSLionel Sambucipnat
1368*0a6a1f1dSLionel Sambucipsec
1369*0a6a1f1dSLionel Sambucirdaattach
1370*0a6a1f1dSLionel Sambuciscsi_target
1371*0a6a1f1dSLionel Sambuciscsid
1372*0a6a1f1dSLionel Sambucisdnd
1373*0a6a1f1dSLionel Sambucisibootd
1374*0a6a1f1dSLionel Sambuckdc
1375*0a6a1f1dSLionel Sambucldconfig
1376*0a6a1f1dSLionel Sambucldpd
1377*0a6a1f1dSLionel Sambuclocal
1378*0a6a1f1dSLionel Sambuclpd
1379*0a6a1f1dSLionel Sambuclvm
1380*0a6a1f1dSLionel Sambucmakemandb
1381*0a6a1f1dSLionel Sambucmdnsd
1382*0a6a1f1dSLionel Sambucmixerctl
1383*0a6a1f1dSLionel Sambucmodules
1384*0a6a1f1dSLionel Sambucmopd
1385*0a6a1f1dSLionel Sambucmotd
1386*0a6a1f1dSLionel Sambucmountall
1387*0a6a1f1dSLionel Sambucmountcritlocal
1388*0a6a1f1dSLionel Sambucmountcritremote
1389*0a6a1f1dSLionel Sambucmountd
1390*0a6a1f1dSLionel Sambucmoused
1391*0a6a1f1dSLionel Sambucmrouted
1392*0a6a1f1dSLionel Sambucnamed
1393*0a6a1f1dSLionel Sambucndbootd
1394*0a6a1f1dSLionel Sambucnetwork
1395*0a6a1f1dSLionel Sambucnewsyslog
1396*0a6a1f1dSLionel Sambucnfsd
1397*0a6a1f1dSLionel Sambucnfslocking
1398*0a6a1f1dSLionel Sambucnpf
1399*0a6a1f1dSLionel Sambucntpd
1400*0a6a1f1dSLionel Sambucntpdate
1401*0a6a1f1dSLionel Sambucperusertmp
1402*0a6a1f1dSLionel Sambucpf
1403*0a6a1f1dSLionel Sambucpf_boot
1404*0a6a1f1dSLionel Sambucpflogd
1405*0a6a1f1dSLionel Sambucpostfix
1406*0a6a1f1dSLionel Sambucpowerd
1407*0a6a1f1dSLionel Sambucppp
1408*0a6a1f1dSLionel Sambucpwcheck
1409*0a6a1f1dSLionel Sambucquota
1410*0a6a1f1dSLionel Sambucracoon
1411*0a6a1f1dSLionel Sambucraidframe
1412*0a6a1f1dSLionel Sambucraidframeparity
1413*0a6a1f1dSLionel Sambucrandom_seed
1414*0a6a1f1dSLionel Sambucrarpd
1415*0a6a1f1dSLionel Sambucrbootd
1416*0a6a1f1dSLionel Sambucresize_root
1417*0a6a1f1dSLionel Sambucrndctl
1418*0a6a1f1dSLionel Sambucroot
1419*0a6a1f1dSLionel Sambucroute6d
1420*0a6a1f1dSLionel Sambucrouted
1421*0a6a1f1dSLionel Sambucrpcbind
1422*0a6a1f1dSLionel Sambucrtadvd
1423*0a6a1f1dSLionel Sambucrtclocaltime
1424*0a6a1f1dSLionel Sambucrwho
1425*0a6a1f1dSLionel Sambucsavecore
1426*0a6a1f1dSLionel Sambucscreenblank
1427*0a6a1f1dSLionel Sambucsecurelevel
1428*0a6a1f1dSLionel Sambucsshd
1429*0a6a1f1dSLionel Sambucstaticroute
1430*0a6a1f1dSLionel Sambucswap1
1431*0a6a1f1dSLionel Sambucswap2
1432*0a6a1f1dSLionel Sambucsysctl
1433*0a6a1f1dSLionel Sambucsysdb
1434*0a6a1f1dSLionel Sambucsyslogd
1435*0a6a1f1dSLionel Sambuctimed
1436*0a6a1f1dSLionel Sambuctpctl
1437*0a6a1f1dSLionel Sambucttys
1438*0a6a1f1dSLionel Sambucveriexec
1439*0a6a1f1dSLionel Sambucvirecover
1440*0a6a1f1dSLionel Sambucwdogctl
1441*0a6a1f1dSLionel Sambucwpa_supplicant
1442*0a6a1f1dSLionel Sambucwscons
1443*0a6a1f1dSLionel Sambucwsmoused
1444*0a6a1f1dSLionel Sambucypbind
1445*0a6a1f1dSLionel Sambucyppasswdd
1446*0a6a1f1dSLionel Sambucypserv
1447*0a6a1f1dSLionel Sambuc"
1448*0a6a1f1dSLionel Sambucrc_obsolete_files="
1449*0a6a1f1dSLionel SambucNETWORK
1450*0a6a1f1dSLionel Sambucbtattach
1451*0a6a1f1dSLionel Sambucbtconfig
1452*0a6a1f1dSLionel Sambucbtcontrol
1453*0a6a1f1dSLionel Sambucbtdevctl
1454*0a6a1f1dSLionel Sambucbthcid
1455*0a6a1f1dSLionel Sambucbtuartd
1456*0a6a1f1dSLionel Sambucdaemon
1457*0a6a1f1dSLionel Sambucfsck.sh
1458*0a6a1f1dSLionel Sambucgated
1459*0a6a1f1dSLionel Sambuckerberos
1460*0a6a1f1dSLionel Sambuclogin
1461*0a6a1f1dSLionel Sambucnfsiod
1462*0a6a1f1dSLionel Sambucpoffd
1463*0a6a1f1dSLionel Sambucportmap
1464*0a6a1f1dSLionel Sambucsdpd
1465*0a6a1f1dSLionel Sambucservers
1466*0a6a1f1dSLionel Sambucsunndd
1467*0a6a1f1dSLionel Sambucsystemfs
1468*0a6a1f1dSLionel Sambucxntpd
1469*0a6a1f1dSLionel Sambuc"
1470*0a6a1f1dSLionel Sambucrc_obsolete_vars="
1471*0a6a1f1dSLionel Sambucamd amd_master
1472*0a6a1f1dSLionel Sambucbtcontrol btcontrol_devices
1473*0a6a1f1dSLionel Sambuccritical_filesystems critical_filesystems_beforenet
1474*0a6a1f1dSLionel Sambucmountcritlocal mountcritremote
1475*0a6a1f1dSLionel Sambucnetwork ip6forwarding
1476*0a6a1f1dSLionel Sambucnetwork nfsiod_flags
1477*0a6a1f1dSLionel Sambucsdpd sdpd_control
1478*0a6a1f1dSLionel Sambucsdpd sdpd_groupname
1479*0a6a1f1dSLionel Sambucsdpd sdpd_username
1480*0a6a1f1dSLionel Sambucsysctl defcorename
1481*0a6a1f1dSLionel Sambuc"
1482*0a6a1f1dSLionel Sambuc
148323a61ee0SLionel Sambucadditem rc "/etc/rc* and /etc/rc.d/ being up to date"
148423a61ee0SLionel Sambucdo_rc()
148523a61ee0SLionel Sambuc{
148623a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_rc  fix|check"
148723a61ee0SLionel Sambuc	op="$1"
148823a61ee0SLionel Sambuc	failed=0
148923a61ee0SLionel Sambuc	generated_scripts=""
149023a61ee0SLionel Sambuc	if [ "${MKX11}" != "no" ]; then
149123a61ee0SLionel Sambuc		generated_scripts="${generated_scripts} xdm xfs"
149223a61ee0SLionel Sambuc	fi
149323a61ee0SLionel Sambuc
149423a61ee0SLionel Sambuc	compare_dir "${op}" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
1495*0a6a1f1dSLionel Sambuc		${rc_644_files}
149623a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
149723a61ee0SLionel Sambuc
149823a61ee0SLionel Sambuc	if ! $SOURCEMODE; then
149923a61ee0SLionel Sambuc		extra_scripts="${generated_scripts}"
150023a61ee0SLionel Sambuc	else
150123a61ee0SLionel Sambuc		extra_scripts=""
150223a61ee0SLionel Sambuc	fi
150323a61ee0SLionel Sambuc
150423a61ee0SLionel Sambuc	compare_dir "${op}" "${SRC_DIR}/etc/rc.d" "${DEST_DIR}/etc/rc.d" 555 \
1505*0a6a1f1dSLionel Sambuc		${rc_555_files} \
150623a61ee0SLionel Sambuc		${extra_scripts}
150723a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
150823a61ee0SLionel Sambuc
1509*0a6a1f1dSLionel Sambuc	if ! find_file_in_dirlist blacklistd "blacklistd" \
1510*0a6a1f1dSLionel Sambuc	    "${SRC_DIR}/external/bsd/blacklist/etc/rc.d" \
1511*0a6a1f1dSLionel Sambuc	    "${SRC_DIR}/etc/rc.d"; then
1512*0a6a1f1dSLionel Sambuc	    failed=1
1513*0a6a1f1dSLionel Sambuc	else
1514*0a6a1f1dSLionel Sambuc	    populate_dir "$op" true "${dir}" "${DEST_DIR}/etc/rc.d" 555 \
1515*0a6a1f1dSLionel Sambuc		blacklistd
1516*0a6a1f1dSLionel Sambuc	    failed=$(( ${failed} + $? ))
1517*0a6a1f1dSLionel Sambuc	fi
1518*0a6a1f1dSLionel Sambuc
151923a61ee0SLionel Sambuc	if $SOURCEMODE && [ -n "${generated_scripts}" ]; then
152023a61ee0SLionel Sambuc		# generate scripts
152123a61ee0SLionel Sambuc		mkdir "${SCRATCHDIR}/rc"
152223a61ee0SLionel Sambuc		for f in ${generated_scripts}; do
1523*0a6a1f1dSLionel Sambuc			${SED} -e "s,@X11ROOTDIR@,${X11ROOTDIR},g" \
152423a61ee0SLionel Sambuc			    < "${SRC_DIR}/etc/rc.d/${f}.in" \
152523a61ee0SLionel Sambuc			    > "${SCRATCHDIR}/rc/${f}"
152623a61ee0SLionel Sambuc		done
152723a61ee0SLionel Sambuc		compare_dir "${op}" "${SCRATCHDIR}/rc" \
152823a61ee0SLionel Sambuc		    "${DEST_DIR}/etc/rc.d" 555 \
152923a61ee0SLionel Sambuc		    ${generated_scripts}
153023a61ee0SLionel Sambuc		failed=$(( ${failed} + $? ))
153123a61ee0SLionel Sambuc	fi
153223a61ee0SLionel Sambuc
153323a61ee0SLionel Sambuc		# check for obsolete rc.d files
1534*0a6a1f1dSLionel Sambuc	for f in ${rc_obsolete_files}; do
153523a61ee0SLionel Sambuc		fd="/etc/rc.d/${f}"
153623a61ee0SLionel Sambuc		[ -e "${DEST_DIR}${fd}" ] && echo "${fd}"
153723a61ee0SLionel Sambuc	done | obsolete_paths "${op}"
153823a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
153923a61ee0SLionel Sambuc
154023a61ee0SLionel Sambuc		# check for obsolete rc.conf(5) variables
1541*0a6a1f1dSLionel Sambuc	set -- ${rc_obsolete_vars}
154223a61ee0SLionel Sambuc	while [ $# -gt 1 ]; do
154323a61ee0SLionel Sambuc		if rcconf_is_set "${op}" "$1" "$2" 1; then
154423a61ee0SLionel Sambuc			failed=1
154523a61ee0SLionel Sambuc		fi
154623a61ee0SLionel Sambuc		shift 2
154723a61ee0SLionel Sambuc	done
154823a61ee0SLionel Sambuc
154923a61ee0SLionel Sambuc	return ${failed}
155023a61ee0SLionel Sambuc}
155123a61ee0SLionel Sambuc
155223a61ee0SLionel Sambuc#
155323a61ee0SLionel Sambuc#	sendmail
155423a61ee0SLionel Sambuc#
155523a61ee0SLionel Sambucadddisableditem sendmail "remove obsolete sendmail configuration files and scripts"
155623a61ee0SLionel Sambucdo_sendmail()
155723a61ee0SLionel Sambuc{
155823a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_sendmail  fix|check"
155923a61ee0SLionel Sambuc	op="$1"
156023a61ee0SLionel Sambuc	failed=0
156123a61ee0SLionel Sambuc
156223a61ee0SLionel Sambuc	# Don't complain if the "sendmail" package is installed because the
156323a61ee0SLionel Sambuc	# files might still be in use.
156423a61ee0SLionel Sambuc	if /usr/sbin/pkg_info -qe sendmail >/dev/null 2>&1; then
156523a61ee0SLionel Sambuc		return 0
156623a61ee0SLionel Sambuc	fi
156723a61ee0SLionel Sambuc
156823a61ee0SLionel Sambuc	for f in /etc/mail/helpfile /etc/mail/local-host-names \
156923a61ee0SLionel Sambuc	    /etc/mail/sendmail.cf /etc/mail/submit.cf /etc/rc.d/sendmail \
157023a61ee0SLionel Sambuc	    /etc/rc.d/smmsp /usr/share/misc/sendmail.hf \
1571*0a6a1f1dSLionel Sambuc	    $( ( find "${DEST_DIR}/usr/share/sendmail" -type f ; \
1572*0a6a1f1dSLionel Sambuc	         find "${DEST_DIR}/usr/share/sendmail" -type d \
1573*0a6a1f1dSLionel Sambuc	       ) | unprefix "${DEST_DIR}" ) \
1574*0a6a1f1dSLionel Sambuc	    /var/log/sendmail.st \
1575*0a6a1f1dSLionel Sambuc	    /var/spool/clientmqueue \
1576*0a6a1f1dSLionel Sambuc	    /var/spool/mqueue
1577*0a6a1f1dSLionel Sambuc	do
157823a61ee0SLionel Sambuc		[ -e "${DEST_DIR}${f}" ] && echo "${f}"
157923a61ee0SLionel Sambuc	done | obsolete_paths "${op}"
158023a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
158123a61ee0SLionel Sambuc
158223a61ee0SLionel Sambuc	return ${failed}
158323a61ee0SLionel Sambuc}
158423a61ee0SLionel Sambuc
158523a61ee0SLionel Sambuc#
158623a61ee0SLionel Sambuc#	mailerconf
158723a61ee0SLionel Sambuc#
158823a61ee0SLionel Sambucadddisableditem mailerconf "update /etc/mailer.conf after sendmail removal"
158923a61ee0SLionel Sambucdo_mailerconf()
159023a61ee0SLionel Sambuc{
159123a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_mailterconf  fix|check"
159223a61ee0SLionel Sambuc	op="$1"
159323a61ee0SLionel Sambuc
159423a61ee0SLionel Sambuc	failed=0
159523a61ee0SLionel Sambuc	mta_path="$(${AWK} '/^sendmail[ \t]/{print$2}' \
159623a61ee0SLionel Sambuc		"${DEST_DIR}/etc/mailer.conf")"
159723a61ee0SLionel Sambuc	old_sendmail_path="/usr/libexec/sendmail/sendmail"
159823a61ee0SLionel Sambuc	if [ "${mta_path}" = "${old_sendmail_path}" ]; then
159923a61ee0SLionel Sambuc	    if [ "$op" = check ]; then
160023a61ee0SLionel Sambuc		msg "mailer.conf points to obsolete ${old_sendmail_path}"
160123a61ee0SLionel Sambuc		failed=1;
160223a61ee0SLionel Sambuc	    else
160323a61ee0SLionel Sambuc		populate_dir "${op}" false \
160423a61ee0SLionel Sambuc		"${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 mailer.conf
160523a61ee0SLionel Sambuc		failed=$?
160623a61ee0SLionel Sambuc	    fi
160723a61ee0SLionel Sambuc	fi
160823a61ee0SLionel Sambuc
160923a61ee0SLionel Sambuc	return ${failed}
161023a61ee0SLionel Sambuc}
161123a61ee0SLionel Sambuc
161223a61ee0SLionel Sambuc#
161323a61ee0SLionel Sambuc#	ssh
161423a61ee0SLionel Sambuc#
161523a61ee0SLionel Sambucadditem ssh "ssh configuration update"
161623a61ee0SLionel Sambucdo_ssh()
161723a61ee0SLionel Sambuc{
161823a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_ssh  fix|check"
161923a61ee0SLionel Sambuc	op="$1"
162023a61ee0SLionel Sambuc
162123a61ee0SLionel Sambuc	failed=0
162223a61ee0SLionel Sambuc	_etcssh="${DEST_DIR}/etc/ssh"
162323a61ee0SLionel Sambuc	if ! check_dir "${op}" "${_etcssh}" 755; then
162423a61ee0SLionel Sambuc		failed=1
162523a61ee0SLionel Sambuc	fi
162623a61ee0SLionel Sambuc
162723a61ee0SLionel Sambuc	if [ ${failed} -eq 0 ]; then
162823a61ee0SLionel Sambuc		for f in \
162923a61ee0SLionel Sambuc			    ssh_known_hosts ssh_known_hosts2 \
163023a61ee0SLionel Sambuc			    ssh_host_dsa_key ssh_host_dsa_key.pub \
163123a61ee0SLionel Sambuc			    ssh_host_rsa_key ssh_host_rsa_key.pub \
163223a61ee0SLionel Sambuc			    ssh_host_key ssh_host_key.pub \
163323a61ee0SLionel Sambuc		    ; do
163423a61ee0SLionel Sambuc			if ! move_file "${op}" \
163523a61ee0SLionel Sambuc			    "${DEST_DIR}/etc/${f}" "${_etcssh}/${f}" ; then
163623a61ee0SLionel Sambuc				failed=1
163723a61ee0SLionel Sambuc			fi
163823a61ee0SLionel Sambuc		done
163923a61ee0SLionel Sambuc		for f in sshd.conf ssh.conf ; do
164023a61ee0SLionel Sambuc				# /etc/ssh/ssh{,d}.conf -> ssh{,d}_config
164123a61ee0SLionel Sambuc				#
164223a61ee0SLionel Sambuc			if ! move_file "${op}" \
164323a61ee0SLionel Sambuc			    "${_etcssh}/${f}" "${_etcssh}/${f%.conf}_config" ;
164423a61ee0SLionel Sambuc			then
164523a61ee0SLionel Sambuc				failed=1
164623a61ee0SLionel Sambuc			fi
164723a61ee0SLionel Sambuc				# /etc/ssh{,d}.conf -> /etc/ssh/ssh{,d}_config
164823a61ee0SLionel Sambuc				#
164923a61ee0SLionel Sambuc			if ! move_file "${op}" \
165023a61ee0SLionel Sambuc			    "${DEST_DIR}/etc/${f}" \
165123a61ee0SLionel Sambuc			    "${_etcssh}/${f%.conf}_config" ;
165223a61ee0SLionel Sambuc			then
165323a61ee0SLionel Sambuc				failed=1
165423a61ee0SLionel Sambuc			fi
165523a61ee0SLionel Sambuc		done
165623a61ee0SLionel Sambuc	fi
165723a61ee0SLionel Sambuc
165823a61ee0SLionel Sambuc	sshdconf=""
165923a61ee0SLionel Sambuc	for f in \
166023a61ee0SLionel Sambuc	    "${_etcssh}/sshd_config" \
166123a61ee0SLionel Sambuc	    "${_etcssh}/sshd.conf" \
166223a61ee0SLionel Sambuc	    "${DEST_DIR}/etc/sshd.conf" ; do
166323a61ee0SLionel Sambuc		if [ -f "${f}" ]; then
166423a61ee0SLionel Sambuc			sshdconf="${f}"
166523a61ee0SLionel Sambuc			break
166623a61ee0SLionel Sambuc		fi
166723a61ee0SLionel Sambuc	done
166823a61ee0SLionel Sambuc	if [ -n "${sshdconf}" ]; then
166923a61ee0SLionel Sambuc		modify_file "${op}" "${sshdconf}" "${SCRATCHDIR}/sshdconf" '
167023a61ee0SLionel Sambuc			/^[^#$]/ {
167123a61ee0SLionel Sambuc				kw = tolower($1)
167223a61ee0SLionel Sambuc				if (kw == "hostkey" &&
167323a61ee0SLionel Sambuc				    $2 ~ /^\/etc\/+ssh_host(_[dr]sa)?_key$/ ) {
167423a61ee0SLionel Sambuc					sub(/\/etc\/+/, "/etc/ssh/")
167523a61ee0SLionel Sambuc				}
167623a61ee0SLionel Sambuc				if (kw == "rhostsauthentication" ||
167723a61ee0SLionel Sambuc				    kw == "verifyreversemapping" ||
167823a61ee0SLionel Sambuc				    kw == "reversemappingcheck") {
167923a61ee0SLionel Sambuc					sub(/^/, "# DEPRECATED:\t")
168023a61ee0SLionel Sambuc				}
168123a61ee0SLionel Sambuc			}
168223a61ee0SLionel Sambuc			{ print }
168323a61ee0SLionel Sambuc		'
168423a61ee0SLionel Sambuc		failed=$(( ${failed} + $? ))
168523a61ee0SLionel Sambuc	fi
168623a61ee0SLionel Sambuc
168723a61ee0SLionel Sambuc	if ! find_file_in_dirlist moduli "moduli" \
168823a61ee0SLionel Sambuc	    "${SRC_DIR}/crypto/external/bsd/openssh/dist" "${SRC_DIR}/etc" ; then
168923a61ee0SLionel Sambuc		failed=1
169023a61ee0SLionel Sambuc			# ${dir} is set by find_file_in_dirlist()
169123a61ee0SLionel Sambuc	elif ! compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 moduli; then
169223a61ee0SLionel Sambuc		failed=1
169323a61ee0SLionel Sambuc	fi
169423a61ee0SLionel Sambuc
169523a61ee0SLionel Sambuc	if ! check_dir "${op}" "${DEST_DIR}/var/chroot/sshd" 755 ; then
169623a61ee0SLionel Sambuc		failed=1
169723a61ee0SLionel Sambuc	fi
169823a61ee0SLionel Sambuc
169923a61ee0SLionel Sambuc	if rcconf_is_set "${op}" sshd sshd_conf_dir 1; then
170023a61ee0SLionel Sambuc		failed=1
170123a61ee0SLionel Sambuc	fi
170223a61ee0SLionel Sambuc
170323a61ee0SLionel Sambuc	return ${failed}
170423a61ee0SLionel Sambuc}
170523a61ee0SLionel Sambuc
170623a61ee0SLionel Sambuc#
170723a61ee0SLionel Sambuc#	wscons
170823a61ee0SLionel Sambuc#
170923a61ee0SLionel Sambucadditem wscons "wscons configuration file update"
171023a61ee0SLionel Sambucdo_wscons()
171123a61ee0SLionel Sambuc{
171223a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_wscons  fix|check"
171323a61ee0SLionel Sambuc	op="$1"
171423a61ee0SLionel Sambuc
171523a61ee0SLionel Sambuc	[ -f "${DEST_DIR}/etc/wscons.conf" ] || return 0
171623a61ee0SLionel Sambuc
171723a61ee0SLionel Sambuc	failed=0
171823a61ee0SLionel Sambuc	notfixed=""
171923a61ee0SLionel Sambuc	if [ "${op}" = "fix" ]; then
172023a61ee0SLionel Sambuc		notfixed="${NOT_FIXED}"
172123a61ee0SLionel Sambuc	fi
172223a61ee0SLionel Sambuc	while read _type _arg1 _rest; do
172323a61ee0SLionel Sambuc		if [ "${_type}" = "mux" -a "${_arg1}" = "1" ]; then
172423a61ee0SLionel Sambuc			msg \
172523a61ee0SLionel Sambuc    "Obsolete wscons.conf(5) entry \""${_type} ${_arg1}"\" found.${notfixed}"
172623a61ee0SLionel Sambuc			failed=1
172723a61ee0SLionel Sambuc		fi
172823a61ee0SLionel Sambuc	done < "${DEST_DIR}/etc/wscons.conf"
172923a61ee0SLionel Sambuc
173023a61ee0SLionel Sambuc	return ${failed}
173123a61ee0SLionel Sambuc}
173223a61ee0SLionel Sambuc
173323a61ee0SLionel Sambuc#
173423a61ee0SLionel Sambuc#	X11
173523a61ee0SLionel Sambuc#
173623a61ee0SLionel Sambucadditem x11 "x11 configuration update"
173723a61ee0SLionel Sambucdo_x11()
173823a61ee0SLionel Sambuc{
173923a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_x11  fix|check"
174023a61ee0SLionel Sambuc	op="$1"
174123a61ee0SLionel Sambuc
174223a61ee0SLionel Sambuc	failed=0
174323a61ee0SLionel Sambuc	_etcx11="${DEST_DIR}/etc/X11"
174423a61ee0SLionel Sambuc	if [ ! -d "${_etcx11}" ]; then
174523a61ee0SLionel Sambuc		msg "${_etcx11} is not a directory; skipping check"
174623a61ee0SLionel Sambuc		return 0
174723a61ee0SLionel Sambuc	fi
174823a61ee0SLionel Sambuc	if [ -d "${DEST_DIR}/usr/X11R6/." ]
174923a61ee0SLionel Sambuc	then
175023a61ee0SLionel Sambuc		_libx11="${DEST_DIR}/usr/X11R6/lib/X11"
175123a61ee0SLionel Sambuc		if [ ! -d "${_libx11}" ]; then
175223a61ee0SLionel Sambuc			msg "${_libx11} is not a directory; skipping check"
175323a61ee0SLionel Sambuc			return 0
175423a61ee0SLionel Sambuc		fi
175523a61ee0SLionel Sambuc	fi
175623a61ee0SLionel Sambuc
175723a61ee0SLionel Sambuc	_notfixed=""
175823a61ee0SLionel Sambuc	if [ "${op}" = "fix" ]; then
175923a61ee0SLionel Sambuc		_notfixed="${NOT_FIXED}"
176023a61ee0SLionel Sambuc	fi
176123a61ee0SLionel Sambuc
176223a61ee0SLionel Sambuc	for d in \
176323a61ee0SLionel Sambuc		    fs lbxproxy proxymngr rstart twm xdm xinit xserver xsm \
176423a61ee0SLionel Sambuc	    ; do
176523a61ee0SLionel Sambuc		sd="${_libx11}/${d}"
176623a61ee0SLionel Sambuc		ld="/etc/X11/${d}"
176723a61ee0SLionel Sambuc		td="${DEST_DIR}${ld}"
176823a61ee0SLionel Sambuc		if [ -h "${sd}" ]; then
176923a61ee0SLionel Sambuc			continue
177023a61ee0SLionel Sambuc		elif [ -d "${sd}" ]; then
177123a61ee0SLionel Sambuc			tdfiles="$(find "${td}" \! -type d)"
177223a61ee0SLionel Sambuc			if [ -n "${tdfiles}" ]; then
177323a61ee0SLionel Sambuc				msg "${sd} exists yet ${td} already" \
177423a61ee0SLionel Sambuc				    "contains files${_notfixed}"
177523a61ee0SLionel Sambuc			else
177623a61ee0SLionel Sambuc				msg "Migrate ${sd} to ${td}${_notfixed}"
177723a61ee0SLionel Sambuc			fi
177823a61ee0SLionel Sambuc			failed=1
177923a61ee0SLionel Sambuc		elif [ -e "${sd}" ]; then
178023a61ee0SLionel Sambuc			msg "Unexpected file ${sd}${_notfixed}"
178123a61ee0SLionel Sambuc			continue
178223a61ee0SLionel Sambuc		else
178323a61ee0SLionel Sambuc			continue
178423a61ee0SLionel Sambuc		fi
178523a61ee0SLionel Sambuc	done
178623a61ee0SLionel Sambuc
178723a61ee0SLionel Sambuc	return ${failed}
178823a61ee0SLionel Sambuc}
178923a61ee0SLionel Sambuc
179023a61ee0SLionel Sambuc#
179123a61ee0SLionel Sambuc#	xkb
179223a61ee0SLionel Sambuc#
179323a61ee0SLionel Sambuc# /usr/X11R7/lib/X11/xkb/symbols/pc used to be a directory, but changed
179423a61ee0SLionel Sambuc# to a file on 2009-06-12.  Fixing this requires removing the directory
179523a61ee0SLionel Sambuc# (which we can do) and re-extracting the xbase set (which we can't do),
179623a61ee0SLionel Sambuc# or at least adding that one file (which we may be able to do if X11SRCDIR
179723a61ee0SLionel Sambuc# is available).
179823a61ee0SLionel Sambuc#
179923a61ee0SLionel Sambucadditem xkb "clean up for xkbdata to xkeyboard-config upgrade"
180023a61ee0SLionel Sambucdo_xkb()
180123a61ee0SLionel Sambuc{
180223a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_xkb  fix|check"
180323a61ee0SLionel Sambuc	op="$1"
180423a61ee0SLionel Sambuc	failed=0
180523a61ee0SLionel Sambuc
180623a61ee0SLionel Sambuc	pcpath="/usr/X11R7/lib/X11/xkb/symbols/pc"
180723a61ee0SLionel Sambuc	pcsrcdir="${X11SRCDIR}/external/mit/xkeyboard-config/dist/symbols"
180823a61ee0SLionel Sambuc
180923a61ee0SLionel Sambuc	filemsg="\
181023a61ee0SLionel Sambuc${pcpath} was a directory, should be a file.
181123a61ee0SLionel Sambuc    To fix, extract the xbase set again."
181223a61ee0SLionel Sambuc
181323a61ee0SLionel Sambuc	_notfixed=""
181423a61ee0SLionel Sambuc	if [ "${op}" = "fix" ]; then
181523a61ee0SLionel Sambuc		_notfixed="${NOT_FIXED}"
181623a61ee0SLionel Sambuc	fi
181723a61ee0SLionel Sambuc
1818*0a6a1f1dSLionel Sambuc	if [ ! -d "${DEST_DIR}${pcpath}" ]; then
181923a61ee0SLionel Sambuc		return 0
182023a61ee0SLionel Sambuc	fi
182123a61ee0SLionel Sambuc
182223a61ee0SLionel Sambuc	# Delete obsolete files in the directory, and the directory
182323a61ee0SLionel Sambuc	# itself.  If the directory contains unexpected extra files
182423a61ee0SLionel Sambuc	# then it will not be deleted.
182523a61ee0SLionel Sambuc	( [ -f "${DEST_DIR}"/var/db/obsolete/xbase ] \
1826*0a6a1f1dSLionel Sambuc	    &&  ${SORT} -ru "${DEST_DIR}"/var/db/obsolete/xbase \
182723a61ee0SLionel Sambuc	    | ${GREP} -E "^\\.?${pcpath}/" ;
182823a61ee0SLionel Sambuc	    echo "${pcpath}" ) \
182923a61ee0SLionel Sambuc	| obsolete_paths "${op}"
183023a61ee0SLionel Sambuc	failed=$(( ${failed} + $? ))
183123a61ee0SLionel Sambuc
183223a61ee0SLionel Sambuc	# If the directory was removed above, then try to replace it with
183323a61ee0SLionel Sambuc	# a file.
1834*0a6a1f1dSLionel Sambuc	if [ -d "${DEST_DIR}${pcpath}" ]; then
183523a61ee0SLionel Sambuc		msg "${filemsg}${_notfixed}"
183623a61ee0SLionel Sambuc		failed=$(( ${failed} + 1 ))
183723a61ee0SLionel Sambuc	else
183823a61ee0SLionel Sambuc		if ! find_file_in_dirlist pc "${pcpath}" \
183923a61ee0SLionel Sambuc			"${pcsrcdir}" "${SRC_DIR}${pcpath%/*}"
184023a61ee0SLionel Sambuc		then
184123a61ee0SLionel Sambuc			msg "${filemsg}${_notfixed}"
184223a61ee0SLionel Sambuc			failed=$(( ${failed} + 1 ))
184323a61ee0SLionel Sambuc		else
184423a61ee0SLionel Sambuc			# ${dir} is set by find_file_in_dirlist()
184523a61ee0SLionel Sambuc			populate_dir "${op}" true \
184623a61ee0SLionel Sambuc				"${dir}" "${DEST_DIR}${pcpath%/*}" 444 \
184723a61ee0SLionel Sambuc				pc
184823a61ee0SLionel Sambuc			failed=$(( ${failed} + $? ))
184923a61ee0SLionel Sambuc		fi
185023a61ee0SLionel Sambuc	fi
185123a61ee0SLionel Sambuc
185223a61ee0SLionel Sambuc	return $failed
185323a61ee0SLionel Sambuc}
185423a61ee0SLionel Sambuc
185523a61ee0SLionel Sambuc#
185623a61ee0SLionel Sambuc#	uid
185723a61ee0SLionel Sambuc#
185823a61ee0SLionel Sambucadditem uid "required users in /etc/master.passwd"
185923a61ee0SLionel Sambucdo_uid()
186023a61ee0SLionel Sambuc{
186123a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_uid  fix|check"
186223a61ee0SLionel Sambuc
1863*0a6a1f1dSLionel Sambuc	check_ids "$1" users "${DEST_DIR}/etc/master.passwd" \
1864*0a6a1f1dSLionel Sambuc	    "${SRC_DIR}/etc/master.passwd" 12 \
186584d9c625SLionel Sambuc	    postfix SKIP named ntpd sshd SKIP _pflogd _rwhod SKIP _proxy \
186684d9c625SLionel Sambuc	    _timedc _sdpd _httpd _mdnsd _tests _tcpdump _tss SKIP _rtadvd
186723a61ee0SLionel Sambuc}
186823a61ee0SLionel Sambuc
186923a61ee0SLionel Sambuc
187023a61ee0SLionel Sambuc#
187123a61ee0SLionel Sambuc#	varrwho
187223a61ee0SLionel Sambuc#
187323a61ee0SLionel Sambucadditem varrwho "required ownership of files in /var/rwho"
187423a61ee0SLionel Sambucdo_varrwho()
187523a61ee0SLionel Sambuc{
187623a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_varrwho  fix|check"
187723a61ee0SLionel Sambuc
187823a61ee0SLionel Sambuc	contents_owner "$1" "${DEST_DIR}/var/rwho" _rwhod _rwhod
187923a61ee0SLionel Sambuc}
188023a61ee0SLionel Sambuc
188123a61ee0SLionel Sambuc
188223a61ee0SLionel Sambuc#
188323a61ee0SLionel Sambuc#	tcpdumpchroot
188423a61ee0SLionel Sambuc#
188523a61ee0SLionel Sambucadditem tcpdumpchroot "remove /var/chroot/tcpdump/etc/protocols"
188623a61ee0SLionel Sambucdo_tcpdumpchroot()
188723a61ee0SLionel Sambuc{
188823a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_tcpdumpchroot  fix|check"
188923a61ee0SLionel Sambuc
189023a61ee0SLionel Sambuc	failed=0;
189123a61ee0SLionel Sambuc	if [ -r "${DEST_DIR}/var/chroot/tcpdump/etc/protocols" ]; then
189223a61ee0SLionel Sambuc		if [ "$1" = "fix" ]; then
189323a61ee0SLionel Sambuc			rm "${DEST_DIR}/var/chroot/tcpdump/etc/protocols"
189423a61ee0SLionel Sambuc			failed=$(( ${failed} + $? ))
189523a61ee0SLionel Sambuc			rmdir "${DEST_DIR}/var/chroot/tcpdump/etc"
189623a61ee0SLionel Sambuc			failed=$(( ${failed} + $? ))
189723a61ee0SLionel Sambuc		else
189823a61ee0SLionel Sambuc			failed=1
189923a61ee0SLionel Sambuc		fi
190023a61ee0SLionel Sambuc	fi
190123a61ee0SLionel Sambuc	return ${failed}
190223a61ee0SLionel Sambuc}
190323a61ee0SLionel Sambuc
190423a61ee0SLionel Sambuc
190523a61ee0SLionel Sambuc#
190623a61ee0SLionel Sambuc#	atf
190723a61ee0SLionel Sambuc#
190823a61ee0SLionel Sambucadditem atf "install missing atf configuration files and validate them"
190923a61ee0SLionel Sambucdo_atf()
191023a61ee0SLionel Sambuc{
191123a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_atf  fix|check"
191223a61ee0SLionel Sambuc	op="$1"
191323a61ee0SLionel Sambuc	failed=0
191423a61ee0SLionel Sambuc
191523a61ee0SLionel Sambuc	# Ensure atf configuration files are in place.
191623a61ee0SLionel Sambuc	if find_file_in_dirlist NetBSD.conf "NetBSD.conf" \
191723a61ee0SLionel Sambuc	    "${SRC_DIR}/external/bsd/atf/etc/atf" \
191823a61ee0SLionel Sambuc	    "${SRC_DIR}/etc/atf"; then
191923a61ee0SLionel Sambuc			# ${dir} is set by find_file_in_dirlist()
192023a61ee0SLionel Sambuc		populate_dir "${op}" true "${dir}" "${DEST_DIR}/etc/atf" 644 \
192123a61ee0SLionel Sambuc		    NetBSD.conf common.conf || failed=1
192223a61ee0SLionel Sambuc	else
192323a61ee0SLionel Sambuc		failed=1
192423a61ee0SLionel Sambuc	fi
192523a61ee0SLionel Sambuc	if find_file_in_dirlist atf-run.hooks "atf-run.hooks" \
1926*0a6a1f1dSLionel Sambuc	    "${SRC_DIR}/external/bsd/atf/dist/tools/sample" \
192723a61ee0SLionel Sambuc	    "${SRC_DIR}/etc/atf"; then
192823a61ee0SLionel Sambuc			# ${dir} is set by find_file_in_dirlist()
192923a61ee0SLionel Sambuc		populate_dir "${op}" true "${dir}" "${DEST_DIR}/etc/atf" 644 \
193023a61ee0SLionel Sambuc		    atf-run.hooks || failed=1
193123a61ee0SLionel Sambuc	else
193223a61ee0SLionel Sambuc		failed=1
193323a61ee0SLionel Sambuc	fi
193423a61ee0SLionel Sambuc
193523a61ee0SLionel Sambuc	# Validate the _atf to _tests user/group renaming.
193623a61ee0SLionel Sambuc	if [ -f "${DEST_DIR}/etc/atf/common.conf" ]; then
193723a61ee0SLionel Sambuc		handle_atf_user "${op}" || failed=1
193823a61ee0SLionel Sambuc	else
193923a61ee0SLionel Sambuc		failed=1
194023a61ee0SLionel Sambuc	fi
194123a61ee0SLionel Sambuc
194223a61ee0SLionel Sambuc	return ${failed}
194323a61ee0SLionel Sambuc}
194423a61ee0SLionel Sambuc
194523a61ee0SLionel Sambuchandle_atf_user()
194623a61ee0SLionel Sambuc{
194723a61ee0SLionel Sambuc	local op="$1"
194823a61ee0SLionel Sambuc	local failed=0
194923a61ee0SLionel Sambuc
195023a61ee0SLionel Sambuc	local conf="${DEST_DIR}/etc/atf/common.conf"
195123a61ee0SLionel Sambuc	if grep '[^#]*unprivileged-user[ \t]*=.*_atf' "${conf}" >/dev/null
195223a61ee0SLionel Sambuc	then
195323a61ee0SLionel Sambuc		if [ "$1" = "fix" ]; then
1954*0a6a1f1dSLionel Sambuc			${SED} -e \
195523a61ee0SLionel Sambuc			    "/[^#]*unprivileged-user[\ t]*=/s/_atf/_tests/" \
195623a61ee0SLionel Sambuc			    "${conf}" >"${conf}.new"
195723a61ee0SLionel Sambuc			failed=$(( ${failed} + $? ))
195823a61ee0SLionel Sambuc			mv "${conf}.new" "${conf}"
195923a61ee0SLionel Sambuc			failed=$(( ${failed} + $? ))
196023a61ee0SLionel Sambuc			msg "Set unprivileged-user=_tests in ${conf}"
196123a61ee0SLionel Sambuc		else
196223a61ee0SLionel Sambuc			msg "unprivileged-user=_atf in ${conf} should be" \
196323a61ee0SLionel Sambuc			    "unprivileged-user=_tests"
196423a61ee0SLionel Sambuc			failed=1
196523a61ee0SLionel Sambuc		fi
196623a61ee0SLionel Sambuc	fi
196723a61ee0SLionel Sambuc
196823a61ee0SLionel Sambuc	return ${failed}
196923a61ee0SLionel Sambuc}
197023a61ee0SLionel Sambuc
197123a61ee0SLionel Sambuc#
197223a61ee0SLionel Sambuc#	catpages
197323a61ee0SLionel Sambuc#
197423a61ee0SLionel Sambucobsolete_catpages()
197523a61ee0SLionel Sambuc{
197623a61ee0SLionel Sambuc	basedir="$2"
197723a61ee0SLionel Sambuc	section="$3"
197823a61ee0SLionel Sambuc	mandir="${basedir}/man${section}"
197923a61ee0SLionel Sambuc	catdir="${basedir}/cat${section}"
198023a61ee0SLionel Sambuc	test -d "$mandir" || return 0
198123a61ee0SLionel Sambuc	test -d "$catdir" || return 0
198223a61ee0SLionel Sambuc	(cd "$mandir" && find . -type f) | {
198323a61ee0SLionel Sambuc	failed=0
198423a61ee0SLionel Sambuc	while read manpage; do
198523a61ee0SLionel Sambuc		manpage="${manpage#./}"
198623a61ee0SLionel Sambuc		case "$manpage" in
198723a61ee0SLionel Sambuc		*.Z)
198823a61ee0SLionel Sambuc			catname="$catdir/${manpage%.*.Z}.0"
198923a61ee0SLionel Sambuc			;;
199023a61ee0SLionel Sambuc		*.gz)
199123a61ee0SLionel Sambuc			catname="$catdir/${manpage%.*.gz}.0"
199223a61ee0SLionel Sambuc			;;
199323a61ee0SLionel Sambuc		*)
199423a61ee0SLionel Sambuc			catname="$catdir/${manpage%.*}.0"
199523a61ee0SLionel Sambuc			;;
199623a61ee0SLionel Sambuc		esac
199723a61ee0SLionel Sambuc		test -e "$catname" -a "$catname" -ot "$mandir/$manpage" || continue
199823a61ee0SLionel Sambuc		if [ "$1" = "fix" ]; then
199923a61ee0SLionel Sambuc			rm "$catname"
200023a61ee0SLionel Sambuc			failed=$(( ${failed} + $? ))
200123a61ee0SLionel Sambuc			msg "Removed obsolete cat page $catname"
200223a61ee0SLionel Sambuc		else
200323a61ee0SLionel Sambuc			msg "Obsolete cat page $catname"
200423a61ee0SLionel Sambuc			failed=1
200523a61ee0SLionel Sambuc		fi
200623a61ee0SLionel Sambuc	done
200723a61ee0SLionel Sambuc	exit $failed
200823a61ee0SLionel Sambuc	}
200923a61ee0SLionel Sambuc}
201023a61ee0SLionel Sambuc
201123a61ee0SLionel Sambucadditem catpages "remove outdated cat pages"
201223a61ee0SLionel Sambucdo_catpages()
201323a61ee0SLionel Sambuc{
201423a61ee0SLionel Sambuc	failed=0
201523a61ee0SLionel Sambuc	for manbase in /usr/share/man /usr/X11R6/man /usr/X11R7/man; do
201623a61ee0SLionel Sambuc		for sec in 1 2 3 4 5 6 7 8 9; do
201723a61ee0SLionel Sambuc			obsolete_catpages "$1" "${DEST_DIR}${manbase}" "${sec}"
201823a61ee0SLionel Sambuc			failed=$(( ${failed} + $? ))
201923a61ee0SLionel Sambuc			if [ "$1" = "fix" ]; then
202023a61ee0SLionel Sambuc				rmdir "${DEST_DIR}${manbase}/cat${sec}"/* \
202123a61ee0SLionel Sambuc					2>/dev/null
202223a61ee0SLionel Sambuc				rmdir "${DEST_DIR}${manbase}/cat${sec}" \
202323a61ee0SLionel Sambuc					2>/dev/null
202423a61ee0SLionel Sambuc			fi
202523a61ee0SLionel Sambuc		done
202623a61ee0SLionel Sambuc	done
202723a61ee0SLionel Sambuc	return $failed
202823a61ee0SLionel Sambuc}
202923a61ee0SLionel Sambuc
203023a61ee0SLionel Sambuc#
2031*0a6a1f1dSLionel Sambuc#	man.conf
203223a61ee0SLionel Sambuc#
2033*0a6a1f1dSLionel Sambucadditem manconf "check for a mandoc usage in /etc/man.conf"
2034*0a6a1f1dSLionel Sambucdo_manconf()
203523a61ee0SLionel Sambuc{
2036*0a6a1f1dSLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_manconf  fix|check"
203723a61ee0SLionel Sambuc	op="$1"
203823a61ee0SLionel Sambuc	failed=0
203923a61ee0SLionel Sambuc
2040*0a6a1f1dSLionel Sambuc	[ -f "${DEST_DIR}/etc/man.conf" ] || return 0
2041*0a6a1f1dSLionel Sambuc	if ${GREP} -w "mandoc" "${DEST_DIR}/etc/man.conf" >/dev/null 2>&1;
2042*0a6a1f1dSLionel Sambuc	then
2043*0a6a1f1dSLionel Sambuc		failed=0;
2044*0a6a1f1dSLionel Sambuc	else
2045*0a6a1f1dSLionel Sambuc		failed=1
2046*0a6a1f1dSLionel Sambuc		notfixed=""
2047*0a6a1f1dSLionel Sambuc		if [ "${op}" = "fix" ]; then
2048*0a6a1f1dSLionel Sambuc			notfixed="${NOT_FIXED}"
2049*0a6a1f1dSLionel Sambuc		fi
2050*0a6a1f1dSLionel Sambuc		msg "The file /etc/man.conf has not been adapted to mandoc usage; you"
2051*0a6a1f1dSLionel Sambuc		msg "probably want to copy a new version over. ${notfixed}"
2052*0a6a1f1dSLionel Sambuc	fi
205323a61ee0SLionel Sambuc
205423a61ee0SLionel Sambuc	return ${failed}
205523a61ee0SLionel Sambuc}
205623a61ee0SLionel Sambuc
205723a61ee0SLionel Sambuc
205823a61ee0SLionel Sambuc#
205923a61ee0SLionel Sambuc#	ptyfsoldnodes
206023a61ee0SLionel Sambuc#
206123a61ee0SLionel Sambucadditem ptyfsoldnodes "remove legacy device nodes when using ptyfs"
206223a61ee0SLionel Sambucdo_ptyfsoldnodes()
206323a61ee0SLionel Sambuc{
206423a61ee0SLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_ptyfsoldnodes  fix|check"
206523a61ee0SLionel Sambuc	_ptyfs_op="$1"
206623a61ee0SLionel Sambuc
206723a61ee0SLionel Sambuc	# Check whether ptyfs is in use
206823a61ee0SLionel Sambuc	failed=0;
206923a61ee0SLionel Sambuc	if ! ${GREP} -E "^ptyfs" "${DEST_DIR}/etc/fstab" > /dev/null; then
207023a61ee0SLionel Sambuc		msg "ptyfs is not in use"
207123a61ee0SLionel Sambuc		return 0
207223a61ee0SLionel Sambuc	fi
207323a61ee0SLionel Sambuc
2074*0a6a1f1dSLionel Sambuc	if [ ! -e "${DEST_DIR}/dev/pts" ]; then
2075*0a6a1f1dSLionel Sambuc		msg "ptyfs is not properly configured: missing /dev/pts"
2076*0a6a1f1dSLionel Sambuc		return 1
2077*0a6a1f1dSLionel Sambuc	fi
2078*0a6a1f1dSLionel Sambuc
207923a61ee0SLionel Sambuc	# Find the device major numbers for the pty master and slave
208023a61ee0SLionel Sambuc	# devices, by parsing the output from "MAKEDEV -s pty0".
208123a61ee0SLionel Sambuc	#
208223a61ee0SLionel Sambuc	# Output from MAKEDEV looks like this:
208323a61ee0SLionel Sambuc	# ./ttyp0 type=char device=netbsd,5,0 mode=666 gid=0 uid=0
208423a61ee0SLionel Sambuc	# ./ptyp0 type=char device=netbsd,6,0 mode=666 gid=0 uid=0
208523a61ee0SLionel Sambuc	#
208623a61ee0SLionel Sambuc	# Output from awk, used in the eval statement, looks like this:
208723a61ee0SLionel Sambuc	# maj_ptym=6; maj_ptys=5;
208823a61ee0SLionel Sambuc	#
208923a61ee0SLionel Sambuc	eval "$(
209023a61ee0SLionel Sambuc	    ${HOST_SH} "${DEST_DIR}/dev/MAKEDEV" -s pty0 2>/dev/null \
209123a61ee0SLionel Sambuc	    | ${AWK} '\
209223a61ee0SLionel Sambuc	    BEGIN { before_re = ".*device=[a-zA-Z]*,"; after_re = ",.*"; }
209323a61ee0SLionel Sambuc	    /ptyp0/ { maj_ptym = gensub(before_re, "", 1, $0);
209423a61ee0SLionel Sambuc		      maj_ptym = gensub(after_re, "", 1, maj_ptym); }
209523a61ee0SLionel Sambuc	    /ttyp0/ { maj_ptys = gensub(before_re, "", 1, $0);
209623a61ee0SLionel Sambuc		      maj_ptys = gensub(after_re, "", 1, maj_ptys); }
209723a61ee0SLionel Sambuc	    END { print "maj_ptym=" maj_ptym "; maj_ptys=" maj_ptys ";"; }
209823a61ee0SLionel Sambuc	    '
209923a61ee0SLionel Sambuc	    )"
210023a61ee0SLionel Sambuc	#msg "Major numbers are maj_ptym=${maj_ptym} maj_ptys=${maj_ptys}"
210123a61ee0SLionel Sambuc	if [ -z "$maj_ptym" ] || [ -z "$maj_ptys" ]; then
210223a61ee0SLionel Sambuc		msg "Cannot find device major numbers for pty master and slave"
210323a61ee0SLionel Sambuc		return 1
210423a61ee0SLionel Sambuc	fi
210523a61ee0SLionel Sambuc
210623a61ee0SLionel Sambuc	# look for /dev/[pt]ty[p-zP-T][0-9a-zA-Z], and check that they
210723a61ee0SLionel Sambuc	# have the expected device major numbers.  ttyv* is typically not a
210823a61ee0SLionel Sambuc	# pty device, but we check it anyway.
210923a61ee0SLionel Sambuc	#
211023a61ee0SLionel Sambuc	# The "for d1" loop is intended to avoid overflowing ARG_MAX;
211123a61ee0SLionel Sambuc	# otherwise we could have used a single glob pattern.
211223a61ee0SLionel Sambuc	#
211323a61ee0SLionel Sambuc	# If there are no files that match a particular pattern,
211423a61ee0SLionel Sambuc	# then stat prints something like:
211523a61ee0SLionel Sambuc	#    stat: /dev/[pt]tyx?: lstat: No such file or directory
211623a61ee0SLionel Sambuc	# and we ignore it.  XXX: We also ignore other error messages.
211723a61ee0SLionel Sambuc	#
211823a61ee0SLionel Sambuc	_ptyfs_tmp="$(mktemp /tmp/postinstall.ptyfs.XXXXXXXX)"
211923a61ee0SLionel Sambuc	for d1 in p q r s t u v w x y z P Q R S T; do
212023a61ee0SLionel Sambuc		${STAT} -f "%Hr %N" "${DEST_DIR}/dev/"[pt]ty${d1}? 2>&1
212123a61ee0SLionel Sambuc	done \
212223a61ee0SLionel Sambuc	| while read -r major node ; do
212323a61ee0SLionel Sambuc		case "$major" in
212423a61ee0SLionel Sambuc		${maj_ptym}|${maj_ptys}) echo "$node" ;;
212523a61ee0SLionel Sambuc		esac
212623a61ee0SLionel Sambuc	done >"${_ptyfs_tmp}"
212723a61ee0SLionel Sambuc
212823a61ee0SLionel Sambuc	_desc="legacy device node"
212923a61ee0SLionel Sambuc	while read node; do
213023a61ee0SLionel Sambuc		if [ "${_ptyfs_op}" = "check" ]; then
213123a61ee0SLionel Sambuc			msg "Remove ${_desc} ${node}"
213223a61ee0SLionel Sambuc			failed=1
213323a61ee0SLionel Sambuc		else # "fix"
213423a61ee0SLionel Sambuc			if rm "${node}"; then
213523a61ee0SLionel Sambuc				msg "Removed ${_desc} ${node}"
213623a61ee0SLionel Sambuc			else
213723a61ee0SLionel Sambuc				warn "Failed to remove ${_desc} ${node}"
213823a61ee0SLionel Sambuc				failed=1
213923a61ee0SLionel Sambuc			fi
214023a61ee0SLionel Sambuc		fi
214123a61ee0SLionel Sambuc	done < "${_ptyfs_tmp}"
214223a61ee0SLionel Sambuc	rm "${_ptyfs_tmp}"
214323a61ee0SLionel Sambuc
214423a61ee0SLionel Sambuc	return ${failed}
214523a61ee0SLionel Sambuc}
214623a61ee0SLionel Sambuc
214723a61ee0SLionel Sambuc
214823a61ee0SLionel Sambuc#
2149*0a6a1f1dSLionel Sambuc#	varshm
2150*0a6a1f1dSLionel Sambuc#
2151*0a6a1f1dSLionel Sambucadditem varshm "check for a tmpfs mounted on /var/shm"
2152*0a6a1f1dSLionel Sambucdo_varshm()
2153*0a6a1f1dSLionel Sambuc{
2154*0a6a1f1dSLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_varshm  fix|check"
2155*0a6a1f1dSLionel Sambuc	op="$1"
2156*0a6a1f1dSLionel Sambuc	failed=0
2157*0a6a1f1dSLionel Sambuc
2158*0a6a1f1dSLionel Sambuc	[ -f "${DEST_DIR}/etc/fstab" ] || return 0
2159*0a6a1f1dSLionel Sambuc	if ${GREP} -w "/var/shm" "${DEST_DIR}/etc/fstab" >/dev/null 2>&1;
2160*0a6a1f1dSLionel Sambuc	then
2161*0a6a1f1dSLionel Sambuc		failed=0;
2162*0a6a1f1dSLionel Sambuc	else
2163*0a6a1f1dSLionel Sambuc		if [ "${op}" = "check" ]; then
2164*0a6a1f1dSLionel Sambuc			failed=1
2165*0a6a1f1dSLionel Sambuc			msg "No /var/shm mount found in ${DEST_DIR}/etc/fstab"
2166*0a6a1f1dSLionel Sambuc		elif [ "${op}" = "fix" ]; then
2167*0a6a1f1dSLionel Sambuc			printf '\ntmpfs\t/var/shm\ttmpfs\trw,-m1777,-sram%%25\n' \
2168*0a6a1f1dSLionel Sambuc				>> "${DEST_DIR}/etc/fstab"
2169*0a6a1f1dSLionel Sambuc			msg "Added tmpfs with 25% ram limit as /var/shm"
2170*0a6a1f1dSLionel Sambuc
2171*0a6a1f1dSLionel Sambuc		fi
2172*0a6a1f1dSLionel Sambuc	fi
2173*0a6a1f1dSLionel Sambuc
2174*0a6a1f1dSLionel Sambuc	return ${failed}
2175*0a6a1f1dSLionel Sambuc}
2176*0a6a1f1dSLionel Sambuc
2177*0a6a1f1dSLionel Sambuc#
2178*0a6a1f1dSLionel Sambuc#	obsolete_stand
2179*0a6a1f1dSLionel Sambuc#
2180*0a6a1f1dSLionel Sambucadddisableditem obsolete_stand "remove obsolete files from /stand"
2181*0a6a1f1dSLionel Sambucdo_obsolete_stand()
2182*0a6a1f1dSLionel Sambuc{
2183*0a6a1f1dSLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_obsolete_stnd  fix|check"
2184*0a6a1f1dSLionel Sambuc	op="$1"
2185*0a6a1f1dSLionel Sambuc	failed=0
2186*0a6a1f1dSLionel Sambuc
2187*0a6a1f1dSLionel Sambuc	for dir in \
2188*0a6a1f1dSLionel Sambuc	    /stand/${MACHINE} \
2189*0a6a1f1dSLionel Sambuc	    /stand/${MACHINE}-4xx \
2190*0a6a1f1dSLionel Sambuc	    /stand/${MACHINE}-booke \
2191*0a6a1f1dSLionel Sambuc	    /stand/${MACHINE}-xen \
2192*0a6a1f1dSLionel Sambuc	    /stand/${MACHINE}pae-xen
2193*0a6a1f1dSLionel Sambuc	do
2194*0a6a1f1dSLionel Sambuc		[ -d "${DESTDIR}${dir}" ] && obsolete_stand "${dir}"
2195*0a6a1f1dSLionel Sambuc	done | obsolete_paths "${op}"
2196*0a6a1f1dSLionel Sambuc	failed=$(( ${failed} + $? ))
2197*0a6a1f1dSLionel Sambuc
2198*0a6a1f1dSLionel Sambuc	return ${failed}
2199*0a6a1f1dSLionel Sambuc}
2200*0a6a1f1dSLionel Sambuc
2201*0a6a1f1dSLionel Sambuc#
2202*0a6a1f1dSLionel Sambuc#	obsolete
2203*0a6a1f1dSLionel Sambuc#	(this item is last to allow other items to move obsolete files)
2204*0a6a1f1dSLionel Sambuc#
2205*0a6a1f1dSLionel Sambucadditem obsolete "remove obsolete file sets and minor libraries"
2206*0a6a1f1dSLionel Sambucdo_obsolete()
2207*0a6a1f1dSLionel Sambuc{
2208*0a6a1f1dSLionel Sambuc	[ -n "$1" ] || err 3 "USAGE: do_obsolete  fix|check"
2209*0a6a1f1dSLionel Sambuc	op="$1"
2210*0a6a1f1dSLionel Sambuc	failed=0
2211*0a6a1f1dSLionel Sambuc
2212*0a6a1f1dSLionel Sambuc	${SORT} -ru "${DEST_DIR}"/var/db/obsolete/* | obsolete_paths "${op}"
2213*0a6a1f1dSLionel Sambuc	failed=$(( ${failed} + $? ))
2214*0a6a1f1dSLionel Sambuc
2215*0a6a1f1dSLionel Sambuc	(
2216*0a6a1f1dSLionel Sambuc		obsolete_libs /lib
2217*0a6a1f1dSLionel Sambuc		obsolete_libs /usr/lib
2218*0a6a1f1dSLionel Sambuc		obsolete_libs /usr/lib/i18n
2219*0a6a1f1dSLionel Sambuc		obsolete_libs /usr/X11R6/lib
2220*0a6a1f1dSLionel Sambuc		obsolete_libs /usr/X11R7/lib
2221*0a6a1f1dSLionel Sambuc		[ "$MACHINE" = "amd64" ] && obsolete_libs /usr/lib/i386
2222*0a6a1f1dSLionel Sambuc		[ "$MACHINE" = "sparc64" ] && obsolete_libs /usr/lib/sparc
2223*0a6a1f1dSLionel Sambuc	) | obsolete_paths "${op}"
2224*0a6a1f1dSLionel Sambuc	failed=$(( ${failed} + $? ))
2225*0a6a1f1dSLionel Sambuc
2226*0a6a1f1dSLionel Sambuc	return ${failed}
2227*0a6a1f1dSLionel Sambuc}
2228*0a6a1f1dSLionel Sambuc
2229*0a6a1f1dSLionel Sambuc#
223023a61ee0SLionel Sambuc#	end of items
223123a61ee0SLionel Sambuc#	------------
223223a61ee0SLionel Sambuc#
223323a61ee0SLionel Sambuc
223423a61ee0SLionel Sambuc
223523a61ee0SLionel Sambucusage()
223623a61ee0SLionel Sambuc{
223723a61ee0SLionel Sambuc	cat 1>&2 << _USAGE_
223884d9c625SLionel SambucUsage: ${PROGNAME} [-s srcdir] [-x xsrcdir] [-d destdir] [-m mach] [-a arch] op [item [...]]
223923a61ee0SLionel Sambuc	Perform post-installation checks and/or fixes on a system's
224023a61ee0SLionel Sambuc	configuration files.
224123a61ee0SLionel Sambuc	If no items are provided, a default set of checks or fixes is applied.
224223a61ee0SLionel Sambuc
224323a61ee0SLionel Sambuc	Options:
224423a61ee0SLionel Sambuc	-s {srcdir|tgzfile|tempdir}
224523a61ee0SLionel Sambuc			Location of the source files.  This may be any
224623a61ee0SLionel Sambuc			of the following:
224723a61ee0SLionel Sambuc			* A directory that contains a NetBSD source tree;
224823a61ee0SLionel Sambuc			* A distribution set file such as "etc.tgz" or
224923a61ee0SLionel Sambuc			  "xetc.tgz".  Pass multiple -s options to specify
225023a61ee0SLionel Sambuc			  multiple such files;
225123a61ee0SLionel Sambuc			* A temporary directory in which one or both of
225223a61ee0SLionel Sambuc			  "etc.tgz" and "xetc.tgz" have been extracted.
225384d9c625SLionel Sambuc							[${SRC_DIR:-/usr/src}]
225484d9c625SLionel Sambuc	-x xsrcdir      Location of the X11 source files.  This must be
225584d9c625SLionel Sambuc			a directory that contains a NetBSD xsrc tree.
225684d9c625SLionel Sambuc							[${XSRC_DIR:-/usr/src/../xsrc}]
225723a61ee0SLionel Sambuc	-d destdir	Destination directory to check. [${DEST_DIR:-/}]
225823a61ee0SLionel Sambuc	-m mach		MACHINE.			[${MACHINE}]
225923a61ee0SLionel Sambuc	-a arch		MACHINE_ARCH.			[${MACHINE_ARCH}]
226023a61ee0SLionel Sambuc
226123a61ee0SLionel Sambuc	Operation may be one of:
226223a61ee0SLionel Sambuc		help	Display this help.
226323a61ee0SLionel Sambuc		list	List available items.
226423a61ee0SLionel Sambuc		check	Perform post-installation checks on items.
226523a61ee0SLionel Sambuc		diff [diff(1) options ...]
226623a61ee0SLionel Sambuc			Similar to 'check' but also output difference of files.
226723a61ee0SLionel Sambuc		fix	Apply fixes that 'check' determines need to be applied.
226823a61ee0SLionel Sambuc		usage	Display this usage.
226923a61ee0SLionel Sambuc_USAGE_
227023a61ee0SLionel Sambuc	exit 2
227123a61ee0SLionel Sambuc}
227223a61ee0SLionel Sambuc
227323a61ee0SLionel Sambuc
227423a61ee0SLionel Sambuclist()
227523a61ee0SLionel Sambuc{
227623a61ee0SLionel Sambuc	echo "Default set of items (to apply if no items are provided by user):"
227723a61ee0SLionel Sambuc	echo "  Item          Description"
227823a61ee0SLionel Sambuc	echo "  ----          -----------"
227923a61ee0SLionel Sambuc	for i in ${defaultitems}; do
228023a61ee0SLionel Sambuc		eval desc=\"\${desc_${i}}\"
228123a61ee0SLionel Sambuc		printf "  %-12s  %s\n" "${i}" "${desc}"
228223a61ee0SLionel Sambuc	done
228323a61ee0SLionel Sambuc	echo "Items disabled by default (must be requested explicitly):"
228423a61ee0SLionel Sambuc	echo "  Item          Description"
228523a61ee0SLionel Sambuc	echo "  ----          -----------"
228623a61ee0SLionel Sambuc	for i in ${otheritems}; do
228723a61ee0SLionel Sambuc		eval desc=\"\${desc_${i}}\"
228823a61ee0SLionel Sambuc		printf "  %-12s  %s\n" "${i}" "${desc}"
228923a61ee0SLionel Sambuc	done
229023a61ee0SLionel Sambuc
229123a61ee0SLionel Sambuc}
229223a61ee0SLionel Sambuc
229323a61ee0SLionel Sambuc
229423a61ee0SLionel Sambucmain()
229523a61ee0SLionel Sambuc{
229623a61ee0SLionel Sambuc	TGZLIST=		# quoted list list of tgz files
229723a61ee0SLionel Sambuc	SRC_ARGLIST=		# quoted list of one or more "-s" args
229823a61ee0SLionel Sambuc	SRC_DIR="${SRC_ARG}"	# set default value for early usage()
229984d9c625SLionel Sambuc	XSRC_DIR="${SRC_ARG}/../xsrc"
230023a61ee0SLionel Sambuc	N_SRC_ARGS=0		# number of "-s" args
230123a61ee0SLionel Sambuc	TGZMODE=false		# true if "-s" specifies a tgz file
230223a61ee0SLionel Sambuc	DIRMODE=false		# true if "-s" specified a directory
230323a61ee0SLionel Sambuc	SOURCEMODE=false	# true if "-s" specified a source directory
230423a61ee0SLionel Sambuc
230584d9c625SLionel Sambuc	while getopts s:x:d:m:a: ch; do
230623a61ee0SLionel Sambuc		case "${ch}" in
230723a61ee0SLionel Sambuc		s)
230823a61ee0SLionel Sambuc			qarg="$(shell_quote "${OPTARG}")"
230923a61ee0SLionel Sambuc			N_SRC_ARGS=$(( $N_SRC_ARGS + 1 ))
231023a61ee0SLionel Sambuc			SRC_ARGLIST="${SRC_ARGLIST}${SRC_ARGLIST:+ }-s ${qarg}"
231123a61ee0SLionel Sambuc			if [ -f "${OPTARG}" ]; then
231223a61ee0SLionel Sambuc				# arg refers to a *.tgz file.
231323a61ee0SLionel Sambuc				# This may happen twice, for both
231423a61ee0SLionel Sambuc				# etc.tgz and xetc.tgz, so we build up a
231523a61ee0SLionel Sambuc				# quoted list in TGZLIST.
231623a61ee0SLionel Sambuc				TGZMODE=true
231723a61ee0SLionel Sambuc				TGZLIST="${TGZLIST}${TGZLIST:+ }${qarg}"
231823a61ee0SLionel Sambuc				# Note that, when TGZMODE is true,
231923a61ee0SLionel Sambuc				# SRC_ARG is used only for printing
232023a61ee0SLionel Sambuc				# human-readable messages.
232123a61ee0SLionel Sambuc				SRC_ARG="${TGZLIST}"
232223a61ee0SLionel Sambuc			elif [ -d "${OPTARG}" ]; then
232323a61ee0SLionel Sambuc				# arg refers to a directory.
232423a61ee0SLionel Sambuc				# It might be a source directory, or a
232523a61ee0SLionel Sambuc				# directory where the sets have already
232623a61ee0SLionel Sambuc				# been extracted.
232723a61ee0SLionel Sambuc				DIRMODE=true
232823a61ee0SLionel Sambuc				SRC_ARG="${OPTARG}"
232923a61ee0SLionel Sambuc				if [ -f "${OPTARG}/etc/Makefile" ]; then
233023a61ee0SLionel Sambuc					SOURCEMODE=true
233123a61ee0SLionel Sambuc				fi
233223a61ee0SLionel Sambuc			else
233323a61ee0SLionel Sambuc				err 2 "Invalid argument for -s option"
233423a61ee0SLionel Sambuc			fi
233523a61ee0SLionel Sambuc			;;
233684d9c625SLionel Sambuc		x)
233784d9c625SLionel Sambuc			if [ -d "${OPTARG}" ]; then
233884d9c625SLionel Sambuc				# arg refers to a directory.
233984d9c625SLionel Sambuc				XSRC_DIR="${OPTARG}"
234084d9c625SLionel Sambuc			else
234184d9c625SLionel Sambuc				err 2 "Not a directory for -x option"
234284d9c625SLionel Sambuc			fi
234384d9c625SLionel Sambuc			;;
234423a61ee0SLionel Sambuc		d)
234523a61ee0SLionel Sambuc			DEST_DIR="${OPTARG}"
234623a61ee0SLionel Sambuc			;;
234723a61ee0SLionel Sambuc		m)
234823a61ee0SLionel Sambuc			MACHINE="${OPTARG}"
234923a61ee0SLionel Sambuc			;;
235023a61ee0SLionel Sambuc		a)
235123a61ee0SLionel Sambuc			MACHINE_ARCH="${OPTARG}"
235223a61ee0SLionel Sambuc			;;
235323a61ee0SLionel Sambuc		*)
235423a61ee0SLionel Sambuc			usage
235523a61ee0SLionel Sambuc			;;
235623a61ee0SLionel Sambuc		esac
235723a61ee0SLionel Sambuc	done
235823a61ee0SLionel Sambuc	shift $((${OPTIND} - 1))
235923a61ee0SLionel Sambuc	[ $# -gt 0 ] || usage
236023a61ee0SLionel Sambuc
236123a61ee0SLionel Sambuc	if [ "$N_SRC_ARGS" -gt 1 ] && $DIRMODE; then
236223a61ee0SLionel Sambuc		err 2 "Multiple -s args are allowed only with tgz files"
236323a61ee0SLionel Sambuc	fi
236423a61ee0SLionel Sambuc	if [ "$N_SRC_ARGS" -eq 0 ]; then
236523a61ee0SLionel Sambuc		# The default SRC_ARG was set elsewhere
236623a61ee0SLionel Sambuc		DIRMODE=true
236723a61ee0SLionel Sambuc		SOURCEMODE=true
236823a61ee0SLionel Sambuc		SRC_ARGLIST="-s $(shell_quote "${SRC_ARG}")"
236923a61ee0SLionel Sambuc	fi
237023a61ee0SLionel Sambuc
237123a61ee0SLionel Sambuc	#
237223a61ee0SLionel Sambuc	# If '-s' arg or args specified tgz files, extract them
237323a61ee0SLionel Sambuc	# to a scratch directory.
237423a61ee0SLionel Sambuc	#
237523a61ee0SLionel Sambuc	if $TGZMODE; then
237623a61ee0SLionel Sambuc		ETCTGZDIR="${SCRATCHDIR}/etc.tgz"
237723a61ee0SLionel Sambuc		echo "Note: Creating temporary directory ${ETCTGZDIR}"
237823a61ee0SLionel Sambuc		if ! mkdir "${ETCTGZDIR}"; then
237923a61ee0SLionel Sambuc			err 2 "Can't create ${ETCTGZDIR}"
238023a61ee0SLionel Sambuc		fi
238123a61ee0SLionel Sambuc		( # subshell to localise changes to "$@"
238223a61ee0SLionel Sambuc			eval "set -- ${TGZLIST}"
238323a61ee0SLionel Sambuc			for tgz in "$@"; do
238423a61ee0SLionel Sambuc				echo "Note: Extracting files from ${tgz}"
238523a61ee0SLionel Sambuc				cat "${tgz}" | (
238623a61ee0SLionel Sambuc					cd "${ETCTGZDIR}" &&
238723a61ee0SLionel Sambuc					tar -zxf -
238823a61ee0SLionel Sambuc				) || err 2 "Can't extract ${tgz}"
238923a61ee0SLionel Sambuc			done
239023a61ee0SLionel Sambuc		)
239123a61ee0SLionel Sambuc		SRC_DIR="${ETCTGZDIR}"
239223a61ee0SLionel Sambuc	else
239323a61ee0SLionel Sambuc		SRC_DIR="${SRC_ARG}"
239423a61ee0SLionel Sambuc	fi
239523a61ee0SLionel Sambuc
239623a61ee0SLionel Sambuc	[ -d "${SRC_DIR}" ]	|| err 2 "${SRC_DIR} is not a directory"
239723a61ee0SLionel Sambuc	[ -d "${DEST_DIR}" ]	|| err 2 "${DEST_DIR} is not a directory"
239823a61ee0SLionel Sambuc	[ -n "${MACHINE}" ]	|| err 2 "\${MACHINE} is not defined"
239923a61ee0SLionel Sambuc	[ -n "${MACHINE_ARCH}" ] || err 2 "\${MACHINE_ARCH} is not defined"
240023a61ee0SLionel Sambuc	if ! $SOURCEMODE && ! [ -f "${SRC_DIR}/etc/mtree/set.etc" ]; then
240123a61ee0SLionel Sambuc		err 2 "Files from the etc.tgz set are missing"
240223a61ee0SLionel Sambuc	fi
240323a61ee0SLionel Sambuc
240423a61ee0SLionel Sambuc		# If directories are /, clear them, so various messages
240523a61ee0SLionel Sambuc		# don't have leading "//".   However, this requires
240623a61ee0SLionel Sambuc		# the use of ${foo:-/} to display the variables.
240723a61ee0SLionel Sambuc		#
240823a61ee0SLionel Sambuc	[ "${SRC_DIR}" = "/" ]	&& SRC_DIR=""
240923a61ee0SLionel Sambuc	[ "${DEST_DIR}" = "/" ]	&& DEST_DIR=""
241023a61ee0SLionel Sambuc
241123a61ee0SLionel Sambuc	detect_x11
241223a61ee0SLionel Sambuc
241323a61ee0SLionel Sambuc	op="$1"
241423a61ee0SLionel Sambuc	shift
241523a61ee0SLionel Sambuc
241623a61ee0SLionel Sambuc	case "${op}" in
241723a61ee0SLionel Sambuc	diff)
241823a61ee0SLionel Sambuc		op=check
241923a61ee0SLionel Sambuc		DIFF_STYLE=n			# default style is RCS
242023a61ee0SLionel Sambuc		OPTIND=1
242123a61ee0SLionel Sambuc		while getopts bcenpuw ch; do
242223a61ee0SLionel Sambuc			case "${ch}" in
242323a61ee0SLionel Sambuc			c|e|n|u)
242423a61ee0SLionel Sambuc				if [ "${DIFF_STYLE}" != "n" -a \
242523a61ee0SLionel Sambuc				    "${DIFF_STYLE}" != "${ch}" ]; then
242623a61ee0SLionel Sambuc					err 2 "conflicting output style: ${ch}"
242723a61ee0SLionel Sambuc				fi
242823a61ee0SLionel Sambuc				DIFF_STYLE="${ch}"
242923a61ee0SLionel Sambuc				;;
243023a61ee0SLionel Sambuc			b|p|w)
243123a61ee0SLionel Sambuc				DIFF_OPT="${DIFF_OPT} -${ch}"
243223a61ee0SLionel Sambuc				;;
243323a61ee0SLionel Sambuc			*)
243423a61ee0SLionel Sambuc				err 2 "unknown diff option"
243523a61ee0SLionel Sambuc				;;
243623a61ee0SLionel Sambuc			esac
243723a61ee0SLionel Sambuc		done
243823a61ee0SLionel Sambuc		shift $((${OPTIND} - 1))
243923a61ee0SLionel Sambuc		;;
244023a61ee0SLionel Sambuc	esac
244123a61ee0SLionel Sambuc
244223a61ee0SLionel Sambuc	case "${op}" in
244323a61ee0SLionel Sambuc
244423a61ee0SLionel Sambuc	usage|help)
244523a61ee0SLionel Sambuc		usage
244623a61ee0SLionel Sambuc		;;
244723a61ee0SLionel Sambuc
244823a61ee0SLionel Sambuc	list)
244923a61ee0SLionel Sambuc		echo "Source directory: ${SRC_DIR:-/}"
245023a61ee0SLionel Sambuc		echo "Target directory: ${DEST_DIR:-/}"
245123a61ee0SLionel Sambuc		if $TGZMODE; then
245223a61ee0SLionel Sambuc			echo " (extracted from: ${SRC_ARG})"
245323a61ee0SLionel Sambuc		fi
245423a61ee0SLionel Sambuc		list
245523a61ee0SLionel Sambuc		;;
245623a61ee0SLionel Sambuc
245723a61ee0SLionel Sambuc	check|fix)
245823a61ee0SLionel Sambuc		todo="$*"
245923a61ee0SLionel Sambuc		: ${todo:="${defaultitems}"}
246023a61ee0SLionel Sambuc
246123a61ee0SLionel Sambuc		# ensure that all supplied items are valid
246223a61ee0SLionel Sambuc		#
246323a61ee0SLionel Sambuc		for i in ${todo}; do
246423a61ee0SLionel Sambuc			eval desc=\"\${desc_${i}}\"
246523a61ee0SLionel Sambuc			[ -n "${desc}" ] || err 2 "Unsupported ${op} '"${i}"'"
246623a61ee0SLionel Sambuc		done
246723a61ee0SLionel Sambuc
246823a61ee0SLionel Sambuc		# perform each check/fix
246923a61ee0SLionel Sambuc		#
247023a61ee0SLionel Sambuc		echo "Source directory: ${SRC_DIR:-/}"
247123a61ee0SLionel Sambuc		if $TGZMODE; then
247223a61ee0SLionel Sambuc			echo " (extracted from: ${SRC_ARG})"
247323a61ee0SLionel Sambuc		fi
247423a61ee0SLionel Sambuc		echo "Target directory: ${DEST_DIR:-/}"
247523a61ee0SLionel Sambuc		items_passed=
247623a61ee0SLionel Sambuc		items_failed=
247723a61ee0SLionel Sambuc		for i in ${todo}; do
247823a61ee0SLionel Sambuc			echo "${i} ${op}:"
247923a61ee0SLionel Sambuc			( eval do_${i} ${op} )
248023a61ee0SLionel Sambuc			if [ $? -eq 0 ]; then
248123a61ee0SLionel Sambuc				items_passed="${items_passed} ${i}"
248223a61ee0SLionel Sambuc			else
248323a61ee0SLionel Sambuc				items_failed="${items_failed} ${i}"
248423a61ee0SLionel Sambuc			fi
248523a61ee0SLionel Sambuc		done
248623a61ee0SLionel Sambuc
248723a61ee0SLionel Sambuc		if [ "${op}" = "check" ]; then
248823a61ee0SLionel Sambuc			plural="checks"
248923a61ee0SLionel Sambuc		else
249023a61ee0SLionel Sambuc			plural="fixes"
249123a61ee0SLionel Sambuc		fi
249223a61ee0SLionel Sambuc
249323a61ee0SLionel Sambuc		echo "${PROGNAME} ${plural} passed:${items_passed}"
249423a61ee0SLionel Sambuc		echo "${PROGNAME} ${plural} failed:${items_failed}"
249523a61ee0SLionel Sambuc		if [ -n "${items_failed}" ]; then
249623a61ee0SLionel Sambuc		    exitstatus=1;
249723a61ee0SLionel Sambuc		    if [ "${op}" = "check" ]; then
249823a61ee0SLionel Sambuc			[ "$MACHINE" = "$(uname -m)" ] && m= || m=" -m $MACHINE"
249923a61ee0SLionel Sambuc			cat <<_Fix_me_
250023a61ee0SLionel SambucTo fix, run:
2501d19d7d58SLionel Sambuc    ${HOST_SH} ${0} ${SRC_ARGLIST} -d ${DEST_DIR:-/}$m fix${items_failed}
250223a61ee0SLionel SambucNote that this may overwrite local changes.
250323a61ee0SLionel Sambuc_Fix_me_
250423a61ee0SLionel Sambuc		    fi
250523a61ee0SLionel Sambuc		fi
250623a61ee0SLionel Sambuc
250723a61ee0SLionel Sambuc		;;
250823a61ee0SLionel Sambuc
250923a61ee0SLionel Sambuc	*)
251023a61ee0SLionel Sambuc		warn "Unknown operation '"${op}"'"
251123a61ee0SLionel Sambuc		usage
251223a61ee0SLionel Sambuc		;;
251323a61ee0SLionel Sambuc
251423a61ee0SLionel Sambuc	esac
251523a61ee0SLionel Sambuc}
251623a61ee0SLionel Sambuc
251723a61ee0SLionel Sambuc# defaults
251823a61ee0SLionel Sambuc#
251923a61ee0SLionel SambucPROGNAME="${0##*/}"
252023a61ee0SLionel SambucSRC_ARG="/usr/src"
252123a61ee0SLionel SambucDEST_DIR="/"
252223a61ee0SLionel Sambuc: ${MACHINE:="$( uname -m )"}	# assume native build if $MACHINE is not set
252323a61ee0SLionel Sambuc: ${MACHINE_ARCH:="$( uname -p )"}# assume native build if not set
252423a61ee0SLionel Sambuc
252523a61ee0SLionel SambucDIFF_STYLE=
252623a61ee0SLionel SambucNOT_FIXED=" (FIX MANUALLY)"
252723a61ee0SLionel SambucSCRATCHDIR="$( mkdtemp )" || err 2 "Can't create scratch directory"
252823a61ee0SLionel Sambuctrap "/bin/rm -rf \"\${SCRATCHDIR}\" ; exit 0" 1 2 3 15	# HUP INT QUIT TERM
252923a61ee0SLionel Sambuc
253023a61ee0SLionel Sambucumask 022
253123a61ee0SLionel Sambucexec 3>/dev/null
253223a61ee0SLionel Sambucexec 4>/dev/null
253323a61ee0SLionel Sambucexitstatus=0
253423a61ee0SLionel Sambuc
253523a61ee0SLionel Sambucmain "$@"
253623a61ee0SLionel Sambuc/bin/rm -rf "${SCRATCHDIR}"
253723a61ee0SLionel Sambucexit $exitstatus
2538