Mon Jul 20 21:03:43 2009 UTC ()
moduli moved with openssh


(christos)
diff -r1.99 -r1.100 src/usr.sbin/postinstall/postinstall

cvs diff -r1.99 -r1.100 src/usr.sbin/postinstall/Attic/postinstall (switch to unified diff)

--- src/usr.sbin/postinstall/Attic/postinstall 2009/06/23 17:58:30 1.99
+++ src/usr.sbin/postinstall/Attic/postinstall 2009/07/20 21:03:42 1.100
@@ -1,1657 +1,1657 @@ @@ -1,1657 +1,1657 @@
1#!/bin/sh 1#!/bin/sh
2# 2#
3# $NetBSD: postinstall,v 1.99 2009/06/23 17:58:30 tron Exp $ 3# $NetBSD: postinstall,v 1.100 2009/07/20 21:03:42 christos Exp $
4# 4#
5# Copyright (c) 2002-2008 The NetBSD Foundation, Inc. 5# Copyright (c) 2002-2008 The NetBSD Foundation, Inc.
6# All rights reserved. 6# All rights reserved.
7# 7#
8# This code is derived from software contributed to The NetBSD Foundation 8# This code is derived from software contributed to The NetBSD Foundation
9# by Luke Mewburn. 9# by Luke Mewburn.
10# 10#
11# Redistribution and use in source and binary forms, with or without 11# Redistribution and use in source and binary forms, with or without
12# modification, are permitted provided that the following conditions 12# modification, are permitted provided that the following conditions
13# are met: 13# are met:
14# 1. Redistributions of source code must retain the above copyright 14# 1. Redistributions of source code must retain the above copyright
15# notice, this list of conditions and the following disclaimer. 15# notice, this list of conditions and the following disclaimer.
16# 2. Redistributions in binary form must reproduce the above copyright 16# 2. Redistributions in binary form must reproduce the above copyright
17# notice, this list of conditions and the following disclaimer in the 17# notice, this list of conditions and the following disclaimer in the
18# documentation and/or other materials provided with the distribution. 18# documentation and/or other materials provided with the distribution.
19# 19#
20# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE. 30# POSSIBILITY OF SUCH DAMAGE.
31# 31#
32# postinstall 32# postinstall
33# Check for or fix configuration changes that occur 33# Check for or fix configuration changes that occur
34# over time as NetBSD evolves. 34# over time as NetBSD evolves.
35# 35#
36 36
37# 37#
38# checks to add: 38# checks to add:
39# - sysctl(8) renames (net.inet6.ip6.bindv6only -> net.inet6.ip6.v6only) 39# - sysctl(8) renames (net.inet6.ip6.bindv6only -> net.inet6.ip6.v6only)
40# - de* -> tlp* migration (/etc/ifconfig.de*, $ifconfig_de*, 40# - de* -> tlp* migration (/etc/ifconfig.de*, $ifconfig_de*,
41# dhclient.conf, ...) ? 41# dhclient.conf, ...) ?
42# - support quiet/verbose mode ? 42# - support quiet/verbose mode ?
43# - differentiate between failures caused by missing source 43# - differentiate between failures caused by missing source
44# and real failures 44# and real failures
45# - install moduli into usr/share/examples/ssh and use from there? 45# - install moduli into usr/share/examples/ssh and use from there?
46# - differentiate between "needs fix" versus "can't fix" issues 46# - differentiate between "needs fix" versus "can't fix" issues
47# 47#
48 48
49# This script is executed as part of a cross build. Allow the build 49# This script is executed as part of a cross build. Allow the build
50# environment to override the locations of some tools. 50# environment to override the locations of some tools.
51: ${AWK:=awk} 51: ${AWK:=awk}
52: ${FGREP:=fgrep} 52: ${FGREP:=fgrep}
53: ${GREP:=grep} 53: ${GREP:=grep}
54: ${MAKE:=make} 54: ${MAKE:=make}
55 55
56# 56#
57# helper functions 57# helper functions
58# 58#
59 59
60err() 60err()
61{ 61{
62 exitval=$1 62 exitval=$1
63 shift 63 shift
64 echo 1>&2 "${PROGNAME}: $*" 64 echo 1>&2 "${PROGNAME}: $*"
65 if [ -n "${SCRATCHDIR}" ]; then 65 if [ -n "${SCRATCHDIR}" ]; then
66 /bin/rm -rf "${SCRATCHDIR}" 66 /bin/rm -rf "${SCRATCHDIR}"
67 fi 67 fi
68 exit ${exitval} 68 exit ${exitval}
69} 69}
70 70
71warn() 71warn()
72{ 72{
73 echo 1>&2 "${PROGNAME}: $*" 73 echo 1>&2 "${PROGNAME}: $*"
74} 74}
75 75
76msg() 76msg()
77{ 77{
78 echo " $*" 78 echo " $*"
79} 79}
80 80
81mkdtemp() 81mkdtemp()
82{ 82{
83 # Make sure we don't loop forever if mkdir will always fail. 83 # Make sure we don't loop forever if mkdir will always fail.
84 [ -d /tmp ] || err 2 /tmp is not a directory 84 [ -d /tmp ] || err 2 /tmp is not a directory
85 [ -w /tmp ] || err 2 /tmp is not writable 85 [ -w /tmp ] || err 2 /tmp is not writable
86 86
87 _base="/tmp/_postinstall.$$" 87 _base="/tmp/_postinstall.$$"
88 _serial=0 88 _serial=0
89 89
90 while true; do 90 while true; do
91 _dir="${_base}.${_serial}" 91 _dir="${_base}.${_serial}"
92 mkdir -m 0700 "${_dir}" && break 92 mkdir -m 0700 "${_dir}" && break
93 _serial=$((${_serial} + 1)) 93 _serial=$((${_serial} + 1))
94 done 94 done
95 echo "${_dir}" 95 echo "${_dir}"
96} 96}
97 97
98# Quote args to make them safe in the shell. 98# Quote args to make them safe in the shell.
99# Usage: quotedlist="$(shell_quote args...)" 99# Usage: quotedlist="$(shell_quote args...)"
100# 100#
101# After building up a quoted list, use it by evaling it inside 101# After building up a quoted list, use it by evaling it inside
102# double quotes, like this: 102# double quotes, like this:
103# eval "set -- $quotedlist" 103# eval "set -- $quotedlist"
104# or like this: 104# or like this:
105# eval "\$command $quotedlist \$filename" 105# eval "\$command $quotedlist \$filename"
106shell_quote() 106shell_quote()
107{ 107{
108 local result='' 108 local result=''
109 local arg 109 local arg
110 for arg in "$@" ; do 110 for arg in "$@" ; do
111 # Append a space if necessary 111 # Append a space if necessary
112 result="${result}${result:+ }" 112 result="${result}${result:+ }"
113 # Convert each embedded ' to '\'', 113 # Convert each embedded ' to '\'',
114 # then insert ' at the beginning of the first line, 114 # then insert ' at the beginning of the first line,
115 # and append ' at the end of the last line. 115 # and append ' at the end of the last line.
116 result="${result}$(printf "%s\n" "$arg" | \ 116 result="${result}$(printf "%s\n" "$arg" | \
117 sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")" 117 sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
118 done 118 done
119 printf "%s\n" "$result" 119 printf "%s\n" "$result"
120} 120}
121 121
122 122
123# additem item description 123# additem item description
124# Add item to list of supported items to check/fix, 124# Add item to list of supported items to check/fix,
125# which are checked/fixed by default if no item is requested by user. 125# which are checked/fixed by default if no item is requested by user.
126# 126#
127additem() 127additem()
128{ 128{
129 [ $# -eq 2 ] || err 3 "USAGE: additem item description" 129 [ $# -eq 2 ] || err 3 "USAGE: additem item description"
130 defaultitems="${defaultitems}${defaultitems:+ }$1" 130 defaultitems="${defaultitems}${defaultitems:+ }$1"
131 eval desc_$1=\"$2\" 131 eval desc_$1=\"$2\"
132} 132}
133 133
134# adddisableditem item description 134# adddisableditem item description
135# Add item to list of supported items to check/fix, 135# Add item to list of supported items to check/fix,
136# but execute the item only if the user asks for it explicitly. 136# but execute the item only if the user asks for it explicitly.
137# 137#
138adddisableditem() 138adddisableditem()
139{ 139{
140 [ $# -eq 2 ] || err 3 "USAGE: adddisableditem item description" 140 [ $# -eq 2 ] || err 3 "USAGE: adddisableditem item description"
141 otheritems="${otheritems}${otheritems:+ }$1" 141 otheritems="${otheritems}${otheritems:+ }$1"
142 eval desc_$1=\"$2\" 142 eval desc_$1=\"$2\"
143} 143}
144 144
145# checkdir op dir mode 145# checkdir op dir mode
146# Ensure dir exists, and if not, create it with the appropriate mode. 146# Ensure dir exists, and if not, create it with the appropriate mode.
147# Returns 0 if ok, 1 otherwise. 147# Returns 0 if ok, 1 otherwise.
148# 148#
149check_dir() 149check_dir()
150{ 150{
151 [ $# -eq 3 ] || err 3 "USAGE: check_dir op dir mode" 151 [ $# -eq 3 ] || err 3 "USAGE: check_dir op dir mode"
152 _cdop="$1" 152 _cdop="$1"
153 _cddir="$2" 153 _cddir="$2"
154 _cdmode="$3" 154 _cdmode="$3"
155 [ -d "${_cddir}" ] && return 0 155 [ -d "${_cddir}" ] && return 0
156 if [ "${_cdop}" = "check" ]; then 156 if [ "${_cdop}" = "check" ]; then
157 msg "${_cddir} is not a directory" 157 msg "${_cddir} is not a directory"
158 return 1 158 return 1
159 elif ! mkdir -m "${_cdmode}" "${_cddir}" ; then 159 elif ! mkdir -m "${_cdmode}" "${_cddir}" ; then
160 msg "Can't create missing ${_cddir}" 160 msg "Can't create missing ${_cddir}"
161 return 1 161 return 1
162 else 162 else
163 msg "Missing ${_cddir} created" 163 msg "Missing ${_cddir} created"
164 fi 164 fi
165 return 0 165 return 0
166} 166}
167 167
168# check_ids op type file id [...] 168# check_ids op type file id [...]
169# Check if file of type "users" or "groups" contains the relevant IDs 169# Check if file of type "users" or "groups" contains the relevant IDs
170# Returns 0 if ok, 1 otherwise. 170# Returns 0 if ok, 1 otherwise.
171#  171#
172check_ids() 172check_ids()
173{ 173{
174 [ $# -ge 4 ] || err 3 "USAGE: checks_ids op type file id [...]" 174 [ $# -ge 4 ] || err 3 "USAGE: checks_ids op type file id [...]"
175 _op="$1" 175 _op="$1"
176 _type="$2" 176 _type="$2"
177 _file="$3" 177 _file="$3"
178 shift 3 178 shift 3
179 #_ids="$@" 179 #_ids="$@"
180 180
181 if [ ! -f "${_file}" ]; then 181 if [ ! -f "${_file}" ]; then
182 msg "${_file} doesn't exist; can't check for missing ${_type}" 182 msg "${_file} doesn't exist; can't check for missing ${_type}"
183 return 1 183 return 1
184 fi 184 fi
185 if [ ! -r "${_file}" ]; then 185 if [ ! -r "${_file}" ]; then
186 msg "${_file} is not readable; can't check for missing ${_type}" 186 msg "${_file} is not readable; can't check for missing ${_type}"
187 return 1 187 return 1
188 fi 188 fi
189 _notfixed="" 189 _notfixed=""
190 if [ "${_op}" = "fix" ]; then 190 if [ "${_op}" = "fix" ]; then
191 _notfixed="${NOT_FIXED}" 191 _notfixed="${NOT_FIXED}"
192 fi 192 fi
193 _missing="$(${AWK} -F: ' 193 _missing="$(${AWK} -F: '
194 BEGIN { 194 BEGIN {
195 for (x = 1; x < ARGC; x++) 195 for (x = 1; x < ARGC; x++)
196 idlist[ARGV[x]]++ 196 idlist[ARGV[x]]++
197 ARGC=1 197 ARGC=1
198 } 198 }
199 { 199 {
200 found[$1]++ 200 found[$1]++
201 } 201 }
202 END { 202 END {
203 for (id in idlist) { 203 for (id in idlist) {
204 if (! (id in found)) 204 if (! (id in found))
205 print id 205 print id
206 } 206 }
207 } 207 }
208 ' "$@" < "${_file}")" || return 1 208 ' "$@" < "${_file}")" || return 1
209 if [ -n "${_missing}" ]; then 209 if [ -n "${_missing}" ]; then
210 msg "Missing ${_type}${_notfixed}:" $(echo ${_missing}) 210 msg "Missing ${_type}${_notfixed}:" $(echo ${_missing})
211 return 1 211 return 1
212 fi 212 fi
213 return 0 213 return 0
214} 214}
215 215
216# populate_dir op onlynew src dest mode file [file ...] 216# populate_dir op onlynew src dest mode file [file ...]
217# Perform op ("check" or "fix") on files in src/ against dest/ 217# Perform op ("check" or "fix") on files in src/ against dest/
218# If op = "check" display missing or changed files, optionally with diffs. 218# If op = "check" display missing or changed files, optionally with diffs.
219# If op != "check" copies any missing or changed files. 219# If op != "check" copies any missing or changed files.
220# If onlynew evaluates to true, changed files are ignored. 220# If onlynew evaluates to true, changed files are ignored.
221# Returns 0 if ok, 1 otherwise. 221# Returns 0 if ok, 1 otherwise.
222# 222#
223populate_dir() 223populate_dir()
224{ 224{
225 [ $# -ge 5 ] || err 3 "USAGE: populate_dir op onlynew src dest mode file [...]" 225 [ $# -ge 5 ] || err 3 "USAGE: populate_dir op onlynew src dest mode file [...]"
226 _op="$1" 226 _op="$1"
227 _onlynew="$2" 227 _onlynew="$2"
228 _src="$3" 228 _src="$3"
229 _dest="$4" 229 _dest="$4"
230 _mode="$5" 230 _mode="$5"
231 shift 5 231 shift 5
232 #_files="$@" 232 #_files="$@"
233 233
234 if [ ! -d "${_src}" ]; then 234 if [ ! -d "${_src}" ]; then
235 msg "${_src} is not a directory; skipping check" 235 msg "${_src} is not a directory; skipping check"
236 return 1 236 return 1
237 fi 237 fi
238 check_dir "${_op}" "${_dest}" 755 || return 1 238 check_dir "${_op}" "${_dest}" 755 || return 1
239 239
240 _cmpdir_rv=0 240 _cmpdir_rv=0
241 for f in "$@"; do 241 for f in "$@"; do
242 fs="${_src}/${f}" 242 fs="${_src}/${f}"
243 fd="${_dest}/${f}" 243 fd="${_dest}/${f}"
244 _error="" 244 _error=""
245 if [ ! -f "${fd}" ]; then 245 if [ ! -f "${fd}" ]; then
246 _error="${fd} does not exist" 246 _error="${fd} does not exist"
247 elif ! cmp -s "${fs}" "${fd}" ; then 247 elif ! cmp -s "${fs}" "${fd}" ; then
248 if $_onlynew; then # leave existing ${fd} alone 248 if $_onlynew; then # leave existing ${fd} alone
249 continue; 249 continue;
250 fi 250 fi
251 _error="${fs} != ${fd}" 251 _error="${fs} != ${fd}"
252 else 252 else
253 continue 253 continue
254 fi 254 fi
255 if [ "${_op}" = "check" ]; then 255 if [ "${_op}" = "check" ]; then
256 msg "${_error}" 256 msg "${_error}"
257 if [ -n "${DIFF_STYLE}" -a -f "${fd}" ]; then 257 if [ -n "${DIFF_STYLE}" -a -f "${fd}" ]; then
258 diff -${DIFF_STYLE} ${DIFF_OPT} "${fd}" "${fs}" 258 diff -${DIFF_STYLE} ${DIFF_OPT} "${fd}" "${fs}"
259 fi 259 fi
260 _cmpdir_rv=1 260 _cmpdir_rv=1
261 elif ! rm -f "${fd}" || 261 elif ! rm -f "${fd}" ||
262 ! cp -f "${fs}" "${fd}"; then 262 ! cp -f "${fs}" "${fd}"; then
263 msg "Can't copy ${fs} to ${fd}" 263 msg "Can't copy ${fs} to ${fd}"
264 _cmpdir_rv=1 264 _cmpdir_rv=1
265 elif ! chmod "${_mode}" "${fd}"; then 265 elif ! chmod "${_mode}" "${fd}"; then
266 msg "Can't change mode of ${fd} to ${_mode}" 266 msg "Can't change mode of ${fd} to ${_mode}"
267 _cmpdir_rv=1 267 _cmpdir_rv=1
268 else 268 else
269 msg "Copied ${fs} to ${fd}" 269 msg "Copied ${fs} to ${fd}"
270 fi 270 fi
271 done 271 done
272 return ${_cmpdir_rv} 272 return ${_cmpdir_rv}
273} 273}
274 274
275# compare_dir op src dest mode file [file ...] 275# compare_dir op src dest mode file [file ...]
276# Perform op ("check" or "fix") on files in src/ against dest/ 276# Perform op ("check" or "fix") on files in src/ against dest/
277# If op = "check" display missing or changed files, optionally with diffs. 277# If op = "check" display missing or changed files, optionally with diffs.
278# If op != "check" copies any missing or changed files. 278# If op != "check" copies any missing or changed files.
279# Returns 0 if ok, 1 otherwise. 279# Returns 0 if ok, 1 otherwise.
280# 280#
281compare_dir() 281compare_dir()
282{ 282{
283 [ $# -ge 4 ] || err 3 "USAGE: compare_dir op src dest mode file [...]" 283 [ $# -ge 4 ] || err 3 "USAGE: compare_dir op src dest mode file [...]"
284 _op="$1" 284 _op="$1"
285 _src="$2" 285 _src="$2"
286 _dest="$3" 286 _dest="$3"
287 _mode="$4" 287 _mode="$4"
288 shift 4 288 shift 4
289 #_files="$@" 289 #_files="$@"
290 290
291 populate_dir "$_op" false "$_src" "$_dest" "$_mode" "$@" 291 populate_dir "$_op" false "$_src" "$_dest" "$_mode" "$@"
292} 292}
293 293
294# move_file op src dest -- 294# move_file op src dest --
295# Check (op == "check") or move (op != "check") from src to dest. 295# Check (op == "check") or move (op != "check") from src to dest.
296# Returns 0 if ok, 1 otherwise. 296# Returns 0 if ok, 1 otherwise.
297# 297#
298move_file() 298move_file()
299{ 299{
300 [ $# -eq 3 ] || err 3 "USAGE: move_file op src dest" 300 [ $# -eq 3 ] || err 3 "USAGE: move_file op src dest"
301 _fm_op="$1" 301 _fm_op="$1"
302 _fm_src="$2" 302 _fm_src="$2"
303 _fm_dest="$3" 303 _fm_dest="$3"
304 304
305 if [ -f "${_fm_src}" -a ! -f "${_fm_dest}" ]; then 305 if [ -f "${_fm_src}" -a ! -f "${_fm_dest}" ]; then
306 if [ "${_fm_op}" = "check" ]; then 306 if [ "${_fm_op}" = "check" ]; then
307 msg "Move ${_fm_src} to ${_fm_dest}" 307 msg "Move ${_fm_src} to ${_fm_dest}"
308 return 1 308 return 1
309 fi 309 fi
310 if ! mv "${_fm_src}" "${_fm_dest}"; then 310 if ! mv "${_fm_src}" "${_fm_dest}"; then
311 msg "Can't move ${_fm_src} to ${_fm_dest}" 311 msg "Can't move ${_fm_src} to ${_fm_dest}"
312 return 1 312 return 1
313 fi 313 fi
314 msg "Moved ${_fm_src} to ${_fm_dest}" 314 msg "Moved ${_fm_src} to ${_fm_dest}"
315 fi 315 fi
316 return 0 316 return 0
317} 317}
318 318
319# rcconf_is_set op name var [verbose] -- 319# rcconf_is_set op name var [verbose] --
320# Load the rcconf for name, and check if obsolete rc.conf(5) variable 320# Load the rcconf for name, and check if obsolete rc.conf(5) variable
321# var is defined or not. 321# var is defined or not.
322# Returns 0 if defined (even to ""), otherwise 1. 322# Returns 0 if defined (even to ""), otherwise 1.
323# If verbose != "", print an obsolete warning if the var is defined. 323# If verbose != "", print an obsolete warning if the var is defined.
324# 324#
325rcconf_is_set() 325rcconf_is_set()
326{ 326{
327 [ $# -ge 3 ] || err 3 "USAGE: rcconf_is_set op name var [verbose]" 327 [ $# -ge 3 ] || err 3 "USAGE: rcconf_is_set op name var [verbose]"
328 _rcis_op="$1" 328 _rcis_op="$1"
329 _rcis_name="$2" 329 _rcis_name="$2"
330 _rcis_var="$3" 330 _rcis_var="$3"
331 _rcis_verbose="$4" 331 _rcis_verbose="$4"
332 _rcis_notfixed="" 332 _rcis_notfixed=""
333 if [ "${_rcis_op}" = "fix" ]; then 333 if [ "${_rcis_op}" = "fix" ]; then
334 _rcis_notfixed="${NOT_FIXED}" 334 _rcis_notfixed="${NOT_FIXED}"
335 fi 335 fi
336 ( 336 (
337 for f in \ 337 for f in \
338 "${DEST_DIR}/etc/rc.conf" \ 338 "${DEST_DIR}/etc/rc.conf" \
339 "${DEST_DIR}/etc/rc.conf.d/${_rcis_name}"; do 339 "${DEST_DIR}/etc/rc.conf.d/${_rcis_name}"; do
340 [ -f "${f}" ] && . "${f}" 340 [ -f "${f}" ] && . "${f}"
341 done 341 done
342 eval echo -n \"\${${_rcis_var}}\" 1>&3 342 eval echo -n \"\${${_rcis_var}}\" 1>&3
343 if eval "[ -n \"\${${_rcis_var}}\" \ 343 if eval "[ -n \"\${${_rcis_var}}\" \
344 -o \"\${${_rcis_var}-UNSET}\" != \"UNSET\" ]"; then 344 -o \"\${${_rcis_var}-UNSET}\" != \"UNSET\" ]"; then
345 if [ -n "${_rcis_verbose}" ]; then 345 if [ -n "${_rcis_verbose}" ]; then
346 msg \ 346 msg \
347 "Obsolete rc.conf(5) variable '\$${_rcis_var}' found.${_rcis_notfixed}" 347 "Obsolete rc.conf(5) variable '\$${_rcis_var}' found.${_rcis_notfixed}"
348 fi 348 fi
349 exit 0 349 exit 0
350 else 350 else
351 exit 1 351 exit 1
352 fi 352 fi
353 ) 353 )
354} 354}
355 355
356# find_file_in_dirlist() file message dir1 [...] -- 356# find_file_in_dirlist() file message dir1 [...] --
357# Find which directory file is in, and sets ${dir} to match. 357# Find which directory file is in, and sets ${dir} to match.
358# Returns 0 if matched, otherwise 1 (and sets ${dir} to ""). 358# Returns 0 if matched, otherwise 1 (and sets ${dir} to "").
359# 359#
360# Generally, check the directory for the "checking from source" case, 360# Generally, check the directory for the "checking from source" case,
361# and then the directory for the "checking from extracted etc.tgz" case. 361# and then the directory for the "checking from extracted etc.tgz" case.
362# 362#
363find_file_in_dirlist() 363find_file_in_dirlist()
364{ 364{
365 [ $# -ge 3 ] || err 3 "USAGE: find_file_in_dirlist file msg dir1 [...]" 365 [ $# -ge 3 ] || err 3 "USAGE: find_file_in_dirlist file msg dir1 [...]"
366 366
367 _file="$1" ; shift 367 _file="$1" ; shift
368 _msg="$1" ; shift 368 _msg="$1" ; shift
369 _dir1st= # first dir in list 369 _dir1st= # first dir in list
370 for dir in "$@"; do 370 for dir in "$@"; do
371 : ${_dir1st:="${dir}"} 371 : ${_dir1st:="${dir}"}
372 if [ -f "${dir}/${_file}" ]; then 372 if [ -f "${dir}/${_file}" ]; then
373 if [ "${_dir1st}" != "${dir}" ]; then 373 if [ "${_dir1st}" != "${dir}" ]; then
374 msg \ 374 msg \
375 "(Checking for ${_msg} from ${dir} instead of ${_dir1st})" 375 "(Checking for ${_msg} from ${dir} instead of ${_dir1st})"
376 fi 376 fi
377 return 0 377 return 0
378 fi 378 fi
379 done 379 done
380 msg "Can't find source directory for ${_msg}" 380 msg "Can't find source directory for ${_msg}"
381 return 1 381 return 1
382} 382}
383 383
384# stat op format target value 384# stat op format target value
385# Call stat(1) on the given target according to the given format, 385# Call stat(1) on the given target according to the given format,
386# if stat(1) is available (it is presumed to live in /usr/bin). 386# if stat(1) is available (it is presumed to live in /usr/bin).
387# If it is not available, this routine will always succeed, otherwise 387# If it is not available, this routine will always succeed, otherwise
388# it returns 0 or 1, depending on whether or not the output from 388# it returns 0 or 1, depending on whether or not the output from
389# stat(1) matches the expected value. 389# stat(1) matches the expected value.
390# 390#
391stat() 391stat()
392{ 392{
393 _stop="$1" 393 _stop="$1"
394 _stfmt="$2" 394 _stfmt="$2"
395 _sttgt="$3" 395 _sttgt="$3"
396 _stval="$4" 396 _stval="$4"
397 397
398 if [ ! -x /usr/bin/stat ]; then 398 if [ ! -x /usr/bin/stat ]; then
399 msg \ 399 msg \
400 "(/usr/bin/stat not available; skipping ${_stop} on ${_sttgt})" 400 "(/usr/bin/stat not available; skipping ${_stop} on ${_sttgt})"
401 return 0 401 return 0
402 fi 402 fi
403 403
404 _stres="$(/usr/bin/stat -q -f "${_stfmt}" "${_sttgt}")" 404 _stres="$(/usr/bin/stat -q -f "${_stfmt}" "${_sttgt}")"
405 [ "${_stres}" = "${_stval}" ] 405 [ "${_stres}" = "${_stval}" ]
406 return $? 406 return $?
407} 407}
408 408
409# file_exists_exact path 409# file_exists_exact path
410# Returns true if a file exists in the ${DEST_DIR} whose name 410# Returns true if a file exists in the ${DEST_DIR} whose name
411# is exactly ${path}, interpreted in a case-sensitive way 411# is exactly ${path}, interpreted in a case-sensitive way
412# even if the underlying file system is case-insensitive. 412# even if the underlying file system is case-insensitive.
413# 413#
414# The path must begin with '/' or './', and is interpreted as 414# The path must begin with '/' or './', and is interpreted as
415# being relative to ${DEST_DIR}. 415# being relative to ${DEST_DIR}.
416# 416#
417file_exists_exact() 417file_exists_exact()
418{ 418{
419 [ -n "$1" ] || err 3 "USAGE: file_exists_exact path" 419 [ -n "$1" ] || err 3 "USAGE: file_exists_exact path"
420 _path="${1#.}" 420 _path="${1#.}"
421 [ -h "${DEST_DIR}${_path}" ] || \ 421 [ -h "${DEST_DIR}${_path}" ] || \
422 [ -e "${DEST_DIR}${_path}" ] || return 1 422 [ -e "${DEST_DIR}${_path}" ] || return 1
423 while [ "${_path}" != "/" ] ; do 423 while [ "${_path}" != "/" ] ; do
424 _dirname="$(dirname "${_path}" 2>/dev/null)" 424 _dirname="$(dirname "${_path}" 2>/dev/null)"
425 _basename="$(basename "${_path}" 2>/dev/null)" 425 _basename="$(basename "${_path}" 2>/dev/null)"
426 ls -fa "${DEST_DIR}${_dirname}" 2> /dev/null \ 426 ls -fa "${DEST_DIR}${_dirname}" 2> /dev/null \
427 | ${FGREP} -x "${_basename}" >/dev/null \ 427 | ${FGREP} -x "${_basename}" >/dev/null \
428 || return 1 428 || return 1
429 _path="${_dirname}" 429 _path="${_dirname}"
430 done 430 done
431 return 0 431 return 0
432} 432}
433 433
434# obsolete_paths op 434# obsolete_paths op
435# Obsolete the list of paths provided on stdin. 435# Obsolete the list of paths provided on stdin.
436# Each path is relative to ${DEST_DIR}, and should 436# Each path is relative to ${DEST_DIR}, and should
437# be an absolute path or start with `./'. 437# be an absolute path or start with `./'.
438# 438#
439obsolete_paths() 439obsolete_paths()
440{ 440{
441 [ -n "$1" ] || err 3 "USAGE: obsolete_paths fix|check" 441 [ -n "$1" ] || err 3 "USAGE: obsolete_paths fix|check"
442 op="$1" 442 op="$1"
443 443
444 failed=0 444 failed=0
445 while read ofile; do 445 while read ofile; do
446 if ! file_exists_exact "${ofile}"; then 446 if ! file_exists_exact "${ofile}"; then
447 continue 447 continue
448 fi 448 fi
449 ofile="${DEST_DIR}${ofile#.}" 449 ofile="${DEST_DIR}${ofile#.}"
450 cmd="rm" 450 cmd="rm"
451 ftype="file" 451 ftype="file"
452 if [ -h "${ofile}" ]; then 452 if [ -h "${ofile}" ]; then
453 ftype="link" 453 ftype="link"
454 elif [ -d "${ofile}" ]; then 454 elif [ -d "${ofile}" ]; then
455 ftype="directory" 455 ftype="directory"
456 cmd="rmdir" 456 cmd="rmdir"
457 fi 457 fi
458 if [ "${op}" = "check" ]; then 458 if [ "${op}" = "check" ]; then
459 msg "Remove obsolete ${ftype} ${ofile}" 459 msg "Remove obsolete ${ftype} ${ofile}"
460 failed=1 460 failed=1
461 elif ! eval "${cmd} \${ofile}"; then 461 elif ! eval "${cmd} \${ofile}"; then
462 msg "Can't remove obsolete ${ftype} ${ofile}" 462 msg "Can't remove obsolete ${ftype} ${ofile}"
463 failed=1 463 failed=1
464 else 464 else
465 msg "Removed obsolete ${ftype} ${ofile}" 465 msg "Removed obsolete ${ftype} ${ofile}"
466 fi 466 fi
467 done 467 done
468 return ${failed} 468 return ${failed}
469} 469}
470 470
471# obsolete_libs dir 471# obsolete_libs dir
472# Display the minor/teeny shared libraries in dir that are considered 472# Display the minor/teeny shared libraries in dir that are considered
473# to be obsolete. 473# to be obsolete.
474# 474#
475# The implementation supports removing obsolete major libraries 475# The implementation supports removing obsolete major libraries
476# if the awk variable AllLibs is set, although there is no way to 476# if the awk variable AllLibs is set, although there is no way to
477# enable that in the enclosing shell function as this time. 477# enable that in the enclosing shell function as this time.
478# 478#
479obsolete_libs() 479obsolete_libs()
480{ 480{
481 [ $# -eq 1 ] || err 3 "USAGE: obsolete_libs dir" 481 [ $# -eq 1 ] || err 3 "USAGE: obsolete_libs dir"
482 dir="$1" 482 dir="$1"
483 483
484 ( 484 (
485 485
486 if [ ! -e "${DEST_DIR}/${dir}" ] 486 if [ ! -e "${DEST_DIR}/${dir}" ]
487 then 487 then
488 return 0 488 return 0
489 fi 489 fi
490 490
491 cd "${DEST_DIR}/${dir}" || err 2 "can't cd to ${DEST_DIR}/${dir}" 491 cd "${DEST_DIR}/${dir}" || err 2 "can't cd to ${DEST_DIR}/${dir}"
492 echo lib*.so.* \ 492 echo lib*.so.* \
493 | tr ' ' '\n' \ 493 | tr ' ' '\n' \
494 | ${AWK} -v LibDir="${dir}/" ' 494 | ${AWK} -v LibDir="${dir}/" '
495#{ 495#{
496 496
497function digit(v, c, n) { return (n <= c) ? v[n] : 0 } 497function digit(v, c, n) { return (n <= c) ? v[n] : 0 }
498 498
499function checklib(results, line, regex) { 499function checklib(results, line, regex) {
500 if (! match(line, regex)) 500 if (! match(line, regex))
501 return 501 return
502 lib = substr(line, RSTART, RLENGTH) 502 lib = substr(line, RSTART, RLENGTH)
503 rev = substr($0, RLENGTH+1) 503 rev = substr($0, RLENGTH+1)
504 if (! (lib in results)) { 504 if (! (lib in results)) {
505 results[lib] = rev 505 results[lib] = rev
506 return 506 return
507 } 507 }
508 orevc = split(results[lib], orev, ".") 508 orevc = split(results[lib], orev, ".")
509 nrevc = split(rev, nrev, ".") 509 nrevc = split(rev, nrev, ".")
510 maxc = (orevc > nrevc) ? orevc : nrevc 510 maxc = (orevc > nrevc) ? orevc : nrevc
511 for (i = 1; i <= maxc; i++) { 511 for (i = 1; i <= maxc; i++) {
512 res = digit(orev, orevc, i) - digit(nrev, nrevc, i) 512 res = digit(orev, orevc, i) - digit(nrev, nrevc, i)
513 if (res < 0) { 513 if (res < 0) {
514 print LibDir lib results[lib] 514 print LibDir lib results[lib]
515 results[lib] = rev 515 results[lib] = rev
516 return 516 return
517 } else if (res > 0) { 517 } else if (res > 0) {
518 print LibDir lib rev 518 print LibDir lib rev
519 return 519 return
520 } 520 }
521 } 521 }
522} 522}
523 523
524/^lib.*\.so\.[0-9]+\.[0-9]+(\.[0-9]+)?$/ { 524/^lib.*\.so\.[0-9]+\.[0-9]+(\.[0-9]+)?$/ {
525 if (AllLibs) 525 if (AllLibs)
526 checklib(minor, $0, "^lib.*\\.so\\.") 526 checklib(minor, $0, "^lib.*\\.so\\.")
527 else 527 else
528 checklib(found, $0, "^lib.*\\.so\\.[0-9]+\\.") 528 checklib(found, $0, "^lib.*\\.so\\.[0-9]+\\.")
529} 529}
530 530
531/^lib.*\.so\.[0-9]+$/ { 531/^lib.*\.so\.[0-9]+$/ {
532 if (AllLibs) 532 if (AllLibs)
533 checklib(major, $0, "^lib.*\\.so\\.") 533 checklib(major, $0, "^lib.*\\.so\\.")
534} 534}
535 535
536#}' 536#}'
537  537
538 ) 538 )
539} 539}
540 540
541# modify_file op srcfile scratchfile awkprog 541# modify_file op srcfile scratchfile awkprog
542# Apply awkprog to srcfile sending output to scratchfile, and 542# Apply awkprog to srcfile sending output to scratchfile, and
543# if appropriate replace srcfile with scratchfile. 543# if appropriate replace srcfile with scratchfile.
544# 544#
545modify_file() 545modify_file()
546{ 546{
547 [ $# -eq 4 ] || err 3 "USAGE: modify_file op file scratch awkprog" 547 [ $# -eq 4 ] || err 3 "USAGE: modify_file op file scratch awkprog"
548 548
549 _mfop="$1" 549 _mfop="$1"
550 _mffile="$2" 550 _mffile="$2"
551 _mfscratch="$3" 551 _mfscratch="$3"
552 _mfprog="$4" 552 _mfprog="$4"
553 _mffailed=0 553 _mffailed=0
554 554
555 ${AWK} "${_mfprog}" < "${_mffile}" > "${_mfscratch}" 555 ${AWK} "${_mfprog}" < "${_mffile}" > "${_mfscratch}"
556 if ! cmp -s "${_mffile}" "${_mfscratch}"; then 556 if ! cmp -s "${_mffile}" "${_mfscratch}"; then
557 diff "${_mffile}" "${_mfscratch}" > "${_mfscratch}.diffs" 557 diff "${_mffile}" "${_mfscratch}" > "${_mfscratch}.diffs"
558 if [ "${_mfop}" = "check" ]; then 558 if [ "${_mfop}" = "check" ]; then
559 msg "${_mffile} needs the following changes:" 559 msg "${_mffile} needs the following changes:"
560 _mffailed=1 560 _mffailed=1
561 elif ! rm -f "${_mffile}" || 561 elif ! rm -f "${_mffile}" ||
562 ! cp -f "${_mfscratch}" "${_mffile}"; then 562 ! cp -f "${_mfscratch}" "${_mffile}"; then
563 msg "${_mffile} changes not applied:" 563 msg "${_mffile} changes not applied:"
564 _mffailed=1 564 _mffailed=1
565 else 565 else
566 msg "${_mffile} changes applied:" 566 msg "${_mffile} changes applied:"
567 fi 567 fi
568 while read _line; do 568 while read _line; do
569 msg " ${_line}" 569 msg " ${_line}"
570 done < "${_mfscratch}.diffs" 570 done < "${_mfscratch}.diffs"
571 fi 571 fi
572 return ${_mffailed} 572 return ${_mffailed}
573} 573}
574 574
575 575
576# contents_owner op directory user group 576# contents_owner op directory user group
577# Make sure directory and contents are owned (and group-owned) 577# Make sure directory and contents are owned (and group-owned)
578# as specified. 578# as specified.
579# 579#
580contents_owner() 580contents_owner()
581{ 581{
582 [ $# -eq 4 ] || err 3 "USAGE: contents_owner op dir user group" 582 [ $# -eq 4 ] || err 3 "USAGE: contents_owner op dir user group"
583 583
584 _op="$1" 584 _op="$1"
585 _dir="$2" 585 _dir="$2"
586 _user="$3" 586 _user="$3"
587 _grp="$4" 587 _grp="$4"
588 588
589 if [ "${_op}" = "check" ]; then 589 if [ "${_op}" = "check" ]; then
590 if [ ! -z "`find "${_dir}" \( ! -user "${_user}" \) -o \ 590 if [ ! -z "`find "${_dir}" \( ! -user "${_user}" \) -o \
591 \( ! -group "${_grp}" \)`" ]; then 591 \( ! -group "${_grp}" \)`" ]; then
592 msg \ 592 msg \
593 "${_dir} and contents not all owned by ${_user}:${_grp}" 593 "${_dir} and contents not all owned by ${_user}:${_grp}"
594 return 1 594 return 1
595 else 595 else
596 return 0 596 return 0
597 fi 597 fi
598 elif [ "${_op}" = "fix" ]; then 598 elif [ "${_op}" = "fix" ]; then
599 find "${_dir}" \( \( ! -user "${_user}" \) -o \ 599 find "${_dir}" \( \( ! -user "${_user}" \) -o \
600 \( ! -group "${_grp}" \) \) -a -print0 \ 600 \( ! -group "${_grp}" \) \) -a -print0 \
601 | xargs -0 chown "${_user}:${_grp}" 601 | xargs -0 chown "${_user}:${_grp}"
602 fi  602 fi
603} 603}
604 604
605# get_makevar var [var ...] 605# get_makevar var [var ...]
606# Retrieve the value of a user-settable system make variable 606# Retrieve the value of a user-settable system make variable
607get_makevar() 607get_makevar()
608{ 608{
609 $SOURCEMODE || err 3 "get_makevar must be used in source mode" 609 $SOURCEMODE || err 3 "get_makevar must be used in source mode"
610 [ $# -eq 0 ] && err 3 "USAGE: get_makevar var [var ...]" 610 [ $# -eq 0 ] && err 3 "USAGE: get_makevar var [var ...]"
611 611
612 for _var in "$@"; do 612 for _var in "$@"; do
613 _value="$(echo '.include <bsd.own.mk>' | \ 613 _value="$(echo '.include <bsd.own.mk>' | \
614 ${MAKE} -f - -V "${_var}")" 614 ${MAKE} -f - -V "${_var}")"
615 615
616 eval ${_var}=\"${_value}\" 616 eval ${_var}=\"${_value}\"
617 done 617 done
618} 618}
619 619
620# detect_x11 620# detect_x11
621# Detect if X11 components should be analysed and set values of 621# Detect if X11 components should be analysed and set values of
622# relevant variables. 622# relevant variables.
623detect_x11() 623detect_x11()
624{ 624{
625 if $SOURCEMODE; then 625 if $SOURCEMODE; then
626 get_makevar MKX11 X11ROOTDIR 626 get_makevar MKX11 X11ROOTDIR
627 else 627 else
628 if [ -f "${SRC_DIR}/etc/mtree/set.xetc" ]; then 628 if [ -f "${SRC_DIR}/etc/mtree/set.xetc" ]; then
629 MKX11=yes 629 MKX11=yes
630 X11ROOTDIR=/this/value/isnt/used/yet 630 X11ROOTDIR=/this/value/isnt/used/yet
631 else 631 else
632 MKX11=no 632 MKX11=no
633 X11ROOTDIR= 633 X11ROOTDIR=
634 fi 634 fi
635 fi 635 fi
636} 636}
637 637
638# 638#
639# items 639# items
640# ----- 640# -----
641# 641#
642 642
643# 643#
644# bluetooth 644# bluetooth
645# 645#
646additem bluetooth "bluetooth configuration is up to date" 646additem bluetooth "bluetooth configuration is up to date"
647do_bluetooth() 647do_bluetooth()
648{ 648{
649 [ -n "$1" ] || err 3 "USAGE: do_bluetooth fix|check" 649 [ -n "$1" ] || err 3 "USAGE: do_bluetooth fix|check"
650 op="$1" 650 op="$1"
651 failed=0 651 failed=0
652 652
653 populate_dir "${op}" true \ 653 populate_dir "${op}" true \
654 "${SRC_DIR}/etc/bluetooth" "${DEST_DIR}/etc/bluetooth" 644 \ 654 "${SRC_DIR}/etc/bluetooth" "${DEST_DIR}/etc/bluetooth" 644 \
655 hosts protocols btattach.conf btdevctl.conf 655 hosts protocols btattach.conf btdevctl.conf
656 failed=$(( ${failed} + $? )) 656 failed=$(( ${failed} + $? ))
657 657
658 move_file "${op}" "${DEST_DIR}/var/db/btdev.xml" \ 658 move_file "${op}" "${DEST_DIR}/var/db/btdev.xml" \
659 "${DEST_DIR}/var/db/btdevctl.plist" 659 "${DEST_DIR}/var/db/btdevctl.plist"
660 failed=$(( ${failed} + $? )) 660 failed=$(( ${failed} + $? ))
661 661
662 return ${failed} 662 return ${failed}
663} 663}
664 664
665# 665#
666# ddbonpanic 666# ddbonpanic
667# 667#
668additem ddbonpanic "verify ddb.onpanic is configured in sysctl.conf" 668additem ddbonpanic "verify ddb.onpanic is configured in sysctl.conf"
669do_ddbonpanic() 669do_ddbonpanic()
670{ 670{
671 [ -n "$1" ] || err 3 "USAGE: do_ddbonpanic fix|check" 671 [ -n "$1" ] || err 3 "USAGE: do_ddbonpanic fix|check"
672 672
673 if ${GREP} -E '^#*[[:space:]]*ddb\.onpanic[[:space:]]*\??=[[:space:]]*[[:digit:]]+' \ 673 if ${GREP} -E '^#*[[:space:]]*ddb\.onpanic[[:space:]]*\??=[[:space:]]*[[:digit:]]+' \
674 "${DEST_DIR}/etc/sysctl.conf" >/dev/null 2>&1 674 "${DEST_DIR}/etc/sysctl.conf" >/dev/null 2>&1
675 then 675 then
676 result=0 676 result=0
677 else 677 else
678 if [ "$1" = check ]; then 678 if [ "$1" = check ]; then
679 msg \ 679 msg \
680 "The ddb.onpanic behaviour is not explicitly specified in /etc/sysctl.conf" 680 "The ddb.onpanic behaviour is not explicitly specified in /etc/sysctl.conf"
681 result=1 681 result=1
682 else 682 else
683 echo >> "${DEST_DIR}/etc/sysctl.conf" 683 echo >> "${DEST_DIR}/etc/sysctl.conf"
684 sed < "${SRC_DIR}/etc/sysctl.conf" \ 684 sed < "${SRC_DIR}/etc/sysctl.conf" \
685 -e '/^ddb\.onpanic/q' | \ 685 -e '/^ddb\.onpanic/q' | \
686 sed -e '1,/^$/d' >> \ 686 sed -e '1,/^$/d' >> \
687 "${DEST_DIR}/etc/sysctl.conf" 687 "${DEST_DIR}/etc/sysctl.conf"
688 result=$? 688 result=$?
689 fi 689 fi
690 fi 690 fi
691 return ${result} 691 return ${result}
692} 692}
693 693
694# 694#
695# defaults 695# defaults
696# 696#
697additem defaults "/etc/defaults/ being up to date" 697additem defaults "/etc/defaults/ being up to date"
698do_defaults() 698do_defaults()
699{ 699{
700 [ -n "$1" ] || err 3 "USAGE: do_defaults fix|check" 700 [ -n "$1" ] || err 3 "USAGE: do_defaults fix|check"
701 op="$1" 701 op="$1"
702 failed=0 702 failed=0
703 703
704 compare_dir "$op" "${SRC_DIR}/etc/defaults" "${DEST_DIR}/etc/defaults" \ 704 compare_dir "$op" "${SRC_DIR}/etc/defaults" "${DEST_DIR}/etc/defaults" \
705 444 \ 705 444 \
706 daily.conf monthly.conf rc.conf security.conf weekly.conf 706 daily.conf monthly.conf rc.conf security.conf weekly.conf
707 failed=$(( ${failed} + $? )) 707 failed=$(( ${failed} + $? ))
708 708
709 find_file_in_dirlist pf.boot.conf "pf.boot.conf" \ 709 find_file_in_dirlist pf.boot.conf "pf.boot.conf" \
710 "${SRC_DIR}/usr.sbin/pf/etc/defaults" "${SRC_DIR}/etc/defaults" \ 710 "${SRC_DIR}/usr.sbin/pf/etc/defaults" "${SRC_DIR}/etc/defaults" \
711 || return 1 711 || return 1
712 # ${dir} is set by find_file_in_dirlist() 712 # ${dir} is set by find_file_in_dirlist()
713 compare_dir "$op" "${dir}" "${DEST_DIR}/etc/defaults" 444 pf.boot.conf 713 compare_dir "$op" "${dir}" "${DEST_DIR}/etc/defaults" 444 pf.boot.conf
714 failed=$(( ${failed} + $? )) 714 failed=$(( ${failed} + $? ))
715 715
716 return ${failed} 716 return ${failed}
717} 717}
718 718
719# 719#
720# dhcpcd 720# dhcpcd
721# 721#
722additem dhcpcd "dhcpcd configuration is up to date" 722additem dhcpcd "dhcpcd configuration is up to date"
723do_dhcpcd() 723do_dhcpcd()
724{ 724{
725 [ -n "$1" ] || err 3 "USAGE: do_dhcpcd fix|check" 725 [ -n "$1" ] || err 3 "USAGE: do_dhcpcd fix|check"
726 op="$1" 726 op="$1"
727 failed=0 727 failed=0
728 728
729 find_file_in_dirlist dhcpcd.conf "dhcpcd.conf" \ 729 find_file_in_dirlist dhcpcd.conf "dhcpcd.conf" \
730 "${SRC_DIR}/external/bsd/dhcpcd/dist" "${SRC_DIR}/etc" || return 1 730 "${SRC_DIR}/external/bsd/dhcpcd/dist" "${SRC_DIR}/etc" || return 1
731 # ${dir} is set by find_file_in_dirlist() 731 # ${dir} is set by find_file_in_dirlist()
732 populate_dir "$op" true "${dir}" "${DEST_DIR}/etc" 644 dhcpcd.conf 732 populate_dir "$op" true "${dir}" "${DEST_DIR}/etc" 644 dhcpcd.conf
733 failed=$(( ${failed} + $? )) 733 failed=$(( ${failed} + $? ))
734 734
735 return ${failed} 735 return ${failed}
736} 736}
737 737
738# 738#
739# envsys 739# envsys
740# 740#
741additem envsys "envsys configuration is up to date" 741additem envsys "envsys configuration is up to date"
742do_envsys() 742do_envsys()
743{ 743{
744 [ -n "$1" ] || err 3 "USAGE: do_envsys fix|check" 744 [ -n "$1" ] || err 3 "USAGE: do_envsys fix|check"
745 op="$1" 745 op="$1"
746 failed=0 746 failed=0
747 747
748 populate_dir "$op" true "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \ 748 populate_dir "$op" true "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
749 envsys.conf 749 envsys.conf
750 failed=$(( ${failed} + $? )) 750 failed=$(( ${failed} + $? ))
751 751
752 populate_dir "$op" true "${SRC_DIR}/etc/powerd/scripts" \ 752 populate_dir "$op" true "${SRC_DIR}/etc/powerd/scripts" \
753 "${DEST_DIR}/etc/powerd/scripts" 555 sensor_battery \ 753 "${DEST_DIR}/etc/powerd/scripts" 555 sensor_battery \
754 sensor_drive sensor_fan sensor_indicator sensor_power \ 754 sensor_drive sensor_fan sensor_indicator sensor_power \
755 sensor_resistance sensor_temperature sensor_voltage 755 sensor_resistance sensor_temperature sensor_voltage
756 failed=$(( ${failed} + $? )) 756 failed=$(( ${failed} + $? ))
757 757
758 return ${failed} 758 return ${failed}
759} 759}
760 760
761# 761#
762# gid 762# gid
763# 763#
764additem gid "required groups in /etc/group" 764additem gid "required groups in /etc/group"
765do_gid() 765do_gid()
766{ 766{
767 [ -n "$1" ] || err 3 "USAGE: do_gid fix|check" 767 [ -n "$1" ] || err 3 "USAGE: do_gid fix|check"
768 768
769 check_ids "$1" groups "${DEST_DIR}/etc/group" \ 769 check_ids "$1" groups "${DEST_DIR}/etc/group" \
770 named ntpd sshd authpf _pflogd _rwhod _proxy _timedc \ 770 named ntpd sshd authpf _pflogd _rwhod _proxy _timedc \
771 _sdpd _httpd 771 _sdpd _httpd
772} 772}
773 773
774# 774#
775# hosts 775# hosts
776# 776#
777additem hosts "/etc/hosts being up to date" 777additem hosts "/etc/hosts being up to date"
778do_hosts() 778do_hosts()
779{ 779{
780 [ -n "$1" ] || err 3 "USAGE: do_hosts fix|check" 780 [ -n "$1" ] || err 3 "USAGE: do_hosts fix|check"
781 781
782 modify_file "$1" "${DEST_DIR}/etc/hosts" "${SCRATCHDIR}/hosts" ' 782 modify_file "$1" "${DEST_DIR}/etc/hosts" "${SCRATCHDIR}/hosts" '
783 /^(127\.0\.0\.1|::1)[ ]+[^\.]*$/ { 783 /^(127\.0\.0\.1|::1)[ ]+[^\.]*$/ {
784 print $0, "localhost." 784 print $0, "localhost."
785 next 785 next
786 } 786 }
787 { print } 787 { print }
788 ' 788 '
789 return $? 789 return $?
790} 790}
791 791
792# 792#
793# iscsi 793# iscsi
794# 794#
795additem iscsi "/etc/iscsi is populated" 795additem iscsi "/etc/iscsi is populated"
796do_iscsi() 796do_iscsi()
797{ 797{
798 [ -n "$1" ] || err 3 "USAGE: do_iscsi fix|check" 798 [ -n "$1" ] || err 3 "USAGE: do_iscsi fix|check"
799 799
800 populate_dir "${op}" true \ 800 populate_dir "${op}" true \
801 "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 600 auths 801 "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 600 auths
802 populate_dir "${op}" true \ 802 populate_dir "${op}" true \
803 "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 644 targets 803 "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 644 targets
804 return $? 804 return $?
805} 805}
806 806
807# 807#
808# makedev 808# makedev
809# 809#
810additem makedev "/dev/MAKEDEV being up to date" 810additem makedev "/dev/MAKEDEV being up to date"
811do_makedev() 811do_makedev()
812{ 812{
813 [ -n "$1" ] || err 3 "USAGE: do_makedev fix|check" 813 [ -n "$1" ] || err 3 "USAGE: do_makedev fix|check"
814 failed=0 814 failed=0
815 815
816 if [ -f "${SRC_DIR}/etc/MAKEDEV.tmpl" ]; then 816 if [ -f "${SRC_DIR}/etc/MAKEDEV.tmpl" ]; then
817 # generate MAKEDEV from source if source is available 817 # generate MAKEDEV from source if source is available
818 env MACHINE="${MACHINE}" \ 818 env MACHINE="${MACHINE}" \
819 MACHINE_ARCH="${MACHINE_ARCH}" \ 819 MACHINE_ARCH="${MACHINE_ARCH}" \
820 NETBSDSRCDIR="${SRC_DIR}" \ 820 NETBSDSRCDIR="${SRC_DIR}" \
821 ${AWK} -f "${SRC_DIR}/etc/MAKEDEV.awk" \ 821 ${AWK} -f "${SRC_DIR}/etc/MAKEDEV.awk" \
822 "${SRC_DIR}/etc/MAKEDEV.tmpl" > "${SCRATCHDIR}/MAKEDEV" 822 "${SRC_DIR}/etc/MAKEDEV.tmpl" > "${SCRATCHDIR}/MAKEDEV"
823 fi 823 fi
824 824
825 find_file_in_dirlist MAKEDEV "MAKEDEV" \ 825 find_file_in_dirlist MAKEDEV "MAKEDEV" \
826 "${SCRATCHDIR}" "${SRC_DIR}/dev" \ 826 "${SCRATCHDIR}" "${SRC_DIR}/dev" \
827 || return 1 827 || return 1
828 # ${dir} is set by find_file_in_dirlist() 828 # ${dir} is set by find_file_in_dirlist()
829 compare_dir "$1" "${dir}" "${DEST_DIR}/dev" 555 MAKEDEV 829 compare_dir "$1" "${dir}" "${DEST_DIR}/dev" 555 MAKEDEV
830 failed=$(( ${failed} + $? )) 830 failed=$(( ${failed} + $? ))
831 831
832 find_file_in_dirlist MAKEDEV.local "MAKEDEV.local" \ 832 find_file_in_dirlist MAKEDEV.local "MAKEDEV.local" \
833 "${SRC_DIR}/etc" "${SRC_DIR}/dev" \ 833 "${SRC_DIR}/etc" "${SRC_DIR}/dev" \
834 || return 1 834 || return 1
835 # ${dir} is set by find_file_in_dirlist() 835 # ${dir} is set by find_file_in_dirlist()
836 compare_dir "$1" "${dir}" "${DEST_DIR}/dev" 555 MAKEDEV.local 836 compare_dir "$1" "${dir}" "${DEST_DIR}/dev" 555 MAKEDEV.local
837 failed=$(( ${failed} + $? )) 837 failed=$(( ${failed} + $? ))
838 838
839 return ${failed} 839 return ${failed}
840} 840}
841 841
842# 842#
843# motd 843# motd
844# 844#
845additem motd "contents of motd" 845additem motd "contents of motd"
846do_motd() 846do_motd()
847{ 847{
848 [ -n "$1" ] || err 3 "USAGE: do_motd fix|check" 848 [ -n "$1" ] || err 3 "USAGE: do_motd fix|check"
849 849
850 if ${GREP} -i 'http://www.NetBSD.org/Misc/send-pr.html' \ 850 if ${GREP} -i 'http://www.NetBSD.org/Misc/send-pr.html' \
851 "${DEST_DIR}/etc/motd" >/dev/null 2>&1 \ 851 "${DEST_DIR}/etc/motd" >/dev/null 2>&1 \
852 || ${GREP} -i 'http://www.NetBSD.org/support/send-pr.html' \ 852 || ${GREP} -i 'http://www.NetBSD.org/support/send-pr.html' \
853 "${DEST_DIR}/etc/motd" >/dev/null 2>&1 853 "${DEST_DIR}/etc/motd" >/dev/null 2>&1
854 then 854 then
855 tmp1="$(mktemp /tmp/postinstall.motd.XXXXXXXX)" 855 tmp1="$(mktemp /tmp/postinstall.motd.XXXXXXXX)"
856 tmp2="$(mktemp /tmp/postinstall.motd.XXXXXXXX)" 856 tmp2="$(mktemp /tmp/postinstall.motd.XXXXXXXX)"
857 sed '1,2d' <"${SRC_DIR}/etc/motd" >"${tmp1}" 857 sed '1,2d' <"${SRC_DIR}/etc/motd" >"${tmp1}"
858 sed '1,2d' <"${DEST_DIR}/etc/motd" >"${tmp2}" 858 sed '1,2d' <"${DEST_DIR}/etc/motd" >"${tmp2}"
859 859
860 if [ "$1" = check ]; then 860 if [ "$1" = check ]; then
861 cmp -s "${tmp1}" "${tmp2}" 861 cmp -s "${tmp1}" "${tmp2}"
862 result=$? 862 result=$?
863 if [ "${result}" -ne 0 ]; then 863 if [ "${result}" -ne 0 ]; then
864 msg \ 864 msg \
865 "Bug reporting messages do not seem to match the installed release" 865 "Bug reporting messages do not seem to match the installed release"
866 fi 866 fi
867 else 867 else
868 head -n 2 "${DEST_DIR}/etc/motd" >"${tmp1}" 868 head -n 2 "${DEST_DIR}/etc/motd" >"${tmp1}"
869 sed '1,2d' <"${SRC_DIR}/etc/motd" >>"${tmp1}" 869 sed '1,2d' <"${SRC_DIR}/etc/motd" >>"${tmp1}"
870 cp "${tmp1}" "${DEST_DIR}/etc/motd" 870 cp "${tmp1}" "${DEST_DIR}/etc/motd"
871 result=0 871 result=0
872 fi 872 fi
873 873
874 rm -f "${tmp1}" "${tmp2}" 874 rm -f "${tmp1}" "${tmp2}"
875 else 875 else
876 result=0 876 result=0
877 fi 877 fi
878 878
879 return ${result} 879 return ${result}
880} 880}
881 881
882# 882#
883# mtree 883# mtree
884# 884#
885additem mtree "/etc/mtree/ being up to date" 885additem mtree "/etc/mtree/ being up to date"
886do_mtree() 886do_mtree()
887{ 887{
888 [ -n "$1" ] || err 3 "USAGE: do_mtree fix|check" 888 [ -n "$1" ] || err 3 "USAGE: do_mtree fix|check"
889 889
890 compare_dir "$1" "${SRC_DIR}/etc/mtree" "${DEST_DIR}/etc/mtree" 444 \ 890 compare_dir "$1" "${SRC_DIR}/etc/mtree" "${DEST_DIR}/etc/mtree" 444 \
891 NetBSD.dist special 891 NetBSD.dist special
892} 892}
893 893
894# 894#
895# named 895# named
896# 896#
897additem named "named configuration update" 897additem named "named configuration update"
898do_named() 898do_named()
899{ 899{
900 [ -n "$1" ] || err 3 "USAGE: do_named fix|check" 900 [ -n "$1" ] || err 3 "USAGE: do_named fix|check"
901 op="$1" 901 op="$1"
902 902
903 move_file "${op}" \ 903 move_file "${op}" \
904 "${DEST_DIR}/etc/namedb/named.conf" \ 904 "${DEST_DIR}/etc/namedb/named.conf" \
905 "${DEST_DIR}/etc/named.conf" 905 "${DEST_DIR}/etc/named.conf"
906 906
907 compare_dir "${op}" "${SRC_DIR}/etc/namedb" "${DEST_DIR}/etc/namedb" \ 907 compare_dir "${op}" "${SRC_DIR}/etc/namedb" "${DEST_DIR}/etc/namedb" \
908 644 \ 908 644 \
909 root.cache 909 root.cache
910} 910}
911 911
912# 912#
913# pam 913# pam
914# 914#
915additem pam "/etc/pam.d is populated" 915additem pam "/etc/pam.d is populated"
916do_pam() 916do_pam()
917{ 917{
918 [ -n "$1" ] || err 3 "USAGE: do_pam fix|check" 918 [ -n "$1" ] || err 3 "USAGE: do_pam fix|check"
919 op="$1" 919 op="$1"
920 failed=0 920 failed=0
921 921
922 populate_dir "${op}" true "${SRC_DIR}/etc/pam.d" \ 922 populate_dir "${op}" true "${SRC_DIR}/etc/pam.d" \
923 "${DEST_DIR}/etc/pam.d" 644 \ 923 "${DEST_DIR}/etc/pam.d" 644 \
924 README display_manager ftpd gdm imap kde login other passwd \ 924 README display_manager ftpd gdm imap kde login other passwd \
925 pop3 ppp rexecd rsh sshd su system telnetd xdm xserver 925 pop3 ppp rexecd rsh sshd su system telnetd xdm xserver
926 926
927 failed=$(( ${failed} + $? )) 927 failed=$(( ${failed} + $? ))
928 928
929 return ${failed} 929 return ${failed}
930} 930}
931 931
932# 932#
933# periodic 933# periodic
934# 934#
935additem periodic "/etc/{daily,weekly,monthly,security} being up to date" 935additem periodic "/etc/{daily,weekly,monthly,security} being up to date"
936do_periodic() 936do_periodic()
937{ 937{
938 [ -n "$1" ] || err 3 "USAGE: do_periodic fix|check" 938 [ -n "$1" ] || err 3 "USAGE: do_periodic fix|check"
939 939
940 compare_dir "$1" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \ 940 compare_dir "$1" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
941 daily weekly monthly security 941 daily weekly monthly security
942} 942}
943 943
944# 944#
945# pf 945# pf
946# 946#
947additem pf "pf configuration being up to date" 947additem pf "pf configuration being up to date"
948do_pf() 948do_pf()
949{ 949{
950 [ -n "$1" ] || err 3 "USAGE: do_pf fix|check" 950 [ -n "$1" ] || err 3 "USAGE: do_pf fix|check"
951 op="$1" 951 op="$1"
952 failed=0 952 failed=0
953 953
954 find_file_in_dirlist pf.os "pf.os" \ 954 find_file_in_dirlist pf.os "pf.os" \
955 "${SRC_DIR}/dist/pf/etc" "${SRC_DIR}/etc" \ 955 "${SRC_DIR}/dist/pf/etc" "${SRC_DIR}/etc" \
956 || return 1 956 || return 1
957 # ${dir} is set by find_file_in_dirlist() 957 # ${dir} is set by find_file_in_dirlist()
958 populate_dir "${op}" true \ 958 populate_dir "${op}" true \
959 "${dir}" "${DEST_DIR}/etc" 644 \ 959 "${dir}" "${DEST_DIR}/etc" 644 \
960 pf.conf 960 pf.conf
961 failed=$(( ${failed} + $? )) 961 failed=$(( ${failed} + $? ))
962 962
963 compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 pf.os 963 compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 pf.os
964 failed=$(( ${failed} + $? )) 964 failed=$(( ${failed} + $? ))
965 965
966 return ${failed} 966 return ${failed}
967} 967}
968 968
969# 969#
970# rc 970# rc
971# 971#
972additem rc "/etc/rc* and /etc/rc.d/ being up to date" 972additem rc "/etc/rc* and /etc/rc.d/ being up to date"
973do_rc() 973do_rc()
974{ 974{
975 [ -n "$1" ] || err 3 "USAGE: do_rc fix|check" 975 [ -n "$1" ] || err 3 "USAGE: do_rc fix|check"
976 op="$1" 976 op="$1"
977 failed=0 977 failed=0
978 generated_scripts="" 978 generated_scripts=""
979 if [ "${MKX11}" != "no" ]; then 979 if [ "${MKX11}" != "no" ]; then
980 generated_scripts="${generated_scripts} xdm xfs" 980 generated_scripts="${generated_scripts} xdm xfs"
981 fi 981 fi
982 982
983 compare_dir "${op}" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \ 983 compare_dir "${op}" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
984 rc rc.subr rc.shutdown 984 rc rc.subr rc.shutdown
985 failed=$(( ${failed} + $? )) 985 failed=$(( ${failed} + $? ))
986 986
987 if ! $SOURCEMODE; then 987 if ! $SOURCEMODE; then
988 extra_scripts="${generated_scripts}" 988 extra_scripts="${generated_scripts}"
989 else 989 else
990 extra_scripts="" 990 extra_scripts=""
991 fi 991 fi
992 992
993 compare_dir "${op}" "${SRC_DIR}/etc/rc.d" "${DEST_DIR}/etc/rc.d" 555 \ 993 compare_dir "${op}" "${SRC_DIR}/etc/rc.d" "${DEST_DIR}/etc/rc.d" 555 \
994 DAEMON DISKS LOGIN NETWORKING SERVERS \ 994 DAEMON DISKS LOGIN NETWORKING SERVERS \
995 accounting altqd amd apmd \ 995 accounting altqd amd apmd \
996 bootconf.sh bootparams btattach btconfig btdevctl bthcid \ 996 bootconf.sh bootparams btattach btconfig btdevctl bthcid \
997 ccd cgd cleartmp cron \ 997 ccd cgd cleartmp cron \
998 dhclient dhcpcd dhcpd dhcrelay dmesg downinterfaces envsys \ 998 dhclient dhcpcd dhcpd dhcrelay dmesg downinterfaces envsys \
999 fsck fsck_root ftp_proxy ftpd \ 999 fsck fsck_root ftp_proxy ftpd \
1000 hostapd httpd \ 1000 hostapd httpd \
1001 identd ifwatchd inetd ipfilter ipfs ipmon ipnat ipsec \ 1001 identd ifwatchd inetd ipfilter ipfs ipmon ipnat ipsec \
1002 irdaattach iscsi_target isdnd \ 1002 irdaattach iscsi_target isdnd \
1003 kdc \ 1003 kdc \
1004 ldconfig local lpd lvm\ 1004 ldconfig local lpd lvm\
1005 mixerctl mopd motd mountall mountcritlocal mountcritremote \ 1005 mixerctl mopd motd mountall mountcritlocal mountcritremote \
1006 mountd moused mrouted \ 1006 mountd moused mrouted \
1007 named ndbootd network newsyslog nfsd nfslocking ntpd ntpdate \ 1007 named ndbootd network newsyslog nfsd nfslocking ntpd ntpdate \
1008 perusertmp pf pf_boot pflogd postfix powerd ppp pwcheck \ 1008 perusertmp pf pf_boot pflogd postfix powerd ppp pwcheck \
1009 quota \ 1009 quota \
1010 racoon rpcbind raidframe raidframeparity rarpd rbootd rndctl \ 1010 racoon rpcbind raidframe raidframeparity rarpd rbootd rndctl \
1011 root route6d routed rtadvd rtclocaltime rtsold rwho \ 1011 root route6d routed rtadvd rtclocaltime rtsold rwho \
1012 savecore screenblank sdpd securelevel sshd \ 1012 savecore screenblank sdpd securelevel sshd \
1013 staticroute swap1 swap2 sysctl sysdb syslogd \ 1013 staticroute swap1 swap2 sysctl sysdb syslogd \
1014 timed tpctl ttys \ 1014 timed tpctl ttys \
1015 veriexec virecover wdogctl wpa_supplicant wscons wsmoused \ 1015 veriexec virecover wdogctl wpa_supplicant wscons wsmoused \
1016 ypbind yppasswdd ypserv \ 1016 ypbind yppasswdd ypserv \
1017 ${extra_scripts} 1017 ${extra_scripts}
1018 failed=$(( ${failed} + $? )) 1018 failed=$(( ${failed} + $? ))
1019 1019
1020 if $SOURCEMODE && [ -n "${generated_scripts}" ]; then 1020 if $SOURCEMODE && [ -n "${generated_scripts}" ]; then
1021 # generate scripts 1021 # generate scripts
1022 mkdir "${SCRATCHDIR}/rc" 1022 mkdir "${SCRATCHDIR}/rc"
1023 for f in ${generated_scripts}; do 1023 for f in ${generated_scripts}; do
1024 sed -e "s,@X11ROOTDIR@,${X11ROOTDIR},g" \ 1024 sed -e "s,@X11ROOTDIR@,${X11ROOTDIR},g" \
1025 < "${SRC_DIR}/etc/rc.d/${f}.in" \ 1025 < "${SRC_DIR}/etc/rc.d/${f}.in" \
1026 > "${SCRATCHDIR}/rc/${f}" 1026 > "${SCRATCHDIR}/rc/${f}"
1027 done 1027 done
1028 compare_dir "${op}" "${SCRATCHDIR}/rc" \ 1028 compare_dir "${op}" "${SCRATCHDIR}/rc" \
1029 "${DEST_DIR}/etc/rc.d" 555 \ 1029 "${DEST_DIR}/etc/rc.d" 555 \
1030 ${generated_scripts} 1030 ${generated_scripts}
1031 failed=$(( ${failed} + $? )) 1031 failed=$(( ${failed} + $? ))
1032 fi 1032 fi
1033 1033
1034 # check for obsolete rc.d files 1034 # check for obsolete rc.d files
1035 for f in NETWORK btcontrol btuartd fsck.sh kerberos nfsiod servers \ 1035 for f in NETWORK btcontrol btuartd fsck.sh kerberos nfsiod servers \
1036 systemfs daemon gated login poffd portmap sunndd xntpd; do 1036 systemfs daemon gated login poffd portmap sunndd xntpd; do
1037 fd="/etc/rc.d/${f}" 1037 fd="/etc/rc.d/${f}"
1038 [ -e "${DEST_DIR}${fd}" ] && echo "${fd}" 1038 [ -e "${DEST_DIR}${fd}" ] && echo "${fd}"
1039 done | obsolete_paths "${op}" 1039 done | obsolete_paths "${op}"
1040 failed=$(( ${failed} + $? )) 1040 failed=$(( ${failed} + $? ))
1041 1041
1042 # check for obsolete rc.conf(5) variables 1042 # check for obsolete rc.conf(5) variables
1043 set -- amd amd_master \ 1043 set -- amd amd_master \
1044 btcontrol btcontrol_devices \ 1044 btcontrol btcontrol_devices \
1045 critical_filesystems critical_filesystems_beforenet \ 1045 critical_filesystems critical_filesystems_beforenet \
1046 defcorename \ 1046 defcorename \
1047 ip6forwarding \ 1047 ip6forwarding \
1048 mountcritlocal mountcritremote \ 1048 mountcritlocal mountcritremote \
1049 network nfsiod_flags \ 1049 network nfsiod_flags \
1050 sdpd sdpd_control \ 1050 sdpd sdpd_control \
1051 sdpd sdpd_groupname \ 1051 sdpd sdpd_groupname \
1052 sdpd sdpd_username \ 1052 sdpd sdpd_username \
1053 sysctl 1053 sysctl
1054 while [ $# -gt 1 ]; do 1054 while [ $# -gt 1 ]; do
1055 if rcconf_is_set "${op}" "$1" "$2" 1; then 1055 if rcconf_is_set "${op}" "$1" "$2" 1; then
1056 failed=1 1056 failed=1
1057 fi 1057 fi
1058 shift 2 1058 shift 2
1059 done 1059 done
1060 1060
1061 return ${failed} 1061 return ${failed}
1062} 1062}
1063 1063
1064# 1064#
1065# sendmail 1065# sendmail
1066# 1066#
1067adddisableditem sendmail "remove obsolete sendmail configuration files and scripts" 1067adddisableditem sendmail "remove obsolete sendmail configuration files and scripts"
1068do_sendmail() 1068do_sendmail()
1069{ 1069{
1070 [ -n "$1" ] || err 3 "USAGE: do_sendmail fix|check" 1070 [ -n "$1" ] || err 3 "USAGE: do_sendmail fix|check"
1071 op="$1" 1071 op="$1"
1072 failed=0 1072 failed=0
1073 1073
1074 # Don't complain if the "sendmail" package is installed because the 1074 # Don't complain if the "sendmail" package is installed because the
1075 # files might still be in use. 1075 # files might still be in use.
1076 if /usr/sbin/pkg_info -qe sendmail >/dev/null 2>&1; then 1076 if /usr/sbin/pkg_info -qe sendmail >/dev/null 2>&1; then
1077 return 0 1077 return 0
1078 fi 1078 fi
1079 1079
1080 for f in /etc/mail/helpfile /etc/mail/local-host-names \ 1080 for f in /etc/mail/helpfile /etc/mail/local-host-names \
1081 /etc/mail/sendmail.cf /etc/mail/submit.cf /etc/rc.d/sendmail \ 1081 /etc/mail/sendmail.cf /etc/mail/submit.cf /etc/rc.d/sendmail \
1082 /etc/rc.d/smmsp /usr/share/misc/sendmail.hf \ 1082 /etc/rc.d/smmsp /usr/share/misc/sendmail.hf \
1083 $(find /usr/share/sendmail -type f) \ 1083 $(find /usr/share/sendmail -type f) \
1084 $(find /usr/share/sendmail -type d) /var/log/sendmail.st \ 1084 $(find /usr/share/sendmail -type d) /var/log/sendmail.st \
1085 /var/spool/clientmqueue /var/spool/mqueue; do 1085 /var/spool/clientmqueue /var/spool/mqueue; do
1086 [ -e "${DEST_DIR}${f}" ] && echo "${f}" 1086 [ -e "${DEST_DIR}${f}" ] && echo "${f}"
1087 done | obsolete_paths "${op}" 1087 done | obsolete_paths "${op}"
1088 failed=$(( ${failed} + $? )) 1088 failed=$(( ${failed} + $? ))
1089 1089
1090 return ${failed} 1090 return ${failed}
1091} 1091}
1092 1092
1093# 1093#
1094# mailerconf 1094# mailerconf
1095# 1095#
1096adddisableditem mailerconf "update /etc/mailer.conf after sendmail removal" 1096adddisableditem mailerconf "update /etc/mailer.conf after sendmail removal"
1097do_mailerconf() 1097do_mailerconf()
1098{ 1098{
1099 [ -n "$1" ] || err 3 "USAGE: do_mailterconf fix|check" 1099 [ -n "$1" ] || err 3 "USAGE: do_mailterconf fix|check"
1100 op="$1" 1100 op="$1"
1101 1101
1102 failed=0 1102 failed=0
1103 mta_path="$(${AWK} '/^sendmail[ \t]/{print$2}' /etc/mailer.conf)" 1103 mta_path="$(${AWK} '/^sendmail[ \t]/{print$2}' /etc/mailer.conf)"
1104 old_sendmail_path="/usr/libexec/sendmail/sendmail" 1104 old_sendmail_path="/usr/libexec/sendmail/sendmail"
1105 if [ "${mta_path}" = "${old_sendmail_path}" ]; then 1105 if [ "${mta_path}" = "${old_sendmail_path}" ]; then
1106 if [ "$op" = check ]; then 1106 if [ "$op" = check ]; then
1107 msg "mailer.conf points to obsolete ${old_sendmail_path}" 1107 msg "mailer.conf points to obsolete ${old_sendmail_path}"
1108 failed=1; 1108 failed=1;
1109 else 1109 else
1110 populate_dir "${op}" false \ 1110 populate_dir "${op}" false \
1111 "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 mailer.conf 1111 "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 mailer.conf
1112 failed=$? 1112 failed=$?
1113 fi 1113 fi
1114 fi 1114 fi
1115  1115
1116 return ${failed} 1116 return ${failed}
1117} 1117}
1118 1118
1119# 1119#
1120# ssh 1120# ssh
1121# 1121#
1122additem ssh "ssh configuration update" 1122additem ssh "ssh configuration update"
1123do_ssh() 1123do_ssh()
1124{ 1124{
1125 [ -n "$1" ] || err 3 "USAGE: do_ssh fix|check" 1125 [ -n "$1" ] || err 3 "USAGE: do_ssh fix|check"
1126 op="$1" 1126 op="$1"
1127 1127
1128 failed=0 1128 failed=0
1129 _etcssh="${DEST_DIR}/etc/ssh" 1129 _etcssh="${DEST_DIR}/etc/ssh"
1130 if ! check_dir "${op}" "${_etcssh}" 755; then 1130 if ! check_dir "${op}" "${_etcssh}" 755; then
1131 failed=1 1131 failed=1
1132 fi 1132 fi
1133 1133
1134 if [ ${failed} -eq 0 ]; then 1134 if [ ${failed} -eq 0 ]; then
1135 for f in \ 1135 for f in \
1136 ssh_known_hosts ssh_known_hosts2 \ 1136 ssh_known_hosts ssh_known_hosts2 \
1137 ssh_host_dsa_key ssh_host_dsa_key.pub \ 1137 ssh_host_dsa_key ssh_host_dsa_key.pub \
1138 ssh_host_rsa_key ssh_host_rsa_key.pub \ 1138 ssh_host_rsa_key ssh_host_rsa_key.pub \
1139 ssh_host_key ssh_host_key.pub \ 1139 ssh_host_key ssh_host_key.pub \
1140 ; do 1140 ; do
1141 if ! move_file "${op}" \ 1141 if ! move_file "${op}" \
1142 "${DEST_DIR}/etc/${f}" "${_etcssh}/${f}" ; then 1142 "${DEST_DIR}/etc/${f}" "${_etcssh}/${f}" ; then
1143 failed=1 1143 failed=1
1144 fi 1144 fi
1145 done 1145 done
1146 for f in sshd.conf ssh.conf ; do 1146 for f in sshd.conf ssh.conf ; do
1147 # /etc/ssh/ssh{,d}.conf -> ssh{,d}_config 1147 # /etc/ssh/ssh{,d}.conf -> ssh{,d}_config
1148 # 1148 #
1149 if ! move_file "${op}" \ 1149 if ! move_file "${op}" \
1150 "${_etcssh}/${f}" "${_etcssh}/${f%.conf}_config" ; 1150 "${_etcssh}/${f}" "${_etcssh}/${f%.conf}_config" ;
1151 then 1151 then
1152 failed=1 1152 failed=1
1153 fi 1153 fi
1154 # /etc/ssh{,d}.conf -> /etc/ssh/ssh{,d}_config 1154 # /etc/ssh{,d}.conf -> /etc/ssh/ssh{,d}_config
1155 # 1155 #
1156 if ! move_file "${op}" \ 1156 if ! move_file "${op}" \
1157 "${DEST_DIR}/etc/${f}" \ 1157 "${DEST_DIR}/etc/${f}" \
1158 "${_etcssh}/${f%.conf}_config" ; 1158 "${_etcssh}/${f%.conf}_config" ;
1159 then 1159 then
1160 failed=1 1160 failed=1
1161 fi 1161 fi
1162 done 1162 done
1163 fi 1163 fi
1164 1164
1165 sshdconf="" 1165 sshdconf=""
1166 for f in \ 1166 for f in \
1167 "${_etcssh}/sshd_config" \ 1167 "${_etcssh}/sshd_config" \
1168 "${_etcssh}/sshd.conf" \ 1168 "${_etcssh}/sshd.conf" \
1169 "${DEST_DIR}/etc/sshd.conf" ; do 1169 "${DEST_DIR}/etc/sshd.conf" ; do
1170 if [ -f "${f}" ]; then 1170 if [ -f "${f}" ]; then
1171 sshdconf="${f}" 1171 sshdconf="${f}"
1172 break 1172 break
1173 fi 1173 fi
1174 done 1174 done
1175 if [ -n "${sshdconf}" ]; then 1175 if [ -n "${sshdconf}" ]; then
1176 modify_file "${op}" "${sshdconf}" "${SCRATCHDIR}/sshdconf" ' 1176 modify_file "${op}" "${sshdconf}" "${SCRATCHDIR}/sshdconf" '
1177 /^[^#$]/ { 1177 /^[^#$]/ {
1178 kw = tolower($1) 1178 kw = tolower($1)
1179 if (kw == "hostkey" && 1179 if (kw == "hostkey" &&
1180 $2 ~ /^\/etc\/+ssh_host(_[dr]sa)?_key$/ ) { 1180 $2 ~ /^\/etc\/+ssh_host(_[dr]sa)?_key$/ ) {
1181 sub(/\/etc\/+/, "/etc/ssh/") 1181 sub(/\/etc\/+/, "/etc/ssh/")
1182 } 1182 }
1183 if (kw == "rhostsauthentication" || 1183 if (kw == "rhostsauthentication" ||
1184 kw == "verifyreversemapping" || 1184 kw == "verifyreversemapping" ||
1185 kw == "reversemappingcheck") { 1185 kw == "reversemappingcheck") {
1186 sub(/^/, "# DEPRECATED:\t") 1186 sub(/^/, "# DEPRECATED:\t")
1187 } 1187 }
1188 } 1188 }
1189 { print } 1189 { print }
1190 ' 1190 '
1191 failed=$(( ${failed} + $? )) 1191 failed=$(( ${failed} + $? ))
1192 fi 1192 fi
1193 1193
1194 if ! find_file_in_dirlist moduli "moduli" \ 1194 if ! find_file_in_dirlist moduli "moduli" \
1195 "${SRC_DIR}/crypto/dist/ssh" "${SRC_DIR}/etc" ; then 1195 "${SRC_DIR}/crypto/external/bsd/openssh/dist" "${SRC_DIR}/etc" ; then
1196 failed=1 1196 failed=1
1197 # ${dir} is set by find_file_in_dirlist() 1197 # ${dir} is set by find_file_in_dirlist()
1198 elif ! compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 moduli; then 1198 elif ! compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 moduli; then
1199 failed=1 1199 failed=1
1200 fi 1200 fi
1201 1201
1202 if ! check_dir "${op}" "${DEST_DIR}/var/chroot/sshd" 755 ; then 1202 if ! check_dir "${op}" "${DEST_DIR}/var/chroot/sshd" 755 ; then
1203 failed=1 1203 failed=1
1204 fi 1204 fi
1205 1205
1206 if rcconf_is_set "${op}" sshd sshd_conf_dir 1; then 1206 if rcconf_is_set "${op}" sshd sshd_conf_dir 1; then
1207 failed=1 1207 failed=1
1208 fi 1208 fi
1209 1209
1210 return ${failed} 1210 return ${failed}
1211} 1211}
1212 1212
1213# 1213#
1214# wscons 1214# wscons
1215# 1215#
1216additem wscons "wscons configuration file update" 1216additem wscons "wscons configuration file update"
1217do_wscons() 1217do_wscons()
1218{ 1218{
1219 [ -n "$1" ] || err 3 "USAGE: do_wscons fix|check" 1219 [ -n "$1" ] || err 3 "USAGE: do_wscons fix|check"
1220 op="$1" 1220 op="$1"
1221 1221
1222 [ -f "${DEST_DIR}/etc/wscons.conf" ] || return 0 1222 [ -f "${DEST_DIR}/etc/wscons.conf" ] || return 0
1223 1223
1224 failed=0 1224 failed=0
1225 notfixed="" 1225 notfixed=""
1226 if [ "${op}" = "fix" ]; then 1226 if [ "${op}" = "fix" ]; then
1227 notfixed="${NOT_FIXED}" 1227 notfixed="${NOT_FIXED}"
1228 fi 1228 fi
1229 while read _type _arg1 _rest; do 1229 while read _type _arg1 _rest; do
1230 if [ "${_type}" = "mux" -a "${_arg1}" = "1" ]; then 1230 if [ "${_type}" = "mux" -a "${_arg1}" = "1" ]; then
1231 msg \ 1231 msg \
1232 "Obsolete wscons.conf(5) entry \""${_type} ${_arg1}"\" found.${notfixed}" 1232 "Obsolete wscons.conf(5) entry \""${_type} ${_arg1}"\" found.${notfixed}"
1233 failed=1 1233 failed=1
1234 fi 1234 fi
1235 done < "${DEST_DIR}/etc/wscons.conf" 1235 done < "${DEST_DIR}/etc/wscons.conf"
1236 1236
1237 return ${failed} 1237 return ${failed}
1238} 1238}
1239 1239
1240# 1240#
1241# X11 1241# X11
1242# 1242#
1243additem x11 "x11 configuration update" 1243additem x11 "x11 configuration update"
1244do_x11() 1244do_x11()
1245{ 1245{
1246 [ -n "$1" ] || err 3 "USAGE: do_x11 fix|check" 1246 [ -n "$1" ] || err 3 "USAGE: do_x11 fix|check"
1247 op="$1" 1247 op="$1"
1248 1248
1249 failed=0 1249 failed=0
1250 _etcx11="${DEST_DIR}/etc/X11" 1250 _etcx11="${DEST_DIR}/etc/X11"
1251 if [ ! -d "${_etcx11}" ]; then 1251 if [ ! -d "${_etcx11}" ]; then
1252 msg "${_etcx11} is not a directory; skipping check" 1252 msg "${_etcx11} is not a directory; skipping check"
1253 return 0 1253 return 0
1254 fi 1254 fi
1255 _libx11="${DEST_DIR}/usr/X11R6/lib/X11" 1255 _libx11="${DEST_DIR}/usr/X11R6/lib/X11"
1256 if [ ! -d "${_libx11}" ]; then 1256 if [ ! -d "${_libx11}" ]; then
1257 msg "${_libx11} is not a directory; skipping check" 1257 msg "${_libx11} is not a directory; skipping check"
1258 return 0 1258 return 0
1259 fi 1259 fi
1260 1260
1261 _notfixed="" 1261 _notfixed=""
1262 if [ "${op}" = "fix" ]; then 1262 if [ "${op}" = "fix" ]; then
1263 _notfixed="${NOT_FIXED}" 1263 _notfixed="${NOT_FIXED}"
1264 fi 1264 fi
1265 1265
1266 for d in \ 1266 for d in \
1267 fs lbxproxy proxymngr rstart twm xdm xinit xserver xsm \ 1267 fs lbxproxy proxymngr rstart twm xdm xinit xserver xsm \
1268 ; do 1268 ; do
1269 sd="${_libx11}/${d}" 1269 sd="${_libx11}/${d}"
1270 ld="/etc/X11/${d}" 1270 ld="/etc/X11/${d}"
1271 td="${DEST_DIR}${ld}" 1271 td="${DEST_DIR}${ld}"
1272 if [ -h "${sd}" ]; then 1272 if [ -h "${sd}" ]; then
1273 continue 1273 continue
1274 elif [ -d "${sd}" ]; then 1274 elif [ -d "${sd}" ]; then
1275 tdfiles="$(find "${td}" \! -type d)" 1275 tdfiles="$(find "${td}" \! -type d)"
1276 if [ -n "${tdfiles}" ]; then 1276 if [ -n "${tdfiles}" ]; then
1277 msg "${sd} exists yet ${td} already" \ 1277 msg "${sd} exists yet ${td} already" \
1278 "contains files${_notfixed}" 1278 "contains files${_notfixed}"
1279 else 1279 else
1280 msg "Migrate ${sd} to ${td}${_notfixed}" 1280 msg "Migrate ${sd} to ${td}${_notfixed}"
1281 fi 1281 fi
1282 failed=1 1282 failed=1
1283 elif [ -e "${sd}" ]; then 1283 elif [ -e "${sd}" ]; then
1284 msg "Unexpected file ${sd}${_notfixed}" 1284 msg "Unexpected file ${sd}${_notfixed}"
1285 continue 1285 continue
1286 else 1286 else
1287 continue 1287 continue
1288 fi 1288 fi
1289 done 1289 done
1290 1290
1291 return ${failed} 1291 return ${failed}
1292} 1292}
1293 1293
1294# 1294#
1295# uid 1295# uid
1296# 1296#
1297additem uid "required users in /etc/master.passwd" 1297additem uid "required users in /etc/master.passwd"
1298do_uid() 1298do_uid()
1299{ 1299{
1300 [ -n "$1" ] || err 3 "USAGE: do_uid fix|check" 1300 [ -n "$1" ] || err 3 "USAGE: do_uid fix|check"
1301 1301
1302 check_ids "$1" users "${DEST_DIR}/etc/master.passwd" \ 1302 check_ids "$1" users "${DEST_DIR}/etc/master.passwd" \
1303 named ntpd postfix sshd _pflogd _rwhod _proxy _timedc \ 1303 named ntpd postfix sshd _pflogd _rwhod _proxy _timedc \
1304 _sdpd _httpd 1304 _sdpd _httpd
1305} 1305}
1306 1306
1307 1307
1308# 1308#
1309# varrwho 1309# varrwho
1310# 1310#
1311additem varrwho "required ownership of files in /var/rwho" 1311additem varrwho "required ownership of files in /var/rwho"
1312do_varrwho() 1312do_varrwho()
1313{ 1313{
1314 [ -n "$1" ] || err 3 "USAGE: do_varrwho fix|check" 1314 [ -n "$1" ] || err 3 "USAGE: do_varrwho fix|check"
1315 1315
1316 contents_owner "$1" "${DEST_DIR}/var/rwho" _rwhod _rwhod 1316 contents_owner "$1" "${DEST_DIR}/var/rwho" _rwhod _rwhod
1317} 1317}
1318 1318
1319 1319
1320# 1320#
1321# obsolete 1321# obsolete
1322# (this item is last to allow other items to move obsolete files) 1322# (this item is last to allow other items to move obsolete files)
1323# 1323#
1324additem obsolete "remove obsolete file sets and minor libraries" 1324additem obsolete "remove obsolete file sets and minor libraries"
1325do_obsolete() 1325do_obsolete()
1326{ 1326{
1327 [ -n "$1" ] || err 3 "USAGE: do_obsolete fix|check" 1327 [ -n "$1" ] || err 3 "USAGE: do_obsolete fix|check"
1328 op="$1" 1328 op="$1"
1329 failed=0 1329 failed=0
1330 1330
1331 sort -ru "${DEST_DIR}"/var/db/obsolete/* | obsolete_paths "${op}" 1331 sort -ru "${DEST_DIR}"/var/db/obsolete/* | obsolete_paths "${op}"
1332 failed=$(( ${failed} + $? )) 1332 failed=$(( ${failed} + $? ))
1333 1333
1334 ( 1334 (
1335 obsolete_libs /lib 1335 obsolete_libs /lib
1336 obsolete_libs /usr/lib 1336 obsolete_libs /usr/lib
1337 obsolete_libs /usr/lib/i18n 1337 obsolete_libs /usr/lib/i18n
1338 obsolete_libs /usr/X11R6/lib 1338 obsolete_libs /usr/X11R6/lib
1339 obsolete_libs /usr/X11R7/lib 1339 obsolete_libs /usr/X11R7/lib
1340 [ "$MACHINE" = "amd64" ] && obsolete_libs /usr/lib/i386 1340 [ "$MACHINE" = "amd64" ] && obsolete_libs /usr/lib/i386
1341 [ "$MACHINE" = "sparc64" ] && obsolete_libs /usr/lib/sparc 1341 [ "$MACHINE" = "sparc64" ] && obsolete_libs /usr/lib/sparc
1342 ) | obsolete_paths "${op}" 1342 ) | obsolete_paths "${op}"
1343 failed=$(( ${failed} + $? )) 1343 failed=$(( ${failed} + $? ))
1344 1344
1345 return ${failed} 1345 return ${failed}
1346} 1346}
1347 1347
1348 1348
1349# 1349#
1350# end of items 1350# end of items
1351# ------------ 1351# ------------
1352# 1352#
1353 1353
1354 1354
1355usage() 1355usage()
1356{ 1356{
1357 cat 1>&2 << _USAGE_ 1357 cat 1>&2 << _USAGE_
1358Usage: ${PROGNAME} [-s srcdir] [-d destdir] [-m mach] [-a arch] op [item [...]] 1358Usage: ${PROGNAME} [-s srcdir] [-d destdir] [-m mach] [-a arch] op [item [...]]
1359 Perform post-installation checks and/or fixes on a system's 1359 Perform post-installation checks and/or fixes on a system's
1360 configuration files. 1360 configuration files.
1361 If no items are provided, a default set of checks or fixes is applied. 1361 If no items are provided, a default set of checks or fixes is applied.
1362 1362
1363 Options: 1363 Options:
1364 -s {srcdir|tgzfile|tempdir} 1364 -s {srcdir|tgzfile|tempdir}
1365 Location of the source files. This may be any 1365 Location of the source files. This may be any
1366 of the following: 1366 of the following:
1367 * A directory that contains a NetBSD source tree; 1367 * A directory that contains a NetBSD source tree;
1368 * A distribution set file such as "etc.tgz" or 1368 * A distribution set file such as "etc.tgz" or
1369 "xetc.tgz", or a colon-separated list of such 1369 "xetc.tgz", or a colon-separated list of such
1370 files; 1370 files;
1371 * A temporary directory in which one or both of 1371 * A temporary directory in which one or both of
1372 "etc.tgz" and "xetc.tgz" have been extracted. 1372 "etc.tgz" and "xetc.tgz" have been extracted.
1373 [${SRC_DIR:-/}] 1373 [${SRC_DIR:-/}]
1374 -d destdir Destination directory to check. [${DEST_DIR:-/}] 1374 -d destdir Destination directory to check. [${DEST_DIR:-/}]
1375 -m mach MACHINE. [${MACHINE}] 1375 -m mach MACHINE. [${MACHINE}]
1376 -a arch MACHINE_ARCH. [${MACHINE_ARCH}] 1376 -a arch MACHINE_ARCH. [${MACHINE_ARCH}]
1377 1377
1378 Operation may be one of: 1378 Operation may be one of:
1379 help Display this help. 1379 help Display this help.
1380 list List available items. 1380 list List available items.
1381 check Perform post-installation checks on items. 1381 check Perform post-installation checks on items.
1382 diff [diff(1) options ...] 1382 diff [diff(1) options ...]
1383 Similar to 'check' but also output difference of files. 1383 Similar to 'check' but also output difference of files.
1384 fix Apply fixes that 'check' determines need to be applied. 1384 fix Apply fixes that 'check' determines need to be applied.
1385 usage Display this usage. 1385 usage Display this usage.
1386_USAGE_ 1386_USAGE_
1387 exit 2 1387 exit 2
1388} 1388}
1389 1389
1390 1390
1391list() 1391list()
1392{ 1392{
1393 echo "Default set of items (to apply if no items are provided by user):" 1393 echo "Default set of items (to apply if no items are provided by user):"
1394 echo " Item Description" 1394 echo " Item Description"
1395 echo " ---- -----------" 1395 echo " ---- -----------"
1396 for i in ${defaultitems}; do 1396 for i in ${defaultitems}; do
1397 eval desc=\"\${desc_${i}}\" 1397 eval desc=\"\${desc_${i}}\"
1398 printf " %-12s %s\n" "${i}" "${desc}" 1398 printf " %-12s %s\n" "${i}" "${desc}"
1399 done 1399 done
1400 echo "Items disabled by default (must be requested explicitly):" 1400 echo "Items disabled by default (must be requested explicitly):"
1401 echo " Item Description" 1401 echo " Item Description"
1402 echo " ---- -----------" 1402 echo " ---- -----------"
1403 for i in ${otheritems}; do 1403 for i in ${otheritems}; do
1404 eval desc=\"\${desc_${i}}\" 1404 eval desc=\"\${desc_${i}}\"
1405 printf " %-12s %s\n" "${i}" "${desc}" 1405 printf " %-12s %s\n" "${i}" "${desc}"
1406 done 1406 done
1407 1407
1408} 1408}
1409 1409
1410 1410
1411main() 1411main()
1412{ 1412{
1413 TGZLIST= # quoted list list of tgz files 1413 TGZLIST= # quoted list list of tgz files
1414 SRC_ARGLIST= # quoted list of one or more "-s" args 1414 SRC_ARGLIST= # quoted list of one or more "-s" args
1415 N_SRC_ARGS=0 # number of "-s" args 1415 N_SRC_ARGS=0 # number of "-s" args
1416 TGZMODE=false # true if "-s" specifies a tgz file 1416 TGZMODE=false # true if "-s" specifies a tgz file
1417 DIRMODE=false # true if "-s" specified a directory 1417 DIRMODE=false # true if "-s" specified a directory
1418 SOURCEMODE=false # true if "-s" specified a source directory 1418 SOURCEMODE=false # true if "-s" specified a source directory
1419 1419
1420 while getopts s:d:m:a: ch; do 1420 while getopts s:d:m:a: ch; do
1421 case "${ch}" in 1421 case "${ch}" in
1422 s) 1422 s)
1423 qarg="$(shell_quote "${OPTARG}")" 1423 qarg="$(shell_quote "${OPTARG}")"
1424 N_SRC_ARGS=$(( $N_SRC_ARGS + 1 )) 1424 N_SRC_ARGS=$(( $N_SRC_ARGS + 1 ))
1425 SRC_ARGLIST="${SRC_ARGLIST}${SRC_ARGLIST:+ }-s ${qarg}" 1425 SRC_ARGLIST="${SRC_ARGLIST}${SRC_ARGLIST:+ }-s ${qarg}"
1426 if [ -f "${OPTARG}" ]; then 1426 if [ -f "${OPTARG}" ]; then
1427 # arg refers to a *.tgz file. 1427 # arg refers to a *.tgz file.
1428 # This may happen twice, for both 1428 # This may happen twice, for both
1429 # etc.tgz and xetc.tgz, so we build up a 1429 # etc.tgz and xetc.tgz, so we build up a
1430 # quoted list in TGZLIST. 1430 # quoted list in TGZLIST.
1431 TGZMODE=true 1431 TGZMODE=true
1432 TGZLIST="${TGZLIST}${TGZLIST:+ }${qarg}" 1432 TGZLIST="${TGZLIST}${TGZLIST:+ }${qarg}"
1433 # Note that, when TGZMODE is true, 1433 # Note that, when TGZMODE is true,
1434 # SRC_ARG is used only for printing 1434 # SRC_ARG is used only for printing
1435 # human-readable messages. 1435 # human-readable messages.
1436 SRC_ARG="${TGZLIST}" 1436 SRC_ARG="${TGZLIST}"
1437 elif [ -d "${OPTARG}" ]; then 1437 elif [ -d "${OPTARG}" ]; then
1438 # arg refers to a directory. 1438 # arg refers to a directory.
1439 # It might be a source directory, or a 1439 # It might be a source directory, or a
1440 # directory where the sets have already 1440 # directory where the sets have already
1441 # been extracted. 1441 # been extracted.
1442 DIRMODE=true 1442 DIRMODE=true
1443 SRC_ARG="${OPTARG}" 1443 SRC_ARG="${OPTARG}"
1444 if [ -f "${OPTARG}/etc/Makefile" ]; then 1444 if [ -f "${OPTARG}/etc/Makefile" ]; then
1445 SOURCEMODE=true 1445 SOURCEMODE=true
1446 fi 1446 fi
1447 elif [ -f "${OPTARG%%:*}" -a -f "${OPTARG##*:}" \ 1447 elif [ -f "${OPTARG%%:*}" -a -f "${OPTARG##*:}" \
1448 -a ! -f "${OPTARG}" ] 1448 -a ! -f "${OPTARG}" ]
1449 then 1449 then
1450 # Backward compatibility: allow arg to refer 1450 # Backward compatibility: allow arg to refer
1451 # to a colon-separated list of tgz files. 1451 # to a colon-separated list of tgz files.
1452 # Remove this after NetBSD-5.0 is released. 1452 # Remove this after NetBSD-5.0 is released.
1453 cat >&2 <<EOF 1453 cat >&2 <<EOF
1454*** WARNING: The "-s tgzfile1:tgzfile2" option is deprecated. Please use 1454*** WARNING: The "-s tgzfile1:tgzfile2" option is deprecated. Please use
1455 "-s tgzfile1 -s tgzfile2" in future. 1455 "-s tgzfile1 -s tgzfile2" in future.
1456EOF 1456EOF
1457 TGZMODE=true 1457 TGZMODE=true
1458 TGZLIST="${TGZLIST}${TGZLIST:+ }$( \ 1458 TGZLIST="${TGZLIST}${TGZLIST:+ }$( \
1459 IFS=: eval shell_quote \${OPTARG} )" 1459 IFS=: eval shell_quote \${OPTARG} )"
1460 else 1460 else
1461 err 2 "Invalid argument for -s option" 1461 err 2 "Invalid argument for -s option"
1462 fi 1462 fi
1463 ;; 1463 ;;
1464 d) 1464 d)
1465 DEST_DIR="${OPTARG}" 1465 DEST_DIR="${OPTARG}"
1466 ;; 1466 ;;
1467 m) 1467 m)
1468 MACHINE="${OPTARG}" 1468 MACHINE="${OPTARG}"
1469 ;; 1469 ;;
1470 a) 1470 a)
1471 MACHINE_ARCH="${OPTARG}" 1471 MACHINE_ARCH="${OPTARG}"
1472 ;; 1472 ;;
1473 *) 1473 *)
1474 usage 1474 usage
1475 ;; 1475 ;;
1476 esac 1476 esac
1477 done 1477 done
1478 shift $((${OPTIND} - 1)) 1478 shift $((${OPTIND} - 1))
1479 [ $# -gt 0 ] || usage 1479 [ $# -gt 0 ] || usage
1480 1480
1481 if [ "$N_SRC_ARGS" -gt 1 ] && $DIRMODE; then 1481 if [ "$N_SRC_ARGS" -gt 1 ] && $DIRMODE; then
1482 err 2 "Multiple -s args are allowed only with tgz files" 1482 err 2 "Multiple -s args are allowed only with tgz files"
1483 fi 1483 fi
1484 if [ "$N_SRC_ARGS" -eq 0 ]; then 1484 if [ "$N_SRC_ARGS" -eq 0 ]; then
1485 # The default SRC_ARG was set elsewhere 1485 # The default SRC_ARG was set elsewhere
1486 DIRMODE=true 1486 DIRMODE=true
1487 SOURCEMODE=true 1487 SOURCEMODE=true
1488 SRC_ARGLIST="-s $(shell_quote "${SRC_ARG}")" 1488 SRC_ARGLIST="-s $(shell_quote "${SRC_ARG}")"
1489 fi 1489 fi
1490 1490
1491 # 1491 #
1492 # If '-s' arg or args specified tgz files, extract them 1492 # If '-s' arg or args specified tgz files, extract them
1493 # to a scratch directory. 1493 # to a scratch directory.
1494 # 1494 #
1495 if $TGZMODE; then 1495 if $TGZMODE; then
1496 ETCTGZDIR="${SCRATCHDIR}/etc.tgz" 1496 ETCTGZDIR="${SCRATCHDIR}/etc.tgz"
1497 echo "Note: Creating temporary directory ${ETCTGZDIR}" 1497 echo "Note: Creating temporary directory ${ETCTGZDIR}"
1498 if ! mkdir "${ETCTGZDIR}"; then 1498 if ! mkdir "${ETCTGZDIR}"; then
1499 err 2 "Can't create ${ETCTGZDIR}" 1499 err 2 "Can't create ${ETCTGZDIR}"
1500 fi 1500 fi
1501 ( # subshell to localise changes to "$@" 1501 ( # subshell to localise changes to "$@"
1502 eval "set -- ${TGZLIST}" 1502 eval "set -- ${TGZLIST}"
1503 for tgz in "$@"; do 1503 for tgz in "$@"; do
1504 echo "Note: Extracting files from ${tgz}" 1504 echo "Note: Extracting files from ${tgz}"
1505 cat "${tgz}" | ( 1505 cat "${tgz}" | (
1506 cd "${ETCTGZDIR}" && 1506 cd "${ETCTGZDIR}" &&
1507 tar -zxf - 1507 tar -zxf -
1508 ) || err 2 "Can't extract ${tgz}" 1508 ) || err 2 "Can't extract ${tgz}"
1509 done 1509 done
1510 ) 1510 )
1511 SRC_DIR="${ETCTGZDIR}" 1511 SRC_DIR="${ETCTGZDIR}"
1512 else 1512 else
1513 SRC_DIR="${SRC_ARG}" 1513 SRC_DIR="${SRC_ARG}"
1514 fi 1514 fi
1515 1515
1516 [ -d "${SRC_DIR}" ] || err 2 "${SRC_DIR} is not a directory" 1516 [ -d "${SRC_DIR}" ] || err 2 "${SRC_DIR} is not a directory"
1517 [ -d "${DEST_DIR}" ] || err 2 "${DEST_DIR} is not a directory" 1517 [ -d "${DEST_DIR}" ] || err 2 "${DEST_DIR} is not a directory"
1518 [ -n "${MACHINE}" ] || err 2 "\${MACHINE} is not defined" 1518 [ -n "${MACHINE}" ] || err 2 "\${MACHINE} is not defined"
1519 [ -n "${MACHINE_ARCH}" ] || err 2 "\${MACHINE_ARCH} is not defined" 1519 [ -n "${MACHINE_ARCH}" ] || err 2 "\${MACHINE_ARCH} is not defined"
1520 if ! $SOURCEMODE && ! [ -f "${SRC_DIR}/etc/mtree/set.etc" ]; then 1520 if ! $SOURCEMODE && ! [ -f "${SRC_DIR}/etc/mtree/set.etc" ]; then
1521 err 2 "Files from the etc.tgz set are missing" 1521 err 2 "Files from the etc.tgz set are missing"
1522 fi 1522 fi
1523 1523
1524 # If directories are /, clear them, so various messages 1524 # If directories are /, clear them, so various messages
1525 # don't have leading "//". However, this requires 1525 # don't have leading "//". However, this requires
1526 # the use of ${foo:-/} to display the variables. 1526 # the use of ${foo:-/} to display the variables.
1527 # 1527 #
1528 [ "${SRC_DIR}" = "/" ] && SRC_DIR="" 1528 [ "${SRC_DIR}" = "/" ] && SRC_DIR=""
1529 [ "${DEST_DIR}" = "/" ] && DEST_DIR="" 1529 [ "${DEST_DIR}" = "/" ] && DEST_DIR=""
1530 1530
1531 detect_x11 1531 detect_x11
1532 1532
1533 op="$1" 1533 op="$1"
1534 shift 1534 shift
1535 1535
1536 case "${op}" in 1536 case "${op}" in
1537 diff) 1537 diff)
1538 op=check 1538 op=check
1539 DIFF_STYLE=n # default style is RCS 1539 DIFF_STYLE=n # default style is RCS
1540 OPTIND=1 1540 OPTIND=1
1541 while getopts bcenpuw ch; do 1541 while getopts bcenpuw ch; do
1542 case "${ch}" in 1542 case "${ch}" in
1543 c|e|n|u) 1543 c|e|n|u)
1544 if [ "${DIFF_STYLE}" != "n" -a \ 1544 if [ "${DIFF_STYLE}" != "n" -a \
1545 "${DIFF_STYLE}" != "${ch}" ]; then 1545 "${DIFF_STYLE}" != "${ch}" ]; then
1546 err 2 "conflicting output style: ${ch}" 1546 err 2 "conflicting output style: ${ch}"
1547 fi 1547 fi
1548 DIFF_STYLE="${ch}" 1548 DIFF_STYLE="${ch}"
1549 ;; 1549 ;;
1550 b|p|w) 1550 b|p|w)
1551 DIFF_OPT="${DIFF_OPT} -${ch}" 1551 DIFF_OPT="${DIFF_OPT} -${ch}"
1552 ;; 1552 ;;
1553 *) 1553 *)
1554 err 2 "unknown diff option" 1554 err 2 "unknown diff option"
1555 ;; 1555 ;;
1556 esac 1556 esac
1557 done 1557 done
1558 shift $((${OPTIND} - 1)) 1558 shift $((${OPTIND} - 1))
1559 ;; 1559 ;;
1560 esac 1560 esac
1561 1561
1562 case "${op}" in 1562 case "${op}" in
1563 1563
1564 usage|help) 1564 usage|help)
1565 usage 1565 usage
1566 ;; 1566 ;;
1567 1567
1568 list) 1568 list)
1569 echo "Source directory: ${SRC_DIR:-/}" 1569 echo "Source directory: ${SRC_DIR:-/}"
1570 echo "Target directory: ${DEST_DIR:-/}" 1570 echo "Target directory: ${DEST_DIR:-/}"
1571 if [ "${SRC_DIR}" != "${SRC_ARG}" ]; then 1571 if [ "${SRC_DIR}" != "${SRC_ARG}" ]; then
1572 echo " (extracted from: ${SRC_ARG})" 1572 echo " (extracted from: ${SRC_ARG})"
1573 fi 1573 fi
1574 list 1574 list
1575 ;; 1575 ;;
1576 1576
1577 check|fix) 1577 check|fix)
1578 todo="$*" 1578 todo="$*"
1579 : ${todo:="${defaultitems}"} 1579 : ${todo:="${defaultitems}"}
1580 1580
1581 # ensure that all supplied items are valid 1581 # ensure that all supplied items are valid
1582 # 1582 #
1583 for i in ${todo}; do 1583 for i in ${todo}; do
1584 eval desc=\"\${desc_${i}}\" 1584 eval desc=\"\${desc_${i}}\"
1585 [ -n "${desc}" ] || err 2 "Unsupported ${op} '"${i}"'" 1585 [ -n "${desc}" ] || err 2 "Unsupported ${op} '"${i}"'"
1586 done 1586 done
1587 1587
1588 # perform each check/fix 1588 # perform each check/fix
1589 # 1589 #
1590 echo "Source directory: ${SRC_DIR:-/}" 1590 echo "Source directory: ${SRC_DIR:-/}"
1591 if [ "${SRC_DIR}" != "${SRC_ARG}" ]; then 1591 if [ "${SRC_DIR}" != "${SRC_ARG}" ]; then
1592 echo " (extracted from: ${SRC_ARG})" 1592 echo " (extracted from: ${SRC_ARG})"
1593 fi 1593 fi
1594 echo "Target directory: ${DEST_DIR:-/}" 1594 echo "Target directory: ${DEST_DIR:-/}"
1595 items_passed= 1595 items_passed=
1596 items_failed= 1596 items_failed=
1597 for i in ${todo}; do 1597 for i in ${todo}; do
1598 echo "${i} ${op}:" 1598 echo "${i} ${op}:"
1599 ( eval do_${i} ${op} ) 1599 ( eval do_${i} ${op} )
1600 if [ $? -eq 0 ]; then 1600 if [ $? -eq 0 ]; then
1601 items_passed="${items_passed} ${i}" 1601 items_passed="${items_passed} ${i}"
1602 else 1602 else
1603 items_failed="${items_failed} ${i}" 1603 items_failed="${items_failed} ${i}"
1604 fi 1604 fi
1605 done 1605 done
1606 1606
1607 if [ "${op}" = "check" ]; then 1607 if [ "${op}" = "check" ]; then
1608 plural="checks" 1608 plural="checks"
1609 else 1609 else
1610 plural="fixes" 1610 plural="fixes"
1611 fi 1611 fi
1612 1612
1613 echo "${PROGNAME} ${plural} passed:${items_passed}" 1613 echo "${PROGNAME} ${plural} passed:${items_passed}"
1614 echo "${PROGNAME} ${plural} failed:${items_failed}" 1614 echo "${PROGNAME} ${plural} failed:${items_failed}"
1615 if [ -n "${items_failed}" ]; then 1615 if [ -n "${items_failed}" ]; then
1616 exitstatus=1; 1616 exitstatus=1;
1617 if [ "${op}" = "check" ]; then 1617 if [ "${op}" = "check" ]; then
1618 [ "$MACHINE" = "$(uname -m)" ] && m= || m=" -m $MACHINE" 1618 [ "$MACHINE" = "$(uname -m)" ] && m= || m=" -m $MACHINE"
1619 cat <<_Fix_me_ 1619 cat <<_Fix_me_
1620To fix, run: 1620To fix, run:
1621 ${0} ${SRC_ARGLIST} -d ${DEST_DIR:-/}$m fix${items_failed} 1621 ${0} ${SRC_ARGLIST} -d ${DEST_DIR:-/}$m fix${items_failed}
1622Note that this may overwrite local changes. 1622Note that this may overwrite local changes.
1623_Fix_me_ 1623_Fix_me_
1624 fi 1624 fi
1625 fi 1625 fi
1626 1626
1627 ;; 1627 ;;
1628  1628
1629 *) 1629 *)
1630 warn "Unknown operation '"${op}"'" 1630 warn "Unknown operation '"${op}"'"
1631 usage 1631 usage
1632 ;; 1632 ;;
1633 1633
1634 esac 1634 esac
1635} 1635}
1636 1636
1637# defaults 1637# defaults
1638# 1638#
1639PROGNAME="${0##*/}" 1639PROGNAME="${0##*/}"
1640SRC_ARG="/usr/src" 1640SRC_ARG="/usr/src"
1641DEST_DIR="/" 1641DEST_DIR="/"
1642: ${MACHINE:="$( uname -m )"} # assume native build if $MACHINE is not set 1642: ${MACHINE:="$( uname -m )"} # assume native build if $MACHINE is not set
1643: ${MACHINE_ARCH:="$( uname -p )"}# assume native build if not set 1643: ${MACHINE_ARCH:="$( uname -p )"}# assume native build if not set
1644 1644
1645DIFF_STYLE= 1645DIFF_STYLE=
1646NOT_FIXED=" (FIX MANUALLY)" 1646NOT_FIXED=" (FIX MANUALLY)"
1647SCRATCHDIR="$( mkdtemp )" || err 2 "Can't create scratch directory" 1647SCRATCHDIR="$( mkdtemp )" || err 2 "Can't create scratch directory"
1648trap "/bin/rm -rf \"\${SCRATCHDIR}\" ; exit 0" 1 2 3 15 # HUP INT QUIT TERM 1648trap "/bin/rm -rf \"\${SCRATCHDIR}\" ; exit 0" 1 2 3 15 # HUP INT QUIT TERM
1649 1649
1650umask 022 1650umask 022
1651exec 3>/dev/null 1651exec 3>/dev/null
1652exec 4>/dev/null 1652exec 4>/dev/null
1653exitstatus=0 1653exitstatus=0
1654 1654
1655main "$@" 1655main "$@"
1656/bin/rm -rf "${SCRATCHDIR}" 1656/bin/rm -rf "${SCRATCHDIR}"
1657exit $exitstatus 1657exit $exitstatus