Tue Jun 11 14:39:07 2013 UTC ()
more thorough passwd/group checks.


(christos)
diff -r1.151 -r1.152 src/usr.sbin/postinstall/postinstall

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

--- src/usr.sbin/postinstall/Attic/postinstall 2013/06/10 20:33:31 1.151
+++ src/usr.sbin/postinstall/Attic/postinstall 2013/06/11 14:39:07 1.152
@@ -1,2164 +1,2174 @@ @@ -1,2164 +1,2174 @@
1#!/bin/sh 1#!/bin/sh
2# 2#
3# $NetBSD: postinstall,v 1.151 2013/06/10 20:33:31 mrg Exp $ 3# $NetBSD: postinstall,v 1.152 2013/06/11 14:39:07 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# XXX BE SURE TO USE ${DEST_DIR} PREFIX BEFORE ALL REAL FILE OPERATIONS XXX 38# XXX BE SURE TO USE ${DEST_DIR} PREFIX BEFORE ALL REAL FILE OPERATIONS XXX
39# 39#
40 40
41# 41#
42# checks to add: 42# checks to add:
43# - sysctl(8) renames (net.inet6.ip6.bindv6only -> net.inet6.ip6.v6only) 43# - sysctl(8) renames (net.inet6.ip6.bindv6only -> net.inet6.ip6.v6only)
44# - de* -> tlp* migration (/etc/ifconfig.de*, $ifconfig_de*, 44# - de* -> tlp* migration (/etc/ifconfig.de*, $ifconfig_de*,
45# dhclient.conf, ...) ? 45# dhclient.conf, ...) ?
46# - support quiet/verbose mode ? 46# - support quiet/verbose mode ?
47# - differentiate between failures caused by missing source 47# - differentiate between failures caused by missing source
48# and real failures 48# and real failures
49# - install moduli into usr/share/examples/ssh and use from there? 49# - install moduli into usr/share/examples/ssh and use from there?
50# - differentiate between "needs fix" versus "can't fix" issues 50# - differentiate between "needs fix" versus "can't fix" issues
51# 51#
52 52
53# This script is executed as part of a cross build. Allow the build 53# This script is executed as part of a cross build. Allow the build
54# environment to override the locations of some tools. 54# environment to override the locations of some tools.
55: ${AWK:=awk} 55: ${AWK:=awk}
56: ${DB:=db} 56: ${DB:=db}
57: ${GREP:=grep} 57: ${GREP:=grep}
58: ${HOST_SH:=sh} 58: ${HOST_SH:=sh}
59: ${MAKE:=make} 59: ${MAKE:=make}
60: ${PWD_MKDB:=/usr/sbin/pwd_mkdb} 60: ${PWD_MKDB:=/usr/sbin/pwd_mkdb}
61: ${STAT:=stat} 61: ${STAT:=stat}
62 62
63# 63#
64# helper functions 64# helper functions
65# 65#
66 66
67err() 67err()
68{ 68{
69 exitval=$1 69 exitval=$1
70 shift 70 shift
71 echo 1>&2 "${PROGNAME}: $*" 71 echo 1>&2 "${PROGNAME}: $*"
72 if [ -n "${SCRATCHDIR}" ]; then 72 if [ -n "${SCRATCHDIR}" ]; then
73 /bin/rm -rf "${SCRATCHDIR}" 73 /bin/rm -rf "${SCRATCHDIR}"
74 fi 74 fi
75 exit ${exitval} 75 exit ${exitval}
76} 76}
77 77
78warn() 78warn()
79{ 79{
80 echo 1>&2 "${PROGNAME}: $*" 80 echo 1>&2 "${PROGNAME}: $*"
81} 81}
82 82
83msg() 83msg()
84{ 84{
85 echo " $*" 85 echo " $*"
86} 86}
87 87
88mkdtemp() 88mkdtemp()
89{ 89{
90 # Make sure we don't loop forever if mkdir will always fail. 90 # Make sure we don't loop forever if mkdir will always fail.
91 [ -d /tmp ] || err 2 /tmp is not a directory 91 [ -d /tmp ] || err 2 /tmp is not a directory
92 [ -w /tmp ] || err 2 /tmp is not writable 92 [ -w /tmp ] || err 2 /tmp is not writable
93 93
94 _base="/tmp/_postinstall.$$" 94 _base="/tmp/_postinstall.$$"
95 _serial=0 95 _serial=0
96 96
97 while true; do 97 while true; do
98 _dir="${_base}.${_serial}" 98 _dir="${_base}.${_serial}"
99 mkdir -m 0700 "${_dir}" && break 99 mkdir -m 0700 "${_dir}" && break
100 _serial=$((${_serial} + 1)) 100 _serial=$((${_serial} + 1))
101 done 101 done
102 echo "${_dir}" 102 echo "${_dir}"
103} 103}
104 104
105# Quote args to make them safe in the shell. 105# Quote args to make them safe in the shell.
106# Usage: quotedlist="$(shell_quote args...)" 106# Usage: quotedlist="$(shell_quote args...)"
107# 107#
108# After building up a quoted list, use it by evaling it inside 108# After building up a quoted list, use it by evaling it inside
109# double quotes, like this: 109# double quotes, like this:
110# eval "set -- $quotedlist" 110# eval "set -- $quotedlist"
111# or like this: 111# or like this:
112# eval "\$command $quotedlist \$filename" 112# eval "\$command $quotedlist \$filename"
113shell_quote() 113shell_quote()
114{ 114{
115 local result='' 115 local result=''
116 local arg 116 local arg
117 for arg in "$@" ; do 117 for arg in "$@" ; do
118 # Append a space if necessary 118 # Append a space if necessary
119 result="${result}${result:+ }" 119 result="${result}${result:+ }"
120 # Convert each embedded ' to '\'', 120 # Convert each embedded ' to '\'',
121 # then insert ' at the beginning of the first line, 121 # then insert ' at the beginning of the first line,
122 # and append ' at the end of the last line. 122 # and append ' at the end of the last line.
123 result="${result}$(printf "%s\n" "$arg" | \ 123 result="${result}$(printf "%s\n" "$arg" | \
124 sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")" 124 sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
125 done 125 done
126 printf "%s\n" "$result" 126 printf "%s\n" "$result"
127} 127}
128 128
129 129
130# additem item description 130# additem item description
131# Add item to list of supported items to check/fix, 131# Add item to list of supported items to check/fix,
132# which are checked/fixed by default if no item is requested by user. 132# which are checked/fixed by default if no item is requested by user.
133# 133#
134additem() 134additem()
135{ 135{
136 [ $# -eq 2 ] || err 3 "USAGE: additem item description" 136 [ $# -eq 2 ] || err 3 "USAGE: additem item description"
137 defaultitems="${defaultitems}${defaultitems:+ }$1" 137 defaultitems="${defaultitems}${defaultitems:+ }$1"
138 eval desc_$1=\"$2\" 138 eval desc_$1=\"$2\"
139} 139}
140 140
141# adddisableditem item description 141# adddisableditem item description
142# Add item to list of supported items to check/fix, 142# Add item to list of supported items to check/fix,
143# but execute the item only if the user asks for it explicitly. 143# but execute the item only if the user asks for it explicitly.
144# 144#
145adddisableditem() 145adddisableditem()
146{ 146{
147 [ $# -eq 2 ] || err 3 "USAGE: adddisableditem item description" 147 [ $# -eq 2 ] || err 3 "USAGE: adddisableditem item description"
148 otheritems="${otheritems}${otheritems:+ }$1" 148 otheritems="${otheritems}${otheritems:+ }$1"
149 eval desc_$1=\"$2\" 149 eval desc_$1=\"$2\"
150} 150}
151 151
152# checkdir op dir mode 152# checkdir op dir mode
153# Ensure dir exists, and if not, create it with the appropriate mode. 153# Ensure dir exists, and if not, create it with the appropriate mode.
154# Returns 0 if ok, 1 otherwise. 154# Returns 0 if ok, 1 otherwise.
155# 155#
156check_dir() 156check_dir()
157{ 157{
158 [ $# -eq 3 ] || err 3 "USAGE: check_dir op dir mode" 158 [ $# -eq 3 ] || err 3 "USAGE: check_dir op dir mode"
159 _cdop="$1" 159 _cdop="$1"
160 _cddir="$2" 160 _cddir="$2"
161 _cdmode="$3" 161 _cdmode="$3"
162 [ -d "${_cddir}" ] && return 0 162 [ -d "${_cddir}" ] && return 0
163 if [ "${_cdop}" = "check" ]; then 163 if [ "${_cdop}" = "check" ]; then
164 msg "${_cddir} is not a directory" 164 msg "${_cddir} is not a directory"
165 return 1 165 return 1
166 elif ! mkdir -m "${_cdmode}" "${_cddir}" ; then 166 elif ! mkdir -m "${_cdmode}" "${_cddir}" ; then
167 msg "Can't create missing ${_cddir}" 167 msg "Can't create missing ${_cddir}"
168 return 1 168 return 1
169 else 169 else
170 msg "Missing ${_cddir} created" 170 msg "Missing ${_cddir} created"
171 fi 171 fi
172 return 0 172 return 0
173} 173}
174 174
175# check_ids op type file id [...] 175# check_ids op type file start id [...]
176# Check if file of type "users" or "groups" contains the relevant IDs 176# Check if file of type "users" or "groups" contains the relevant IDs
177# Returns 0 if ok, 1 otherwise. 177# Returns 0 if ok, 1 otherwise.
178#  178#
179check_ids() 179check_ids()
180{ 180{
181 [ $# -ge 4 ] || err 3 "USAGE: checks_ids op type file id [...]" 181 [ $# -ge 5 ] || err 3 "USAGE: checks_ids op type file start id [...]"
182 _op="$1" 182 _op="$1"
183 _type="$2" 183 _type="$2"
184 _file="$3" 184 _file="$3"
185 shift 3 185 _start="$4"
 186 shift 4
186 #_ids="$@" 187 #_ids="$@"
187 188
188 if [ ! -f "${_file}" ]; then 189 if [ ! -f "${_file}" ]; then
189 msg "${_file} doesn't exist; can't check for missing ${_type}" 190 msg "${_file} doesn't exist; can't check for missing ${_type}"
190 return 1 191 return 1
191 fi 192 fi
192 if [ ! -r "${_file}" ]; then 193 if [ ! -r "${_file}" ]; then
193 msg "${_file} is not readable; can't check for missing ${_type}" 194 msg "${_file} is not readable; can't check for missing ${_type}"
194 return 1 195 return 1
195 fi 196 fi
196 _notfixed="" 197 _notfixed=""
197 if [ "${_op}" = "fix" ]; then 198 if [ "${_op}" = "fix" ]; then
198 _notfixed="${NOT_FIXED}" 199 _notfixed="${NOT_FIXED}"
199 fi 200 fi
200 _missing="$(${AWK} -F: ' 201 _missing="$(${AWK} -v start=$_start -F: '
201 BEGIN { 202 BEGIN {
202 for (x = 1; x < ARGC; x++) 203 for (x = 1; x < ARGC; x++) {
 204 if (ARGV[x] = "SKIP")
 205 continue;
203 idlist[ARGV[x]]++ 206 idlist[ARGV[x]]++
 207 value[ARGV[x]] = start + x - 1;
 208 }
204 ARGC=1 209 ARGC=1
205 } 210 }
206 { 211 {
207 found[$1]++ 212 found[$1]++
 213 number[$1] = $3
208 } 214 }
209 END { 215 END {
210 for (id in idlist) { 216 for (id in idlist) {
211 if (! (id in found)) 217 if (!(id in found))
212 print id 218 printf("%s (missing)\n", id)
 219 else if (number[id] != value[id])
 220 printf("%s (%d != %d)\n", id,
 221 number[id], value[id])
 222 start++;
213 } 223 }
214 } 224 }
215 ' "$@" < "${_file}")" || return 1 225 ' "$@" < "${_file}")" || return 1
216 if [ -n "${_missing}" ]; then 226 if [ -n "${_missing}" ]; then
217 msg "Missing ${_type}${_notfixed}:" $(echo ${_missing}) 227 msg "Error ${_type}${_notfixed}:" $(echo ${_missing})
218 return 1 228 return 1
219 fi 229 fi
220 return 0 230 return 0
221} 231}
222 232
223# populate_dir op onlynew src dest mode file [file ...] 233# populate_dir op onlynew src dest mode file [file ...]
224# Perform op ("check" or "fix") on files in src/ against dest/ 234# Perform op ("check" or "fix") on files in src/ against dest/
225# If op = "check" display missing or changed files, optionally with diffs. 235# If op = "check" display missing or changed files, optionally with diffs.
226# If op != "check" copies any missing or changed files. 236# If op != "check" copies any missing or changed files.
227# If onlynew evaluates to true, changed files are ignored. 237# If onlynew evaluates to true, changed files are ignored.
228# Returns 0 if ok, 1 otherwise. 238# Returns 0 if ok, 1 otherwise.
229# 239#
230populate_dir() 240populate_dir()
231{ 241{
232 [ $# -ge 5 ] || err 3 "USAGE: populate_dir op onlynew src dest mode file [...]" 242 [ $# -ge 5 ] || err 3 "USAGE: populate_dir op onlynew src dest mode file [...]"
233 _op="$1" 243 _op="$1"
234 _onlynew="$2" 244 _onlynew="$2"
235 _src="$3" 245 _src="$3"
236 _dest="$4" 246 _dest="$4"
237 _mode="$5" 247 _mode="$5"
238 shift 5 248 shift 5
239 #_files="$@" 249 #_files="$@"
240 250
241 if [ ! -d "${_src}" ]; then 251 if [ ! -d "${_src}" ]; then
242 msg "${_src} is not a directory; skipping check" 252 msg "${_src} is not a directory; skipping check"
243 return 1 253 return 1
244 fi 254 fi
245 check_dir "${_op}" "${_dest}" 755 || return 1 255 check_dir "${_op}" "${_dest}" 755 || return 1
246 256
247 _cmpdir_rv=0 257 _cmpdir_rv=0
248 for f in "$@"; do 258 for f in "$@"; do
249 fs="${_src}/${f}" 259 fs="${_src}/${f}"
250 fd="${_dest}/${f}" 260 fd="${_dest}/${f}"
251 _error="" 261 _error=""
252 if [ ! -f "${fd}" ]; then 262 if [ ! -f "${fd}" ]; then
253 _error="${fd} does not exist" 263 _error="${fd} does not exist"
254 elif ! cmp -s "${fs}" "${fd}" ; then 264 elif ! cmp -s "${fs}" "${fd}" ; then
255 if $_onlynew; then # leave existing ${fd} alone 265 if $_onlynew; then # leave existing ${fd} alone
256 continue; 266 continue;
257 fi 267 fi
258 _error="${fs} != ${fd}" 268 _error="${fs} != ${fd}"
259 else 269 else
260 continue 270 continue
261 fi 271 fi
262 if [ "${_op}" = "check" ]; then 272 if [ "${_op}" = "check" ]; then
263 msg "${_error}" 273 msg "${_error}"
264 if [ -n "${DIFF_STYLE}" -a -f "${fd}" ]; then 274 if [ -n "${DIFF_STYLE}" -a -f "${fd}" ]; then
265 diff -${DIFF_STYLE} ${DIFF_OPT} "${fd}" "${fs}" 275 diff -${DIFF_STYLE} ${DIFF_OPT} "${fd}" "${fs}"
266 fi 276 fi
267 _cmpdir_rv=1 277 _cmpdir_rv=1
268 elif ! rm -f "${fd}" || 278 elif ! rm -f "${fd}" ||
269 ! cp -f "${fs}" "${fd}"; then 279 ! cp -f "${fs}" "${fd}"; then
270 msg "Can't copy ${fs} to ${fd}" 280 msg "Can't copy ${fs} to ${fd}"
271 _cmpdir_rv=1 281 _cmpdir_rv=1
272 elif ! chmod "${_mode}" "${fd}"; then 282 elif ! chmod "${_mode}" "${fd}"; then
273 msg "Can't change mode of ${fd} to ${_mode}" 283 msg "Can't change mode of ${fd} to ${_mode}"
274 _cmpdir_rv=1 284 _cmpdir_rv=1
275 else 285 else
276 msg "Copied ${fs} to ${fd}" 286 msg "Copied ${fs} to ${fd}"
277 fi 287 fi
278 done 288 done
279 return ${_cmpdir_rv} 289 return ${_cmpdir_rv}
280} 290}
281 291
282# compare_dir op src dest mode file [file ...] 292# compare_dir op src dest mode file [file ...]
283# Perform op ("check" or "fix") on files in src/ against dest/ 293# Perform op ("check" or "fix") on files in src/ against dest/
284# If op = "check" display missing or changed files, optionally with diffs. 294# If op = "check" display missing or changed files, optionally with diffs.
285# If op != "check" copies any missing or changed files. 295# If op != "check" copies any missing or changed files.
286# Returns 0 if ok, 1 otherwise. 296# Returns 0 if ok, 1 otherwise.
287# 297#
288compare_dir() 298compare_dir()
289{ 299{
290 [ $# -ge 4 ] || err 3 "USAGE: compare_dir op src dest mode file [...]" 300 [ $# -ge 4 ] || err 3 "USAGE: compare_dir op src dest mode file [...]"
291 _op="$1" 301 _op="$1"
292 _src="$2" 302 _src="$2"
293 _dest="$3" 303 _dest="$3"
294 _mode="$4" 304 _mode="$4"
295 shift 4 305 shift 4
296 #_files="$@" 306 #_files="$@"
297 307
298 populate_dir "$_op" false "$_src" "$_dest" "$_mode" "$@" 308 populate_dir "$_op" false "$_src" "$_dest" "$_mode" "$@"
299} 309}
300 310
301# move_file op src dest -- 311# move_file op src dest --
302# Check (op == "check") or move (op != "check") from src to dest. 312# Check (op == "check") or move (op != "check") from src to dest.
303# Returns 0 if ok, 1 otherwise. 313# Returns 0 if ok, 1 otherwise.
304# 314#
305move_file() 315move_file()
306{ 316{
307 [ $# -eq 3 ] || err 3 "USAGE: move_file op src dest" 317 [ $# -eq 3 ] || err 3 "USAGE: move_file op src dest"
308 _fm_op="$1" 318 _fm_op="$1"
309 _fm_src="$2" 319 _fm_src="$2"
310 _fm_dest="$3" 320 _fm_dest="$3"
311 321
312 if [ -f "${_fm_src}" -a ! -f "${_fm_dest}" ]; then 322 if [ -f "${_fm_src}" -a ! -f "${_fm_dest}" ]; then
313 if [ "${_fm_op}" = "check" ]; then 323 if [ "${_fm_op}" = "check" ]; then
314 msg "Move ${_fm_src} to ${_fm_dest}" 324 msg "Move ${_fm_src} to ${_fm_dest}"
315 return 1 325 return 1
316 fi 326 fi
317 if ! mv "${_fm_src}" "${_fm_dest}"; then 327 if ! mv "${_fm_src}" "${_fm_dest}"; then
318 msg "Can't move ${_fm_src} to ${_fm_dest}" 328 msg "Can't move ${_fm_src} to ${_fm_dest}"
319 return 1 329 return 1
320 fi 330 fi
321 msg "Moved ${_fm_src} to ${_fm_dest}" 331 msg "Moved ${_fm_src} to ${_fm_dest}"
322 fi 332 fi
323 return 0 333 return 0
324} 334}
325 335
326# rcconf_is_set op name var [verbose] -- 336# rcconf_is_set op name var [verbose] --
327# Load the rcconf for name, and check if obsolete rc.conf(5) variable 337# Load the rcconf for name, and check if obsolete rc.conf(5) variable
328# var is defined or not. 338# var is defined or not.
329# Returns 0 if defined (even to ""), otherwise 1. 339# Returns 0 if defined (even to ""), otherwise 1.
330# If verbose != "", print an obsolete warning if the var is defined. 340# If verbose != "", print an obsolete warning if the var is defined.
331# 341#
332rcconf_is_set() 342rcconf_is_set()
333{ 343{
334 [ $# -ge 3 ] || err 3 "USAGE: rcconf_is_set op name var [verbose]" 344 [ $# -ge 3 ] || err 3 "USAGE: rcconf_is_set op name var [verbose]"
335 _rcis_op="$1" 345 _rcis_op="$1"
336 _rcis_name="$2" 346 _rcis_name="$2"
337 _rcis_var="$3" 347 _rcis_var="$3"
338 _rcis_verbose="$4" 348 _rcis_verbose="$4"
339 _rcis_notfixed="" 349 _rcis_notfixed=""
340 if [ "${_rcis_op}" = "fix" ]; then 350 if [ "${_rcis_op}" = "fix" ]; then
341 _rcis_notfixed="${NOT_FIXED}" 351 _rcis_notfixed="${NOT_FIXED}"
342 fi 352 fi
343 ( 353 (
344 for f in \ 354 for f in \
345 "${DEST_DIR}/etc/rc.conf" \ 355 "${DEST_DIR}/etc/rc.conf" \
346 "${DEST_DIR}/etc/rc.conf.d/${_rcis_name}"; do 356 "${DEST_DIR}/etc/rc.conf.d/${_rcis_name}"; do
347 [ -f "${f}" ] && . "${f}" 357 [ -f "${f}" ] && . "${f}"
348 done 358 done
349 eval echo -n \"\${${_rcis_var}}\" 1>&3 359 eval echo -n \"\${${_rcis_var}}\" 1>&3
350 if eval "[ -n \"\${${_rcis_var}}\" \ 360 if eval "[ -n \"\${${_rcis_var}}\" \
351 -o \"\${${_rcis_var}-UNSET}\" != \"UNSET\" ]"; then 361 -o \"\${${_rcis_var}-UNSET}\" != \"UNSET\" ]"; then
352 if [ -n "${_rcis_verbose}" ]; then 362 if [ -n "${_rcis_verbose}" ]; then
353 msg \ 363 msg \
354 "Obsolete rc.conf(5) variable '\$${_rcis_var}' found.${_rcis_notfixed}" 364 "Obsolete rc.conf(5) variable '\$${_rcis_var}' found.${_rcis_notfixed}"
355 fi 365 fi
356 exit 0 366 exit 0
357 else 367 else
358 exit 1 368 exit 1
359 fi 369 fi
360 ) 370 )
361} 371}
362 372
363# rcvar_is_enabled var 373# rcvar_is_enabled var
364# Check if rcvar is enabled 374# Check if rcvar is enabled
365# 375#
366rcvar_is_enabled() 376rcvar_is_enabled()
367{ 377{
368 [ $# -eq 1 ] || err 3 "USAGE: rcvar_is_enabled var" 378 [ $# -eq 1 ] || err 3 "USAGE: rcvar_is_enabled var"
369 _rcie_var="$1" 379 _rcie_var="$1"
370 ( 380 (
371 [ -f "${DEST_DIR}/etc/rc.conf" ] && . "${DEST_DIR}/etc/rc.conf" 381 [ -f "${DEST_DIR}/etc/rc.conf" ] && . "${DEST_DIR}/etc/rc.conf"
372 eval _rcie_val="\${${_rcie_var}}" 382 eval _rcie_val="\${${_rcie_var}}"
373 case $_rcie_val in 383 case $_rcie_val in
374 # "yes", "true", "on", or "1" 384 # "yes", "true", "on", or "1"
375 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) 385 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
376 exit 0 386 exit 0
377 ;; 387 ;;
378 388
379 *) 389 *)
380 exit 1 390 exit 1
381 ;; 391 ;;
382 esac 392 esac
383 ) 393 )
384} 394}
385 395
386# find_file_in_dirlist() file message dir1 [...] -- 396# find_file_in_dirlist() file message dir1 [...] --
387# Find which directory file is in, and sets ${dir} to match. 397# Find which directory file is in, and sets ${dir} to match.
388# Returns 0 if matched, otherwise 1 (and sets ${dir} to ""). 398# Returns 0 if matched, otherwise 1 (and sets ${dir} to "").
389# 399#
390# Generally, check the directory for the "checking from source" case, 400# Generally, check the directory for the "checking from source" case,
391# and then the directory for the "checking from extracted etc.tgz" case. 401# and then the directory for the "checking from extracted etc.tgz" case.
392# 402#
393find_file_in_dirlist() 403find_file_in_dirlist()
394{ 404{
395 [ $# -ge 3 ] || err 3 "USAGE: find_file_in_dirlist file msg dir1 [...]" 405 [ $# -ge 3 ] || err 3 "USAGE: find_file_in_dirlist file msg dir1 [...]"
396 406
397 _file="$1" ; shift 407 _file="$1" ; shift
398 _msg="$1" ; shift 408 _msg="$1" ; shift
399 _dir1st= # first dir in list 409 _dir1st= # first dir in list
400 for dir in "$@"; do 410 for dir in "$@"; do
401 : ${_dir1st:="${dir}"} 411 : ${_dir1st:="${dir}"}
402 if [ -f "${dir}/${_file}" ]; then 412 if [ -f "${dir}/${_file}" ]; then
403 if [ "${_dir1st}" != "${dir}" ]; then 413 if [ "${_dir1st}" != "${dir}" ]; then
404 msg \ 414 msg \
405 "(Checking for ${_msg} from ${dir} instead of ${_dir1st})" 415 "(Checking for ${_msg} from ${dir} instead of ${_dir1st})"
406 fi 416 fi
407 return 0 417 return 0
408 fi 418 fi
409 done 419 done
410 msg "Can't find source directory for ${_msg}" 420 msg "Can't find source directory for ${_msg}"
411 return 1 421 return 1
412} 422}
413 423
414# file_exists_exact path 424# file_exists_exact path
415# Returns true if a file exists in the ${DEST_DIR} whose name 425# Returns true if a file exists in the ${DEST_DIR} whose name
416# is exactly ${path}, interpreted in a case-sensitive way 426# is exactly ${path}, interpreted in a case-sensitive way
417# even if the underlying file system is case-insensitive. 427# even if the underlying file system is case-insensitive.
418# 428#
419# The path must begin with '/' or './', and is interpreted as 429# The path must begin with '/' or './', and is interpreted as
420# being relative to ${DEST_DIR}. 430# being relative to ${DEST_DIR}.
421# 431#
422file_exists_exact() 432file_exists_exact()
423{ 433{
424 [ -n "$1" ] || err 3 "USAGE: file_exists_exact path" 434 [ -n "$1" ] || err 3 "USAGE: file_exists_exact path"
425 _path="${1#.}" 435 _path="${1#.}"
426 [ -h "${DEST_DIR}${_path}" ] || \ 436 [ -h "${DEST_DIR}${_path}" ] || \
427 [ -e "${DEST_DIR}${_path}" ] || return 1 437 [ -e "${DEST_DIR}${_path}" ] || return 1
428 while [ "${_path}" != "/" ] ; do 438 while [ "${_path}" != "/" ] ; do
429 _dirname="$(dirname "${_path}" 2>/dev/null)" 439 _dirname="$(dirname "${_path}" 2>/dev/null)"
430 _basename="$(basename "${_path}" 2>/dev/null)" 440 _basename="$(basename "${_path}" 2>/dev/null)"
431 ls -fa "${DEST_DIR}${_dirname}" 2> /dev/null \ 441 ls -fa "${DEST_DIR}${_dirname}" 2> /dev/null \
432 | ${GREP} -F -x "${_basename}" >/dev/null \ 442 | ${GREP} -F -x "${_basename}" >/dev/null \
433 || return 1 443 || return 1
434 _path="${_dirname}" 444 _path="${_dirname}"
435 done 445 done
436 return 0 446 return 0
437} 447}
438 448
439# obsolete_paths op 449# obsolete_paths op
440# Obsolete the list of paths provided on stdin. 450# Obsolete the list of paths provided on stdin.
441# Each path is relative to ${DEST_DIR}, and should 451# Each path is relative to ${DEST_DIR}, and should
442# be an absolute path or start with `./'. 452# be an absolute path or start with `./'.
443# 453#
444obsolete_paths() 454obsolete_paths()
445{ 455{
446 [ -n "$1" ] || err 3 "USAGE: obsolete_paths fix|check" 456 [ -n "$1" ] || err 3 "USAGE: obsolete_paths fix|check"
447 op="$1" 457 op="$1"
448 458
449 failed=0 459 failed=0
450 while read ofile; do 460 while read ofile; do
451 if ! file_exists_exact "${ofile}"; then 461 if ! file_exists_exact "${ofile}"; then
452 continue 462 continue
453 fi 463 fi
454 ofile="${DEST_DIR}${ofile#.}" 464 ofile="${DEST_DIR}${ofile#.}"
455 cmd="rm" 465 cmd="rm"
456 ftype="file" 466 ftype="file"
457 if [ -h "${ofile}" ]; then 467 if [ -h "${ofile}" ]; then
458 ftype="link" 468 ftype="link"
459 elif [ -d "${ofile}" ]; then 469 elif [ -d "${ofile}" ]; then
460 ftype="directory" 470 ftype="directory"
461 cmd="rmdir" 471 cmd="rmdir"
462 fi 472 fi
463 if [ "${op}" = "check" ]; then 473 if [ "${op}" = "check" ]; then
464 msg "Remove obsolete ${ftype} ${ofile}" 474 msg "Remove obsolete ${ftype} ${ofile}"
465 failed=1 475 failed=1
466 elif ! eval "${cmd} \${ofile}"; then 476 elif ! eval "${cmd} \${ofile}"; then
467 msg "Can't remove obsolete ${ftype} ${ofile}" 477 msg "Can't remove obsolete ${ftype} ${ofile}"
468 failed=1 478 failed=1
469 else 479 else
470 msg "Removed obsolete ${ftype} ${ofile}" 480 msg "Removed obsolete ${ftype} ${ofile}"
471 fi 481 fi
472 done 482 done
473 return ${failed} 483 return ${failed}
474} 484}
475 485
476# obsolete_libs dir 486# obsolete_libs dir
477# Display the minor/teeny shared libraries in dir that are considered 487# Display the minor/teeny shared libraries in dir that are considered
478# to be obsolete. 488# to be obsolete.
479# 489#
480# The implementation supports removing obsolete major libraries 490# The implementation supports removing obsolete major libraries
481# if the awk variable AllLibs is set, although there is no way to 491# if the awk variable AllLibs is set, although there is no way to
482# enable that in the enclosing shell function as this time. 492# enable that in the enclosing shell function as this time.
483# 493#
484obsolete_libs() 494obsolete_libs()
485{ 495{
486 [ $# -eq 1 ] || err 3 "USAGE: obsolete_libs dir" 496 [ $# -eq 1 ] || err 3 "USAGE: obsolete_libs dir"
487 dir="$1" 497 dir="$1"
488 498
489 _obsolete_libs "${dir}" 499 _obsolete_libs "${dir}"
490 _obsolete_libs "/usr/libdata/debug/${dir}" 500 _obsolete_libs "/usr/libdata/debug/${dir}"
491} 501}
492 502
493_obsolete_libs() 503_obsolete_libs()
494{  504{
495 dir="$1" 505 dir="$1"
496 506
497 ( 507 (
498 508
499 if [ ! -e "${DEST_DIR}/${dir}" ] 509 if [ ! -e "${DEST_DIR}/${dir}" ]
500 then 510 then
501 return 0 511 return 0
502 fi 512 fi
503 513
504 cd "${DEST_DIR}/${dir}" || err 2 "can't cd to ${DEST_DIR}/${dir}" 514 cd "${DEST_DIR}/${dir}" || err 2 "can't cd to ${DEST_DIR}/${dir}"
505 echo lib*.so.* \ 515 echo lib*.so.* \
506 | tr ' ' '\n' \ 516 | tr ' ' '\n' \
507 | ${AWK} -v LibDir="${dir}/" ' 517 | ${AWK} -v LibDir="${dir}/" '
508#{ 518#{
509 519
510function digit(v, c, n) { return (n <= c) ? v[n] : 0 } 520function digit(v, c, n) { return (n <= c) ? v[n] : 0 }
511 521
512function checklib(results, line, regex) { 522function checklib(results, line, regex) {
513 if (! match(line, regex)) 523 if (! match(line, regex))
514 return 524 return
515 lib = substr(line, RSTART, RLENGTH) 525 lib = substr(line, RSTART, RLENGTH)
516 rev = substr($0, RLENGTH+1) 526 rev = substr($0, RLENGTH+1)
517 if (! (lib in results)) { 527 if (! (lib in results)) {
518 results[lib] = rev 528 results[lib] = rev
519 return 529 return
520 } 530 }
521 orevc = split(results[lib], orev, ".") 531 orevc = split(results[lib], orev, ".")
522 nrevc = split(rev, nrev, ".") 532 nrevc = split(rev, nrev, ".")
523 maxc = (orevc > nrevc) ? orevc : nrevc 533 maxc = (orevc > nrevc) ? orevc : nrevc
524 for (i = 1; i <= maxc; i++) { 534 for (i = 1; i <= maxc; i++) {
525 res = digit(orev, orevc, i) - digit(nrev, nrevc, i) 535 res = digit(orev, orevc, i) - digit(nrev, nrevc, i)
526 if (res < 0) { 536 if (res < 0) {
527 print LibDir lib results[lib] 537 print LibDir lib results[lib]
528 results[lib] = rev 538 results[lib] = rev
529 return 539 return
530 } else if (res > 0) { 540 } else if (res > 0) {
531 print LibDir lib rev 541 print LibDir lib rev
532 return 542 return
533 } 543 }
534 } 544 }
535} 545}
536 546
537/^lib.*\.so\.[0-9]+\.[0-9]+(\.[0-9]+)?(\.debug)?$/ { 547/^lib.*\.so\.[0-9]+\.[0-9]+(\.[0-9]+)?(\.debug)?$/ {
538 if (AllLibs) 548 if (AllLibs)
539 checklib(minor, $0, "^lib.*\\.so\\.") 549 checklib(minor, $0, "^lib.*\\.so\\.")
540 else 550 else
541 checklib(found, $0, "^lib.*\\.so\\.[0-9]+\\.") 551 checklib(found, $0, "^lib.*\\.so\\.[0-9]+\\.")
542} 552}
543 553
544/^lib.*\.so\.[0-9]+$/ { 554/^lib.*\.so\.[0-9]+$/ {
545 if (AllLibs) 555 if (AllLibs)
546 checklib(major, $0, "^lib.*\\.so\\.") 556 checklib(major, $0, "^lib.*\\.so\\.")
547} 557}
548 558
549#}' 559#}'
550  560
551 ) 561 )
552} 562}
553 563
554# modify_file op srcfile scratchfile awkprog 564# modify_file op srcfile scratchfile awkprog
555# Apply awkprog to srcfile sending output to scratchfile, and 565# Apply awkprog to srcfile sending output to scratchfile, and
556# if appropriate replace srcfile with scratchfile. 566# if appropriate replace srcfile with scratchfile.
557# 567#
558modify_file() 568modify_file()
559{ 569{
560 [ $# -eq 4 ] || err 3 "USAGE: modify_file op file scratch awkprog" 570 [ $# -eq 4 ] || err 3 "USAGE: modify_file op file scratch awkprog"
561 571
562 _mfop="$1" 572 _mfop="$1"
563 _mffile="$2" 573 _mffile="$2"
564 _mfscratch="$3" 574 _mfscratch="$3"
565 _mfprog="$4" 575 _mfprog="$4"
566 _mffailed=0 576 _mffailed=0
567 577
568 ${AWK} "${_mfprog}" < "${_mffile}" > "${_mfscratch}" 578 ${AWK} "${_mfprog}" < "${_mffile}" > "${_mfscratch}"
569 if ! cmp -s "${_mffile}" "${_mfscratch}"; then 579 if ! cmp -s "${_mffile}" "${_mfscratch}"; then
570 diff "${_mffile}" "${_mfscratch}" > "${_mfscratch}.diffs" 580 diff "${_mffile}" "${_mfscratch}" > "${_mfscratch}.diffs"
571 if [ "${_mfop}" = "check" ]; then 581 if [ "${_mfop}" = "check" ]; then
572 msg "${_mffile} needs the following changes:" 582 msg "${_mffile} needs the following changes:"
573 _mffailed=1 583 _mffailed=1
574 elif ! rm -f "${_mffile}" || 584 elif ! rm -f "${_mffile}" ||
575 ! cp -f "${_mfscratch}" "${_mffile}"; then 585 ! cp -f "${_mfscratch}" "${_mffile}"; then
576 msg "${_mffile} changes not applied:" 586 msg "${_mffile} changes not applied:"
577 _mffailed=1 587 _mffailed=1
578 else 588 else
579 msg "${_mffile} changes applied:" 589 msg "${_mffile} changes applied:"
580 fi 590 fi
581 while read _line; do 591 while read _line; do
582 msg " ${_line}" 592 msg " ${_line}"
583 done < "${_mfscratch}.diffs" 593 done < "${_mfscratch}.diffs"
584 fi 594 fi
585 return ${_mffailed} 595 return ${_mffailed}
586} 596}
587 597
588 598
589# contents_owner op directory user group 599# contents_owner op directory user group
590# Make sure directory and contents are owned (and group-owned) 600# Make sure directory and contents are owned (and group-owned)
591# as specified. 601# as specified.
592# 602#
593contents_owner() 603contents_owner()
594{ 604{
595 [ $# -eq 4 ] || err 3 "USAGE: contents_owner op dir user group" 605 [ $# -eq 4 ] || err 3 "USAGE: contents_owner op dir user group"
596 606
597 _op="$1" 607 _op="$1"
598 _dir="$2" 608 _dir="$2"
599 _user="$3" 609 _user="$3"
600 _grp="$4" 610 _grp="$4"
601 611
602 if [ "${_op}" = "check" ]; then 612 if [ "${_op}" = "check" ]; then
603 if [ ! -z "`find "${_dir}" \( ! -user "${_user}" \) -o \ 613 if [ ! -z "`find "${_dir}" \( ! -user "${_user}" \) -o \
604 \( ! -group "${_grp}" \)`" ]; then 614 \( ! -group "${_grp}" \)`" ]; then
605 msg \ 615 msg \
606 "${_dir} and contents not all owned by ${_user}:${_grp}" 616 "${_dir} and contents not all owned by ${_user}:${_grp}"
607 return 1 617 return 1
608 else 618 else
609 return 0 619 return 0
610 fi 620 fi
611 elif [ "${_op}" = "fix" ]; then 621 elif [ "${_op}" = "fix" ]; then
612 find "${_dir}" \( \( ! -user "${_user}" \) -o \ 622 find "${_dir}" \( \( ! -user "${_user}" \) -o \
613 \( ! -group "${_grp}" \) \) -a -print0 \ 623 \( ! -group "${_grp}" \) \) -a -print0 \
614 | xargs -0 chown "${_user}:${_grp}" 624 | xargs -0 chown "${_user}:${_grp}"
615 fi  625 fi
616} 626}
617 627
618# get_makevar var [var ...] 628# get_makevar var [var ...]
619# Retrieve the value of a user-settable system make variable 629# Retrieve the value of a user-settable system make variable
620get_makevar() 630get_makevar()
621{ 631{
622 $SOURCEMODE || err 3 "get_makevar must be used in source mode" 632 $SOURCEMODE || err 3 "get_makevar must be used in source mode"
623 [ $# -eq 0 ] && err 3 "USAGE: get_makevar var [var ...]" 633 [ $# -eq 0 ] && err 3 "USAGE: get_makevar var [var ...]"
624 634
625 for _var in "$@"; do 635 for _var in "$@"; do
626 _value="$(echo '.include <bsd.own.mk>' | \ 636 _value="$(echo '.include <bsd.own.mk>' | \
627 ${MAKE} -f - -V "${_var}")" 637 ${MAKE} -f - -V "${_var}")"
628 638
629 eval ${_var}=\"${_value}\" 639 eval ${_var}=\"${_value}\"
630 done 640 done
631} 641}
632 642
633# detect_x11 643# detect_x11
634# Detect if X11 components should be analysed and set values of 644# Detect if X11 components should be analysed and set values of
635# relevant variables. 645# relevant variables.
636detect_x11() 646detect_x11()
637{ 647{
638 if $SOURCEMODE; then 648 if $SOURCEMODE; then
639 get_makevar MKX11 X11ROOTDIR X11SRCDIR 649 get_makevar MKX11 X11ROOTDIR X11SRCDIR
640 else 650 else
641 if [ -f "${SRC_DIR}/etc/mtree/set.xetc" ]; then 651 if [ -f "${SRC_DIR}/etc/mtree/set.xetc" ]; then
642 MKX11=yes 652 MKX11=yes
643 X11ROOTDIR=/this/value/isnt/used/yet 653 X11ROOTDIR=/this/value/isnt/used/yet
644 else 654 else
645 MKX11=no 655 MKX11=no
646 X11ROOTDIR= 656 X11ROOTDIR=
647 fi 657 fi
648 X11SRCDIR=/nonexistent/xsrc 658 X11SRCDIR=/nonexistent/xsrc
649 fi 659 fi
650} 660}
651 661
652# 662#
653# items 663# items
654# ----- 664# -----
655# 665#
656 666
657# 667#
658# Bluetooth 668# Bluetooth
659# 669#
660 670
661additem bluetooth "Bluetooth configuration is up to date" 671additem bluetooth "Bluetooth configuration is up to date"
662do_bluetooth() 672do_bluetooth()
663{ 673{
664 [ -n "$1" ] || err 3 "USAGE: do_bluetooth fix|check" 674 [ -n "$1" ] || err 3 "USAGE: do_bluetooth fix|check"
665 op="$1" 675 op="$1"
666 failed=0 676 failed=0
667 677
668 populate_dir "${op}" true \ 678 populate_dir "${op}" true \
669 "${SRC_DIR}/etc/bluetooth" "${DEST_DIR}/etc/bluetooth" 644 \ 679 "${SRC_DIR}/etc/bluetooth" "${DEST_DIR}/etc/bluetooth" 644 \
670 hosts protocols btattach.conf btdevctl.conf 680 hosts protocols btattach.conf btdevctl.conf
671 failed=$(( ${failed} + $? )) 681 failed=$(( ${failed} + $? ))
672 682
673 move_file "${op}" "${DEST_DIR}/var/db/btdev.xml" \ 683 move_file "${op}" "${DEST_DIR}/var/db/btdev.xml" \
674 "${DEST_DIR}/var/db/btdevctl.plist" 684 "${DEST_DIR}/var/db/btdevctl.plist"
675 failed=$(( ${failed} + $? )) 685 failed=$(( ${failed} + $? ))
676 686
677 notfixed="" 687 notfixed=""
678 if [ "${op}" = "fix" ]; then 688 if [ "${op}" = "fix" ]; then
679 notfixed="${NOT_FIXED}" 689 notfixed="${NOT_FIXED}"
680 fi 690 fi
681 for _v in btattach btconfig btdevctl; do 691 for _v in btattach btconfig btdevctl; do
682 if rcvar_is_enabled "${_v}"; then 692 if rcvar_is_enabled "${_v}"; then
683 msg \ 693 msg \
684 "${_v} is obsolete in rc.conf(5)${notfixed}: use bluetooth=YES" 694 "${_v} is obsolete in rc.conf(5)${notfixed}: use bluetooth=YES"
685 failed=$(( ${failed} + 1 )) 695 failed=$(( ${failed} + 1 ))
686 fi 696 fi
687 done 697 done
688 698
689 return ${failed} 699 return ${failed}
690} 700}
691 701
692# 702#
693# ddbonpanic 703# ddbonpanic
694# 704#
695additem ddbonpanic "verify ddb.onpanic is configured in sysctl.conf" 705additem ddbonpanic "verify ddb.onpanic is configured in sysctl.conf"
696do_ddbonpanic() 706do_ddbonpanic()
697{ 707{
698 [ -n "$1" ] || err 3 "USAGE: do_ddbonpanic fix|check" 708 [ -n "$1" ] || err 3 "USAGE: do_ddbonpanic fix|check"
699 709
700 if ${GREP} -E '^#*[[:space:]]*ddb\.onpanic[[:space:]]*\??=[[:space:]]*[[:digit:]]+' \ 710 if ${GREP} -E '^#*[[:space:]]*ddb\.onpanic[[:space:]]*\??=[[:space:]]*[[:digit:]]+' \
701 "${DEST_DIR}/etc/sysctl.conf" >/dev/null 2>&1 711 "${DEST_DIR}/etc/sysctl.conf" >/dev/null 2>&1
702 then 712 then
703 result=0 713 result=0
704 else 714 else
705 if [ "$1" = check ]; then 715 if [ "$1" = check ]; then
706 msg \ 716 msg \
707 "The ddb.onpanic behaviour is not explicitly specified in /etc/sysctl.conf" 717 "The ddb.onpanic behaviour is not explicitly specified in /etc/sysctl.conf"
708 result=1 718 result=1
709 else 719 else
710 echo >> "${DEST_DIR}/etc/sysctl.conf" 720 echo >> "${DEST_DIR}/etc/sysctl.conf"
711 sed < "${SRC_DIR}/etc/sysctl.conf" \ 721 sed < "${SRC_DIR}/etc/sysctl.conf" \
712 -e '/^ddb\.onpanic/q' | \ 722 -e '/^ddb\.onpanic/q' | \
713 sed -e '1,/^$/d' >> \ 723 sed -e '1,/^$/d' >> \
714 "${DEST_DIR}/etc/sysctl.conf" 724 "${DEST_DIR}/etc/sysctl.conf"
715 result=$? 725 result=$?
716 fi 726 fi
717 fi 727 fi
718 return ${result} 728 return ${result}
719} 729}
720 730
721# 731#
722# defaults 732# defaults
723# 733#
724additem defaults "/etc/defaults/ being up to date" 734additem defaults "/etc/defaults/ being up to date"
725do_defaults() 735do_defaults()
726{ 736{
727 [ -n "$1" ] || err 3 "USAGE: do_defaults fix|check" 737 [ -n "$1" ] || err 3 "USAGE: do_defaults fix|check"
728 op="$1" 738 op="$1"
729 failed=0 739 failed=0
730 740
731 # Except for i386 and amd64, rc.conf(5) should be the same as the 741 # Except for i386 and amd64, rc.conf(5) should be the same as the
732 # one obtained from a source directory 742 # one obtained from a source directory
733 extra_scripts="rc.conf" 743 extra_scripts="rc.conf"
734 if [ "$MACHINE" = "i386" -o "$MACHINE" = "amd64" ]; then 744 if [ "$MACHINE" = "i386" -o "$MACHINE" = "amd64" ]; then
735 if $SOURCEMODE; then 745 if $SOURCEMODE; then
736 extra_scripts= # clear 746 extra_scripts= # clear
737 747
738 # Generate and compare the correct rc.conf(5) file 748 # Generate and compare the correct rc.conf(5) file
739 mkdir "${SCRATCHDIR}/defaults" 749 mkdir "${SCRATCHDIR}/defaults"
740 750
741 cat "${SRC_DIR}/etc/defaults/rc.conf" \ 751 cat "${SRC_DIR}/etc/defaults/rc.conf" \
742 "${SRC_DIR}/etc/etc.${MACHINE}/rc.conf.append" \ 752 "${SRC_DIR}/etc/etc.${MACHINE}/rc.conf.append" \
743 > "${SCRATCHDIR}/defaults/rc.conf" 753 > "${SCRATCHDIR}/defaults/rc.conf"
744 754
745 compare_dir "${op}" "${SCRATCHDIR}/defaults" \ 755 compare_dir "${op}" "${SCRATCHDIR}/defaults" \
746 "${DEST_DIR}/etc/defaults" \ 756 "${DEST_DIR}/etc/defaults" \
747 444 \ 757 444 \
748 "rc.conf" 758 "rc.conf"
749 failed=$(( ${failed} + $? )) 759 failed=$(( ${failed} + $? ))
750 fi 760 fi
751 fi 761 fi
752 762
753 compare_dir "$op" "${SRC_DIR}/etc/defaults" "${DEST_DIR}/etc/defaults" \ 763 compare_dir "$op" "${SRC_DIR}/etc/defaults" "${DEST_DIR}/etc/defaults" \
754 444 \ 764 444 \
755 daily.conf monthly.conf security.conf \ 765 daily.conf monthly.conf security.conf \
756 weekly.conf ${extra_scripts} 766 weekly.conf ${extra_scripts}
757 failed=$(( ${failed} + $? )) 767 failed=$(( ${failed} + $? ))
758 768
759 find_file_in_dirlist pf.boot.conf "pf.boot.conf" \ 769 find_file_in_dirlist pf.boot.conf "pf.boot.conf" \
760 "${SRC_DIR}/usr.sbin/pf/etc/defaults" "${SRC_DIR}/etc/defaults" \ 770 "${SRC_DIR}/usr.sbin/pf/etc/defaults" "${SRC_DIR}/etc/defaults" \
761 || return 1 771 || return 1
762 # ${dir} is set by find_file_in_dirlist() 772 # ${dir} is set by find_file_in_dirlist()
763 compare_dir "$op" "${dir}" "${DEST_DIR}/etc/defaults" 444 pf.boot.conf 773 compare_dir "$op" "${dir}" "${DEST_DIR}/etc/defaults" 444 pf.boot.conf
764 failed=$(( ${failed} + $? )) 774 failed=$(( ${failed} + $? ))
765 775
766 return ${failed} 776 return ${failed}
767} 777}
768 778
769# 779#
770# dhcpcd 780# dhcpcd
771# 781#
772additem dhcpcd "dhcpcd configuration is up to date" 782additem dhcpcd "dhcpcd configuration is up to date"
773do_dhcpcd() 783do_dhcpcd()
774{ 784{
775 [ -n "$1" ] || err 3 "USAGE: do_dhcpcd fix|check" 785 [ -n "$1" ] || err 3 "USAGE: do_dhcpcd fix|check"
776 op="$1" 786 op="$1"
777 failed=0 787 failed=0
778 788
779 find_file_in_dirlist dhcpcd.conf "dhcpcd.conf" \ 789 find_file_in_dirlist dhcpcd.conf "dhcpcd.conf" \
780 "${SRC_DIR}/external/bsd/dhcpcd/dist" "${SRC_DIR}/etc" || return 1 790 "${SRC_DIR}/external/bsd/dhcpcd/dist" "${SRC_DIR}/etc" || return 1
781 # ${dir} is set by find_file_in_dirlist() 791 # ${dir} is set by find_file_in_dirlist()
782 populate_dir "$op" true "${dir}" "${DEST_DIR}/etc" 644 dhcpcd.conf 792 populate_dir "$op" true "${dir}" "${DEST_DIR}/etc" 644 dhcpcd.conf
783 failed=$(( ${failed} + $? )) 793 failed=$(( ${failed} + $? ))
784 794
785 return ${failed} 795 return ${failed}
786} 796}
787 797
788# 798#
789# envsys 799# envsys
790# 800#
791additem envsys "envsys configuration is up to date" 801additem envsys "envsys configuration is up to date"
792do_envsys() 802do_envsys()
793{ 803{
794 [ -n "$1" ] || err 3 "USAGE: do_envsys fix|check" 804 [ -n "$1" ] || err 3 "USAGE: do_envsys fix|check"
795 op="$1" 805 op="$1"
796 failed=0 806 failed=0
797 807
798 populate_dir "$op" true "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \ 808 populate_dir "$op" true "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
799 envsys.conf 809 envsys.conf
800 failed=$(( ${failed} + $? )) 810 failed=$(( ${failed} + $? ))
801 811
802 populate_dir "$op" true "${SRC_DIR}/etc/powerd/scripts" \ 812 populate_dir "$op" true "${SRC_DIR}/etc/powerd/scripts" \
803 "${DEST_DIR}/etc/powerd/scripts" 555 sensor_battery \ 813 "${DEST_DIR}/etc/powerd/scripts" 555 sensor_battery \
804 sensor_drive sensor_fan sensor_indicator sensor_power \ 814 sensor_drive sensor_fan sensor_indicator sensor_power \
805 sensor_resistance sensor_temperature sensor_voltage 815 sensor_resistance sensor_temperature sensor_voltage
806 failed=$(( ${failed} + $? )) 816 failed=$(( ${failed} + $? ))
807 817
808 return ${failed} 818 return ${failed}
809} 819}
810 820
811# 821#
812# X11 fontconfig 822# X11 fontconfig
813# 823#
814additem fontconfig "X11 font configuration is up to date" 824additem fontconfig "X11 font configuration is up to date"
815do_fontconfig() 825do_fontconfig()
816{ 826{
817 [ -n "$1" ] || err 3 "USAGE: do_fontconfig fix|check" 827 [ -n "$1" ] || err 3 "USAGE: do_fontconfig fix|check"
818 op="$1" 828 op="$1"
819 failed=0 829 failed=0
820 830
821 # First, check for updates we can handle. 831 # First, check for updates we can handle.
822 if ! $SOURCEMODE; then 832 if ! $SOURCEMODE; then
823 FONTCONFIG_DIR="${SRC_DIR}/etc/fonts/conf.avail"  833 FONTCONFIG_DIR="${SRC_DIR}/etc/fonts/conf.avail"
824 else 834 else
825 FONTCONFIG_DIR="${XSRC_DIR}/external/mit/fontconfig/dist/conf.d" 835 FONTCONFIG_DIR="${XSRC_DIR}/external/mit/fontconfig/dist/conf.d"
826 fi 836 fi
827 837
828 populate_dir "$op" false "${FONTCONFIG_DIR}" "${DEST_DIR}/etc/fonts/conf.avail" 444 \ 838 populate_dir "$op" false "${FONTCONFIG_DIR}" "${DEST_DIR}/etc/fonts/conf.avail" 444 \
829 10-autohint.conf \ 839 10-autohint.conf \
830 10-no-sub-pixel.conf \ 840 10-no-sub-pixel.conf \
831 10-scale-bitmap-fonts.conf \ 841 10-scale-bitmap-fonts.conf \
832 10-sub-pixel-bgr.conf \ 842 10-sub-pixel-bgr.conf \
833 10-sub-pixel-rgb.conf \ 843 10-sub-pixel-rgb.conf \
834 10-sub-pixel-vbgr.conf \ 844 10-sub-pixel-vbgr.conf \
835 10-sub-pixel-vrgb.conf \ 845 10-sub-pixel-vrgb.conf \
836 10-unhinted.conf \ 846 10-unhinted.conf \
837 11-lcdfilter-default.conf \ 847 11-lcdfilter-default.conf \
838 11-lcdfilter-legacy.conf \ 848 11-lcdfilter-legacy.conf \
839 11-lcdfilter-light.conf \ 849 11-lcdfilter-light.conf \
840 20-unhint-small-vera.conf \ 850 20-unhint-small-vera.conf \
841 25-unhint-nonlatin.conf \ 851 25-unhint-nonlatin.conf \
842 30-metric-aliases.conf \ 852 30-metric-aliases.conf \
843 30-urw-aliases.conf \ 853 30-urw-aliases.conf \
844 40-nonlatin.conf \ 854 40-nonlatin.conf \
845 45-latin.conf \ 855 45-latin.conf \
846 49-sansserif.conf \ 856 49-sansserif.conf \
847 50-user.conf \ 857 50-user.conf \
848 51-local.conf \ 858 51-local.conf \
849 60-latin.conf \ 859 60-latin.conf \
850 65-fonts-persian.conf \ 860 65-fonts-persian.conf \
851 65-khmer.conf \ 861 65-khmer.conf \
852 65-nonlatin.conf \ 862 65-nonlatin.conf \
853 69-unifont.conf \ 863 69-unifont.conf \
854 70-no-bitmaps.conf \ 864 70-no-bitmaps.conf \
855 70-yes-bitmaps.conf \ 865 70-yes-bitmaps.conf \
856 80-delicious.conf \ 866 80-delicious.conf \
857 90-synthetic.conf 867 90-synthetic.conf
858 failed=$(( ${failed} + $? )) 868 failed=$(( ${failed} + $? ))
859  869
860 # We can't modify conf.d easily; someone might have removed a file. 870 # We can't modify conf.d easily; someone might have removed a file.
861 871
862 conf_d_failed=0 872 conf_d_failed=0
863 # Look for old files that need to be deleted. 873 # Look for old files that need to be deleted.
864 if [ -f "${DEST_DIR}/etc/fonts/conf.d/10-unhinted.conf" -a \ 874 if [ -f "${DEST_DIR}/etc/fonts/conf.d/10-unhinted.conf" -a \
865 -f "${DEST_DIR}/etc/fonts/conf.d/10-autohint.conf" ]; then 875 -f "${DEST_DIR}/etc/fonts/conf.d/10-autohint.conf" ]; then
866 conf_d_failed=1 876 conf_d_failed=1
867 failed=$(( ${failed} + 1 )) 877 failed=$(( ${failed} + 1 ))
868 fi 878 fi
869 879
870 if [ "$conf_d_failed" = 1 ]; then 880 if [ "$conf_d_failed" = 1 ]; then
871 msg \ 881 msg \
872 "Broken fontconfig configuration found; please delete these files" 882 "Broken fontconfig configuration found; please delete these files"
873 msg \ 883 msg \
874 "in the ${DESTDIR}/etc/fonts/conf.d/ subdirectory:" 884 "in the ${DESTDIR}/etc/fonts/conf.d/ subdirectory:"
875 msg \ 885 msg \
876 " 10-autohint.conf 10-no-sub-pixel.conf 10-sub-pixel-bgr.conf" 886 " 10-autohint.conf 10-no-sub-pixel.conf 10-sub-pixel-bgr.conf"
877 msg \ 887 msg \
878 " 10-sub-pixel-rgb.conf 10-sub-pixel-vbgr.conf" 888 " 10-sub-pixel-rgb.conf 10-sub-pixel-vbgr.conf"
879 msg \ 889 msg \
880 " 10-sub-pixel-vrgb.conf 10-unhinted.conf 25-unhint-nonlatin.conf" 890 " 10-sub-pixel-vrgb.conf 10-unhinted.conf 25-unhint-nonlatin.conf"
881 msg \ 891 msg \
882 " 65-khmer.conf 70-no-bitmaps.conf 70-yes-bitmaps.conf" 892 " 65-khmer.conf 70-no-bitmaps.conf 70-yes-bitmaps.conf"
883 msg \ 893 msg \
884 "(This warning only appears if both the 10-unhinted.conf and" 894 "(This warning only appears if both the 10-unhinted.conf and"
885 msg \ 895 msg \
886 "10-autohint.conf files are present." 896 "10-autohint.conf files are present."
887 fi 897 fi
888 898
889 return ${failed} 899 return ${failed}
890} 900}
891 901
892# 902#
893# gid 903# gid
894# 904#
895additem gid "required groups in /etc/group" 905additem gid "required groups in /etc/group"
896do_gid() 906do_gid()
897{ 907{
898 [ -n "$1" ] || err 3 "USAGE: do_gid fix|check" 908 [ -n "$1" ] || err 3 "USAGE: do_gid fix|check"
899 909
900 check_ids "$1" groups "${DEST_DIR}/etc/group" \ 910 check_ids "$1" groups "${DEST_DIR}/etc/group" 14 \
901 named ntpd sshd authpf _pflogd _rwhod _proxy _timedc \ 911 named ntpd sshd _pflogd _rwhod staff _proxy _timedc \
902 _sdpd _httpd _mdnsd _tests _tcpdump _tss _gpio 912 _sdpd _httpd _mdnsd _tests _tcpdump _tss _gpio
903} 913}
904 914
905# 915#
906# gpio 916# gpio
907# 917#
908additem gpio "gpio configuration is up to date" 918additem gpio "gpio configuration is up to date"
909do_gpio() 919do_gpio()
910{ 920{
911 [ -n "$1" ] || err 3 "USAGE: do_gpio fix|check" 921 [ -n "$1" ] || err 3 "USAGE: do_gpio fix|check"
912 op="$1" 922 op="$1"
913 failed=0 923 failed=0
914 924
915 populate_dir "$op" true "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \ 925 populate_dir "$op" true "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
916 gpio.conf 926 gpio.conf
917 failed=$(( ${failed} + $? )) 927 failed=$(( ${failed} + $? ))
918 928
919 return ${failed} 929 return ${failed}
920} 930}
921 931
922# 932#
923# hosts 933# hosts
924# 934#
925additem hosts "/etc/hosts being up to date" 935additem hosts "/etc/hosts being up to date"
926do_hosts() 936do_hosts()
927{ 937{
928 [ -n "$1" ] || err 3 "USAGE: do_hosts fix|check" 938 [ -n "$1" ] || err 3 "USAGE: do_hosts fix|check"
929 939
930 modify_file "$1" "${DEST_DIR}/etc/hosts" "${SCRATCHDIR}/hosts" ' 940 modify_file "$1" "${DEST_DIR}/etc/hosts" "${SCRATCHDIR}/hosts" '
931 /^(127\.0\.0\.1|::1)[ ]+[^\.]*$/ { 941 /^(127\.0\.0\.1|::1)[ ]+[^\.]*$/ {
932 print $0, "localhost." 942 print $0, "localhost."
933 next 943 next
934 } 944 }
935 { print } 945 { print }
936 ' 946 '
937 return $? 947 return $?
938} 948}
939 949
940# 950#
941# iscsi 951# iscsi
942# 952#
943additem iscsi "/etc/iscsi is populated" 953additem iscsi "/etc/iscsi is populated"
944do_iscsi() 954do_iscsi()
945{ 955{
946 [ -n "$1" ] || err 3 "USAGE: do_iscsi fix|check" 956 [ -n "$1" ] || err 3 "USAGE: do_iscsi fix|check"
947 957
948 populate_dir "${op}" true \ 958 populate_dir "${op}" true \
949 "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 600 auths 959 "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 600 auths
950 populate_dir "${op}" true \ 960 populate_dir "${op}" true \
951 "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 644 targets 961 "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 644 targets
952 return $? 962 return $?
953} 963}
954 964
955# 965#
956# makedev 966# makedev
957# 967#
958additem makedev "/dev/MAKEDEV being up to date" 968additem makedev "/dev/MAKEDEV being up to date"
959do_makedev() 969do_makedev()
960{ 970{
961 [ -n "$1" ] || err 3 "USAGE: do_makedev fix|check" 971 [ -n "$1" ] || err 3 "USAGE: do_makedev fix|check"
962 failed=0 972 failed=0
963 973
964 if [ -f "${SRC_DIR}/etc/MAKEDEV.tmpl" ]; then 974 if [ -f "${SRC_DIR}/etc/MAKEDEV.tmpl" ]; then
965 # generate MAKEDEV from source if source is available 975 # generate MAKEDEV from source if source is available
966 env MACHINE="${MACHINE}" \ 976 env MACHINE="${MACHINE}" \
967 MACHINE_ARCH="${MACHINE_ARCH}" \ 977 MACHINE_ARCH="${MACHINE_ARCH}" \
968 NETBSDSRCDIR="${SRC_DIR}" \ 978 NETBSDSRCDIR="${SRC_DIR}" \
969 ${AWK} -f "${SRC_DIR}/etc/MAKEDEV.awk" \ 979 ${AWK} -f "${SRC_DIR}/etc/MAKEDEV.awk" \
970 "${SRC_DIR}/etc/MAKEDEV.tmpl" > "${SCRATCHDIR}/MAKEDEV" 980 "${SRC_DIR}/etc/MAKEDEV.tmpl" > "${SCRATCHDIR}/MAKEDEV"
971 fi 981 fi
972 982
973 find_file_in_dirlist MAKEDEV "MAKEDEV" \ 983 find_file_in_dirlist MAKEDEV "MAKEDEV" \
974 "${SCRATCHDIR}" "${SRC_DIR}/dev" \ 984 "${SCRATCHDIR}" "${SRC_DIR}/dev" \
975 || return 1 985 || return 1
976 # ${dir} is set by find_file_in_dirlist() 986 # ${dir} is set by find_file_in_dirlist()
977 compare_dir "$1" "${dir}" "${DEST_DIR}/dev" 555 MAKEDEV 987 compare_dir "$1" "${dir}" "${DEST_DIR}/dev" 555 MAKEDEV
978 failed=$(( ${failed} + $? )) 988 failed=$(( ${failed} + $? ))
979 989
980 find_file_in_dirlist MAKEDEV.local "MAKEDEV.local" \ 990 find_file_in_dirlist MAKEDEV.local "MAKEDEV.local" \
981 "${SRC_DIR}/etc" "${SRC_DIR}/dev" \ 991 "${SRC_DIR}/etc" "${SRC_DIR}/dev" \
982 || return 1 992 || return 1
983 # ${dir} is set by find_file_in_dirlist() 993 # ${dir} is set by find_file_in_dirlist()
984 compare_dir "$1" "${dir}" "${DEST_DIR}/dev" 555 MAKEDEV.local 994 compare_dir "$1" "${dir}" "${DEST_DIR}/dev" 555 MAKEDEV.local
985 failed=$(( ${failed} + $? )) 995 failed=$(( ${failed} + $? ))
986 996
987 return ${failed} 997 return ${failed}
988} 998}
989 999
990# 1000#
991# motd 1001# motd
992# 1002#
993additem motd "contents of motd" 1003additem motd "contents of motd"
994do_motd() 1004do_motd()
995{ 1005{
996 [ -n "$1" ] || err 3 "USAGE: do_motd fix|check" 1006 [ -n "$1" ] || err 3 "USAGE: do_motd fix|check"
997 1007
998 if ${GREP} -i 'http://www.NetBSD.org/Misc/send-pr.html' \ 1008 if ${GREP} -i 'http://www.NetBSD.org/Misc/send-pr.html' \
999 "${DEST_DIR}/etc/motd" >/dev/null 2>&1 \ 1009 "${DEST_DIR}/etc/motd" >/dev/null 2>&1 \
1000 || ${GREP} -i 'http://www.NetBSD.org/support/send-pr.html' \ 1010 || ${GREP} -i 'http://www.NetBSD.org/support/send-pr.html' \
1001 "${DEST_DIR}/etc/motd" >/dev/null 2>&1 1011 "${DEST_DIR}/etc/motd" >/dev/null 2>&1
1002 then 1012 then
1003 tmp1="$(mktemp /tmp/postinstall.motd.XXXXXXXX)" 1013 tmp1="$(mktemp /tmp/postinstall.motd.XXXXXXXX)"
1004 tmp2="$(mktemp /tmp/postinstall.motd.XXXXXXXX)" 1014 tmp2="$(mktemp /tmp/postinstall.motd.XXXXXXXX)"
1005 sed '1,2d' <"${SRC_DIR}/etc/motd" >"${tmp1}" 1015 sed '1,2d' <"${SRC_DIR}/etc/motd" >"${tmp1}"
1006 sed '1,2d' <"${DEST_DIR}/etc/motd" >"${tmp2}" 1016 sed '1,2d' <"${DEST_DIR}/etc/motd" >"${tmp2}"
1007 1017
1008 if [ "$1" = check ]; then 1018 if [ "$1" = check ]; then
1009 cmp -s "${tmp1}" "${tmp2}" 1019 cmp -s "${tmp1}" "${tmp2}"
1010 result=$? 1020 result=$?
1011 if [ "${result}" -ne 0 ]; then 1021 if [ "${result}" -ne 0 ]; then
1012 msg \ 1022 msg \
1013 "Bug reporting messages do not seem to match the installed release" 1023 "Bug reporting messages do not seem to match the installed release"
1014 fi 1024 fi
1015 else 1025 else
1016 head -n 2 "${DEST_DIR}/etc/motd" >"${tmp1}" 1026 head -n 2 "${DEST_DIR}/etc/motd" >"${tmp1}"
1017 sed '1,2d' <"${SRC_DIR}/etc/motd" >>"${tmp1}" 1027 sed '1,2d' <"${SRC_DIR}/etc/motd" >>"${tmp1}"
1018 cp "${tmp1}" "${DEST_DIR}/etc/motd" 1028 cp "${tmp1}" "${DEST_DIR}/etc/motd"
1019 result=0 1029 result=0
1020 fi 1030 fi
1021 1031
1022 rm -f "${tmp1}" "${tmp2}" 1032 rm -f "${tmp1}" "${tmp2}"
1023 else 1033 else
1024 result=0 1034 result=0
1025 fi 1035 fi
1026 1036
1027 return ${result} 1037 return ${result}
1028} 1038}
1029 1039
1030# 1040#
1031# mtree 1041# mtree
1032# 1042#
1033additem mtree "/etc/mtree/ being up to date" 1043additem mtree "/etc/mtree/ being up to date"
1034do_mtree() 1044do_mtree()
1035{ 1045{
1036 [ -n "$1" ] || err 3 "USAGE: do_mtree fix|check" 1046 [ -n "$1" ] || err 3 "USAGE: do_mtree fix|check"
1037 failed=0 1047 failed=0
1038 1048
1039 compare_dir "$1" "${SRC_DIR}/etc/mtree" "${DEST_DIR}/etc/mtree" 444 special 1049 compare_dir "$1" "${SRC_DIR}/etc/mtree" "${DEST_DIR}/etc/mtree" 444 special
1040 failed=$(( ${failed} + $? )) 1050 failed=$(( ${failed} + $? ))
1041 1051
1042 if ! $SOURCEMODE; then 1052 if ! $SOURCEMODE; then
1043 MTREE_DIR="${SRC_DIR}/etc/mtree" 1053 MTREE_DIR="${SRC_DIR}/etc/mtree"
1044 else 1054 else
1045 ${MAKE} -C "${SRC_DIR}/etc/mtree" emit_dist_file > \ 1055 ${MAKE} -C "${SRC_DIR}/etc/mtree" emit_dist_file > \
1046 "${SCRATCHDIR}/NetBSD.dist" 1056 "${SCRATCHDIR}/NetBSD.dist"
1047 MTREE_DIR="${SCRATCHDIR}" 1057 MTREE_DIR="${SCRATCHDIR}"
1048 fi 1058 fi
1049 compare_dir "$1" "${MTREE_DIR}" "${DEST_DIR}/etc/mtree" 444 NetBSD.dist 1059 compare_dir "$1" "${MTREE_DIR}" "${DEST_DIR}/etc/mtree" 444 NetBSD.dist
1050 failed=$(( ${failed} + $? )) 1060 failed=$(( ${failed} + $? ))
1051 1061
1052 return ${failed} 1062 return ${failed}
1053} 1063}
1054 1064
1055# 1065#
1056# named 1066# named
1057# 1067#
1058additem named "named configuration update" 1068additem named "named configuration update"
1059do_named() 1069do_named()
1060{ 1070{
1061 [ -n "$1" ] || err 3 "USAGE: do_named fix|check" 1071 [ -n "$1" ] || err 3 "USAGE: do_named fix|check"
1062 op="$1" 1072 op="$1"
1063 1073
1064 move_file "${op}" \ 1074 move_file "${op}" \
1065 "${DEST_DIR}/etc/namedb/named.conf" \ 1075 "${DEST_DIR}/etc/namedb/named.conf" \
1066 "${DEST_DIR}/etc/named.conf" 1076 "${DEST_DIR}/etc/named.conf"
1067 1077
1068 compare_dir "${op}" "${SRC_DIR}/etc/namedb" "${DEST_DIR}/etc/namedb" \ 1078 compare_dir "${op}" "${SRC_DIR}/etc/namedb" "${DEST_DIR}/etc/namedb" \
1069 644 \ 1079 644 \
1070 root.cache 1080 root.cache
1071} 1081}
1072 1082
1073# 1083#
1074# pam 1084# pam
1075# 1085#
1076additem pam "/etc/pam.d is populated" 1086additem pam "/etc/pam.d is populated"
1077do_pam() 1087do_pam()
1078{ 1088{
1079 [ -n "$1" ] || err 3 "USAGE: do_pam fix|check" 1089 [ -n "$1" ] || err 3 "USAGE: do_pam fix|check"
1080 op="$1" 1090 op="$1"
1081 failed=0 1091 failed=0
1082 1092
1083 populate_dir "${op}" true "${SRC_DIR}/etc/pam.d" \ 1093 populate_dir "${op}" true "${SRC_DIR}/etc/pam.d" \
1084 "${DEST_DIR}/etc/pam.d" 644 \ 1094 "${DEST_DIR}/etc/pam.d" 644 \
1085 README display_manager ftpd gdm imap kde login other passwd \ 1095 README display_manager ftpd gdm imap kde login other passwd \
1086 pop3 ppp rexecd rsh sshd su system telnetd xdm xserver 1096 pop3 ppp rexecd rsh sshd su system telnetd xdm xserver
1087 1097
1088 failed=$(( ${failed} + $? )) 1098 failed=$(( ${failed} + $? ))
1089 1099
1090 return ${failed} 1100 return ${failed}
1091} 1101}
1092 1102
1093# 1103#
1094# periodic 1104# periodic
1095# 1105#
1096additem periodic "/etc/{daily,weekly,monthly,security} being up to date" 1106additem periodic "/etc/{daily,weekly,monthly,security} being up to date"
1097do_periodic() 1107do_periodic()
1098{ 1108{
1099 [ -n "$1" ] || err 3 "USAGE: do_periodic fix|check" 1109 [ -n "$1" ] || err 3 "USAGE: do_periodic fix|check"
1100 1110
1101 compare_dir "$1" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \ 1111 compare_dir "$1" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
1102 daily weekly monthly security 1112 daily weekly monthly security
1103} 1113}
1104 1114
1105# 1115#
1106# pf 1116# pf
1107# 1117#
1108additem pf "pf configuration being up to date" 1118additem pf "pf configuration being up to date"
1109do_pf() 1119do_pf()
1110{ 1120{
1111 [ -n "$1" ] || err 3 "USAGE: do_pf fix|check" 1121 [ -n "$1" ] || err 3 "USAGE: do_pf fix|check"
1112 op="$1" 1122 op="$1"
1113 failed=0 1123 failed=0
1114 1124
1115 find_file_in_dirlist pf.os "pf.os" \ 1125 find_file_in_dirlist pf.os "pf.os" \
1116 "${SRC_DIR}/dist/pf/etc" "${SRC_DIR}/etc" \ 1126 "${SRC_DIR}/dist/pf/etc" "${SRC_DIR}/etc" \
1117 || return 1 1127 || return 1
1118 # ${dir} is set by find_file_in_dirlist() 1128 # ${dir} is set by find_file_in_dirlist()
1119 populate_dir "${op}" true \ 1129 populate_dir "${op}" true \
1120 "${dir}" "${DEST_DIR}/etc" 644 \ 1130 "${dir}" "${DEST_DIR}/etc" 644 \
1121 pf.conf 1131 pf.conf
1122 failed=$(( ${failed} + $? )) 1132 failed=$(( ${failed} + $? ))
1123 1133
1124 compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 pf.os 1134 compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 pf.os
1125 failed=$(( ${failed} + $? )) 1135 failed=$(( ${failed} + $? ))
1126 1136
1127 return ${failed} 1137 return ${failed}
1128} 1138}
1129 1139
1130# 1140#
1131# pwd_mkdb 1141# pwd_mkdb
1132# 1142#
1133additem pwd_mkdb "passwd database version" 1143additem pwd_mkdb "passwd database version"
1134do_pwd_mkdb() 1144do_pwd_mkdb()
1135{ 1145{
1136 [ -n "$1" ] || err 3 "USAGE: do_pwd_mkdb fix|check" 1146 [ -n "$1" ] || err 3 "USAGE: do_pwd_mkdb fix|check"
1137 op="$1" 1147 op="$1"
1138 failed=0 1148 failed=0
1139 1149
1140 # XXX Ideally, we should figure out the endianness of the 1150 # XXX Ideally, we should figure out the endianness of the
1141 # target machine, and add "-E B"/"-E L" to the db(1) flags, 1151 # target machine, and add "-E B"/"-E L" to the db(1) flags,
1142 # and "-B"/"-L" to the pwd_mkdb(8) flags if the target is not 1152 # and "-B"/"-L" to the pwd_mkdb(8) flags if the target is not
1143 # the same as the host machine. It probably doesn't matter, 1153 # the same as the host machine. It probably doesn't matter,
1144 # because we don't expect "postinstall fix pwd_mkdb" to be 1154 # because we don't expect "postinstall fix pwd_mkdb" to be
1145 # invoked during a cross build. 1155 # invoked during a cross build.
1146 1156
1147 set -- $(${DB} -q -Sb -Ub -To -N hash "${DEST_DIR}/etc/pwd.db" \ 1157 set -- $(${DB} -q -Sb -Ub -To -N hash "${DEST_DIR}/etc/pwd.db" \
1148 'VERSION\0') 1158 'VERSION\0')
1149 case "$2" in 1159 case "$2" in
1150 '\001\000\000\000') return 0 ;; # version 1, little-endian 1160 '\001\000\000\000') return 0 ;; # version 1, little-endian
1151 '\000\000\000\001') return 0 ;; # version 1, big-endian 1161 '\000\000\000\001') return 0 ;; # version 1, big-endian
1152 esac 1162 esac
1153 1163
1154 if [ "${op}" = "check" ]; then 1164 if [ "${op}" = "check" ]; then
1155 msg "Update format of passwd database" 1165 msg "Update format of passwd database"
1156 failed=1 1166 failed=1
1157 elif ! ${PWD_MKDB} -V 1 -d "${DEST_DIR:-/}" \ 1167 elif ! ${PWD_MKDB} -V 1 -d "${DEST_DIR:-/}" \
1158 "${DEST_DIR}/etc/master.passwd"; 1168 "${DEST_DIR}/etc/master.passwd";
1159 then 1169 then
1160 msg "Can't update format of passwd database" 1170 msg "Can't update format of passwd database"
1161 failed=1 1171 failed=1
1162 else 1172 else
1163 msg "Updated format of passwd database" 1173 msg "Updated format of passwd database"
1164 fi 1174 fi
1165 1175
1166 return ${failed} 1176 return ${failed}
1167} 1177}
1168 1178
1169# 1179#
1170# rc 1180# rc
1171# 1181#
1172additem rc "/etc/rc* and /etc/rc.d/ being up to date" 1182additem rc "/etc/rc* and /etc/rc.d/ being up to date"
1173do_rc() 1183do_rc()
1174{ 1184{
1175 [ -n "$1" ] || err 3 "USAGE: do_rc fix|check" 1185 [ -n "$1" ] || err 3 "USAGE: do_rc fix|check"
1176 op="$1" 1186 op="$1"
1177 failed=0 1187 failed=0
1178 generated_scripts="" 1188 generated_scripts=""
1179 if [ "${MKX11}" != "no" ]; then 1189 if [ "${MKX11}" != "no" ]; then
1180 generated_scripts="${generated_scripts} xdm xfs" 1190 generated_scripts="${generated_scripts} xdm xfs"
1181 fi 1191 fi
1182 1192
1183 compare_dir "${op}" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \ 1193 compare_dir "${op}" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
1184 rc rc.subr rc.shutdown 1194 rc rc.subr rc.shutdown
1185 failed=$(( ${failed} + $? )) 1195 failed=$(( ${failed} + $? ))
1186 1196
1187 if ! $SOURCEMODE; then 1197 if ! $SOURCEMODE; then
1188 extra_scripts="${generated_scripts}" 1198 extra_scripts="${generated_scripts}"
1189 else 1199 else
1190 extra_scripts="" 1200 extra_scripts=""
1191 fi 1201 fi
1192 1202
1193 compare_dir "${op}" "${SRC_DIR}/etc/rc.d" "${DEST_DIR}/etc/rc.d" 555 \ 1203 compare_dir "${op}" "${SRC_DIR}/etc/rc.d" "${DEST_DIR}/etc/rc.d" 555 \
1194 DAEMON DISKS LOGIN NETWORKING SERVERS \ 1204 DAEMON DISKS LOGIN NETWORKING SERVERS \
1195 accounting altqd amd apmd \ 1205 accounting altqd amd apmd \
1196 bluetooth bootconf.sh bootparams \ 1206 bluetooth bootconf.sh bootparams \
1197 ccd cgd cleartmp cron devpubd \ 1207 ccd cgd cleartmp cron devpubd \
1198 dhclient dhcpcd dhcpd dhcrelay dmesg downinterfaces envsys \ 1208 dhclient dhcpcd dhcpd dhcrelay dmesg downinterfaces envsys \
1199 fsck fsck_root ftp_proxy ftpd \ 1209 fsck fsck_root ftp_proxy ftpd \
1200 gpio \ 1210 gpio \
1201 hostapd httpd \ 1211 hostapd httpd \
1202 identd ifwatchd inetd ipfilter ipfs ipmon ipnat ipsec \ 1212 identd ifwatchd inetd ipfilter ipfs ipmon ipnat ipsec \
1203 irdaattach iscsi_target isdnd isibootd \ 1213 irdaattach iscsi_target isdnd isibootd \
1204 kdc \ 1214 kdc \
1205 ldconfig ldpd local lpd lvm \ 1215 ldconfig ldpd local lpd lvm \
1206 makemandb mdnsd mixerctl mopd motd mountall mountcritlocal \ 1216 makemandb mdnsd mixerctl mopd motd mountall mountcritlocal \
1207 mountcritremote mountd moused mrouted \ 1217 mountcritremote mountd moused mrouted \
1208 named ndbootd network newsyslog nfsd nfslocking npf ntpd \ 1218 named ndbootd network newsyslog nfsd nfslocking npf ntpd \
1209 ntpdate \ 1219 ntpdate \
1210 perusertmp pf pf_boot pflogd postfix powerd ppp pwcheck \ 1220 perusertmp pf pf_boot pflogd postfix powerd ppp pwcheck \
1211 quota \ 1221 quota \
1212 racoon rpcbind raidframe raidframeparity random_seed rarpd \ 1222 racoon rpcbind raidframe raidframeparity random_seed rarpd \
1213 rbootd rndctl root route6d routed rtadvd rtclocaltime \ 1223 rbootd rndctl root route6d routed rtadvd rtclocaltime \
1214 rtsold rwho \ 1224 rtsold rwho \
1215 savecore screenblank securelevel sshd \ 1225 savecore screenblank securelevel sshd \
1216 staticroute swap1 swap2 sysctl sysdb syslogd \ 1226 staticroute swap1 swap2 sysctl sysdb syslogd \
1217 timed tpctl ttys \ 1227 timed tpctl ttys \
1218 veriexec virecover wdogctl wpa_supplicant wscons wsmoused \ 1228 veriexec virecover wdogctl wpa_supplicant wscons wsmoused \
1219 ypbind yppasswdd ypserv \ 1229 ypbind yppasswdd ypserv \
1220 ${extra_scripts} 1230 ${extra_scripts}
1221 failed=$(( ${failed} + $? )) 1231 failed=$(( ${failed} + $? ))
1222 1232
1223 if $SOURCEMODE && [ -n "${generated_scripts}" ]; then 1233 if $SOURCEMODE && [ -n "${generated_scripts}" ]; then
1224 # generate scripts 1234 # generate scripts
1225 mkdir "${SCRATCHDIR}/rc" 1235 mkdir "${SCRATCHDIR}/rc"
1226 for f in ${generated_scripts}; do 1236 for f in ${generated_scripts}; do
1227 sed -e "s,@X11ROOTDIR@,${X11ROOTDIR},g" \ 1237 sed -e "s,@X11ROOTDIR@,${X11ROOTDIR},g" \
1228 < "${SRC_DIR}/etc/rc.d/${f}.in" \ 1238 < "${SRC_DIR}/etc/rc.d/${f}.in" \
1229 > "${SCRATCHDIR}/rc/${f}" 1239 > "${SCRATCHDIR}/rc/${f}"
1230 done 1240 done
1231 compare_dir "${op}" "${SCRATCHDIR}/rc" \ 1241 compare_dir "${op}" "${SCRATCHDIR}/rc" \
1232 "${DEST_DIR}/etc/rc.d" 555 \ 1242 "${DEST_DIR}/etc/rc.d" 555 \
1233 ${generated_scripts} 1243 ${generated_scripts}
1234 failed=$(( ${failed} + $? )) 1244 failed=$(( ${failed} + $? ))
1235 fi 1245 fi
1236 1246
1237 # check for obsolete rc.d files 1247 # check for obsolete rc.d files
1238 for f in NETWORK btattach btconfig btcontrol btdevctl bthcid btuartd \ 1248 for f in NETWORK btattach btconfig btcontrol btdevctl bthcid btuartd \
1239 fsck.sh kerberos nfsiod sdpd servers \ 1249 fsck.sh kerberos nfsiod sdpd servers \
1240 systemfs daemon gated login poffd portmap sunndd xntpd; do 1250 systemfs daemon gated login poffd portmap sunndd xntpd; do
1241 fd="/etc/rc.d/${f}" 1251 fd="/etc/rc.d/${f}"
1242 [ -e "${DEST_DIR}${fd}" ] && echo "${fd}" 1252 [ -e "${DEST_DIR}${fd}" ] && echo "${fd}"
1243 done | obsolete_paths "${op}" 1253 done | obsolete_paths "${op}"
1244 failed=$(( ${failed} + $? )) 1254 failed=$(( ${failed} + $? ))
1245 1255
1246 # check for obsolete rc.conf(5) variables 1256 # check for obsolete rc.conf(5) variables
1247 set -- amd amd_master \ 1257 set -- amd amd_master \
1248 btcontrol btcontrol_devices \ 1258 btcontrol btcontrol_devices \
1249 critical_filesystems critical_filesystems_beforenet \ 1259 critical_filesystems critical_filesystems_beforenet \
1250 mountcritlocal mountcritremote \ 1260 mountcritlocal mountcritremote \
1251 network ip6forwarding \ 1261 network ip6forwarding \
1252 network nfsiod_flags \ 1262 network nfsiod_flags \
1253 sdpd sdpd_control \ 1263 sdpd sdpd_control \
1254 sdpd sdpd_groupname \ 1264 sdpd sdpd_groupname \
1255 sdpd sdpd_username \ 1265 sdpd sdpd_username \
1256 sysctl defcorename 1266 sysctl defcorename
1257 while [ $# -gt 1 ]; do 1267 while [ $# -gt 1 ]; do
1258 if rcconf_is_set "${op}" "$1" "$2" 1; then 1268 if rcconf_is_set "${op}" "$1" "$2" 1; then
1259 failed=1 1269 failed=1
1260 fi 1270 fi
1261 shift 2 1271 shift 2
1262 done 1272 done
1263 1273
1264 return ${failed} 1274 return ${failed}
1265} 1275}
1266 1276
1267# 1277#
1268# sendmail 1278# sendmail
1269# 1279#
1270adddisableditem sendmail "remove obsolete sendmail configuration files and scripts" 1280adddisableditem sendmail "remove obsolete sendmail configuration files and scripts"
1271do_sendmail() 1281do_sendmail()
1272{ 1282{
1273 [ -n "$1" ] || err 3 "USAGE: do_sendmail fix|check" 1283 [ -n "$1" ] || err 3 "USAGE: do_sendmail fix|check"
1274 op="$1" 1284 op="$1"
1275 failed=0 1285 failed=0
1276 1286
1277 # Don't complain if the "sendmail" package is installed because the 1287 # Don't complain if the "sendmail" package is installed because the
1278 # files might still be in use. 1288 # files might still be in use.
1279 if /usr/sbin/pkg_info -qe sendmail >/dev/null 2>&1; then 1289 if /usr/sbin/pkg_info -qe sendmail >/dev/null 2>&1; then
1280 return 0 1290 return 0
1281 fi 1291 fi
1282 1292
1283 for f in /etc/mail/helpfile /etc/mail/local-host-names \ 1293 for f in /etc/mail/helpfile /etc/mail/local-host-names \
1284 /etc/mail/sendmail.cf /etc/mail/submit.cf /etc/rc.d/sendmail \ 1294 /etc/mail/sendmail.cf /etc/mail/submit.cf /etc/rc.d/sendmail \
1285 /etc/rc.d/smmsp /usr/share/misc/sendmail.hf \ 1295 /etc/rc.d/smmsp /usr/share/misc/sendmail.hf \
1286 $(find "${DEST_DIR}/usr/share/sendmail" -type f) \ 1296 $(find "${DEST_DIR}/usr/share/sendmail" -type f) \
1287 $(find "${DEST_DIR}/usr/share/sendmail" -type d) \ 1297 $(find "${DEST_DIR}/usr/share/sendmail" -type d) \
1288 "${DEST_DIR}/var/log/sendmail.st" \ 1298 "${DEST_DIR}/var/log/sendmail.st" \
1289 "${DEST_DIR}/var/spool/clientmqueue" \ 1299 "${DEST_DIR}/var/spool/clientmqueue" \
1290 "${DEST_DIR}/var/spool/mqueue"; do 1300 "${DEST_DIR}/var/spool/mqueue"; do
1291 [ -e "${DEST_DIR}${f}" ] && echo "${f}" 1301 [ -e "${DEST_DIR}${f}" ] && echo "${f}"
1292 done | obsolete_paths "${op}" 1302 done | obsolete_paths "${op}"
1293 failed=$(( ${failed} + $? )) 1303 failed=$(( ${failed} + $? ))
1294 1304
1295 return ${failed} 1305 return ${failed}
1296} 1306}
1297 1307
1298# 1308#
1299# mailerconf 1309# mailerconf
1300# 1310#
1301adddisableditem mailerconf "update /etc/mailer.conf after sendmail removal" 1311adddisableditem mailerconf "update /etc/mailer.conf after sendmail removal"
1302do_mailerconf() 1312do_mailerconf()
1303{ 1313{
1304 [ -n "$1" ] || err 3 "USAGE: do_mailterconf fix|check" 1314 [ -n "$1" ] || err 3 "USAGE: do_mailterconf fix|check"
1305 op="$1" 1315 op="$1"
1306 1316
1307 failed=0 1317 failed=0
1308 mta_path="$(${AWK} '/^sendmail[ \t]/{print$2}' \ 1318 mta_path="$(${AWK} '/^sendmail[ \t]/{print$2}' \
1309 "${DEST_DIR}/etc/mailer.conf")" 1319 "${DEST_DIR}/etc/mailer.conf")"
1310 old_sendmail_path="/usr/libexec/sendmail/sendmail" 1320 old_sendmail_path="/usr/libexec/sendmail/sendmail"
1311 if [ "${mta_path}" = "${old_sendmail_path}" ]; then 1321 if [ "${mta_path}" = "${old_sendmail_path}" ]; then
1312 if [ "$op" = check ]; then 1322 if [ "$op" = check ]; then
1313 msg "mailer.conf points to obsolete ${old_sendmail_path}" 1323 msg "mailer.conf points to obsolete ${old_sendmail_path}"
1314 failed=1; 1324 failed=1;
1315 else 1325 else
1316 populate_dir "${op}" false \ 1326 populate_dir "${op}" false \
1317 "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 mailer.conf 1327 "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 mailer.conf
1318 failed=$? 1328 failed=$?
1319 fi 1329 fi
1320 fi 1330 fi
1321  1331
1322 return ${failed} 1332 return ${failed}
1323} 1333}
1324 1334
1325# 1335#
1326# ssh 1336# ssh
1327# 1337#
1328additem ssh "ssh configuration update" 1338additem ssh "ssh configuration update"
1329do_ssh() 1339do_ssh()
1330{ 1340{
1331 [ -n "$1" ] || err 3 "USAGE: do_ssh fix|check" 1341 [ -n "$1" ] || err 3 "USAGE: do_ssh fix|check"
1332 op="$1" 1342 op="$1"
1333 1343
1334 failed=0 1344 failed=0
1335 _etcssh="${DEST_DIR}/etc/ssh" 1345 _etcssh="${DEST_DIR}/etc/ssh"
1336 if ! check_dir "${op}" "${_etcssh}" 755; then 1346 if ! check_dir "${op}" "${_etcssh}" 755; then
1337 failed=1 1347 failed=1
1338 fi 1348 fi
1339 1349
1340 if [ ${failed} -eq 0 ]; then 1350 if [ ${failed} -eq 0 ]; then
1341 for f in \ 1351 for f in \
1342 ssh_known_hosts ssh_known_hosts2 \ 1352 ssh_known_hosts ssh_known_hosts2 \
1343 ssh_host_dsa_key ssh_host_dsa_key.pub \ 1353 ssh_host_dsa_key ssh_host_dsa_key.pub \
1344 ssh_host_rsa_key ssh_host_rsa_key.pub \ 1354 ssh_host_rsa_key ssh_host_rsa_key.pub \
1345 ssh_host_key ssh_host_key.pub \ 1355 ssh_host_key ssh_host_key.pub \
1346 ; do 1356 ; do
1347 if ! move_file "${op}" \ 1357 if ! move_file "${op}" \
1348 "${DEST_DIR}/etc/${f}" "${_etcssh}/${f}" ; then 1358 "${DEST_DIR}/etc/${f}" "${_etcssh}/${f}" ; then
1349 failed=1 1359 failed=1
1350 fi 1360 fi
1351 done 1361 done
1352 for f in sshd.conf ssh.conf ; do 1362 for f in sshd.conf ssh.conf ; do
1353 # /etc/ssh/ssh{,d}.conf -> ssh{,d}_config 1363 # /etc/ssh/ssh{,d}.conf -> ssh{,d}_config
1354 # 1364 #
1355 if ! move_file "${op}" \ 1365 if ! move_file "${op}" \
1356 "${_etcssh}/${f}" "${_etcssh}/${f%.conf}_config" ; 1366 "${_etcssh}/${f}" "${_etcssh}/${f%.conf}_config" ;
1357 then 1367 then
1358 failed=1 1368 failed=1
1359 fi 1369 fi
1360 # /etc/ssh{,d}.conf -> /etc/ssh/ssh{,d}_config 1370 # /etc/ssh{,d}.conf -> /etc/ssh/ssh{,d}_config
1361 # 1371 #
1362 if ! move_file "${op}" \ 1372 if ! move_file "${op}" \
1363 "${DEST_DIR}/etc/${f}" \ 1373 "${DEST_DIR}/etc/${f}" \
1364 "${_etcssh}/${f%.conf}_config" ; 1374 "${_etcssh}/${f%.conf}_config" ;
1365 then 1375 then
1366 failed=1 1376 failed=1
1367 fi 1377 fi
1368 done 1378 done
1369 fi 1379 fi
1370 1380
1371 sshdconf="" 1381 sshdconf=""
1372 for f in \ 1382 for f in \
1373 "${_etcssh}/sshd_config" \ 1383 "${_etcssh}/sshd_config" \
1374 "${_etcssh}/sshd.conf" \ 1384 "${_etcssh}/sshd.conf" \
1375 "${DEST_DIR}/etc/sshd.conf" ; do 1385 "${DEST_DIR}/etc/sshd.conf" ; do
1376 if [ -f "${f}" ]; then 1386 if [ -f "${f}" ]; then
1377 sshdconf="${f}" 1387 sshdconf="${f}"
1378 break 1388 break
1379 fi 1389 fi
1380 done 1390 done
1381 if [ -n "${sshdconf}" ]; then 1391 if [ -n "${sshdconf}" ]; then
1382 modify_file "${op}" "${sshdconf}" "${SCRATCHDIR}/sshdconf" ' 1392 modify_file "${op}" "${sshdconf}" "${SCRATCHDIR}/sshdconf" '
1383 /^[^#$]/ { 1393 /^[^#$]/ {
1384 kw = tolower($1) 1394 kw = tolower($1)
1385 if (kw == "hostkey" && 1395 if (kw == "hostkey" &&
1386 $2 ~ /^\/etc\/+ssh_host(_[dr]sa)?_key$/ ) { 1396 $2 ~ /^\/etc\/+ssh_host(_[dr]sa)?_key$/ ) {
1387 sub(/\/etc\/+/, "/etc/ssh/") 1397 sub(/\/etc\/+/, "/etc/ssh/")
1388 } 1398 }
1389 if (kw == "rhostsauthentication" || 1399 if (kw == "rhostsauthentication" ||
1390 kw == "verifyreversemapping" || 1400 kw == "verifyreversemapping" ||
1391 kw == "reversemappingcheck") { 1401 kw == "reversemappingcheck") {
1392 sub(/^/, "# DEPRECATED:\t") 1402 sub(/^/, "# DEPRECATED:\t")
1393 } 1403 }
1394 } 1404 }
1395 { print } 1405 { print }
1396 ' 1406 '
1397 failed=$(( ${failed} + $? )) 1407 failed=$(( ${failed} + $? ))
1398 fi 1408 fi
1399 1409
1400 if ! find_file_in_dirlist moduli "moduli" \ 1410 if ! find_file_in_dirlist moduli "moduli" \
1401 "${SRC_DIR}/crypto/external/bsd/openssh/dist" "${SRC_DIR}/etc" ; then 1411 "${SRC_DIR}/crypto/external/bsd/openssh/dist" "${SRC_DIR}/etc" ; then
1402 failed=1 1412 failed=1
1403 # ${dir} is set by find_file_in_dirlist() 1413 # ${dir} is set by find_file_in_dirlist()
1404 elif ! compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 moduli; then 1414 elif ! compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 moduli; then
1405 failed=1 1415 failed=1
1406 fi 1416 fi
1407 1417
1408 if ! check_dir "${op}" "${DEST_DIR}/var/chroot/sshd" 755 ; then 1418 if ! check_dir "${op}" "${DEST_DIR}/var/chroot/sshd" 755 ; then
1409 failed=1 1419 failed=1
1410 fi 1420 fi
1411 1421
1412 if rcconf_is_set "${op}" sshd sshd_conf_dir 1; then 1422 if rcconf_is_set "${op}" sshd sshd_conf_dir 1; then
1413 failed=1 1423 failed=1
1414 fi 1424 fi
1415 1425
1416 return ${failed} 1426 return ${failed}
1417} 1427}
1418 1428
1419# 1429#
1420# wscons 1430# wscons
1421# 1431#
1422additem wscons "wscons configuration file update" 1432additem wscons "wscons configuration file update"
1423do_wscons() 1433do_wscons()
1424{ 1434{
1425 [ -n "$1" ] || err 3 "USAGE: do_wscons fix|check" 1435 [ -n "$1" ] || err 3 "USAGE: do_wscons fix|check"
1426 op="$1" 1436 op="$1"
1427 1437
1428 [ -f "${DEST_DIR}/etc/wscons.conf" ] || return 0 1438 [ -f "${DEST_DIR}/etc/wscons.conf" ] || return 0
1429 1439
1430 failed=0 1440 failed=0
1431 notfixed="" 1441 notfixed=""
1432 if [ "${op}" = "fix" ]; then 1442 if [ "${op}" = "fix" ]; then
1433 notfixed="${NOT_FIXED}" 1443 notfixed="${NOT_FIXED}"
1434 fi 1444 fi
1435 while read _type _arg1 _rest; do 1445 while read _type _arg1 _rest; do
1436 if [ "${_type}" = "mux" -a "${_arg1}" = "1" ]; then 1446 if [ "${_type}" = "mux" -a "${_arg1}" = "1" ]; then
1437 msg \ 1447 msg \
1438 "Obsolete wscons.conf(5) entry \""${_type} ${_arg1}"\" found.${notfixed}" 1448 "Obsolete wscons.conf(5) entry \""${_type} ${_arg1}"\" found.${notfixed}"
1439 failed=1 1449 failed=1
1440 fi 1450 fi
1441 done < "${DEST_DIR}/etc/wscons.conf" 1451 done < "${DEST_DIR}/etc/wscons.conf"
1442 1452
1443 return ${failed} 1453 return ${failed}
1444} 1454}
1445 1455
1446# 1456#
1447# X11 1457# X11
1448# 1458#
1449additem x11 "x11 configuration update" 1459additem x11 "x11 configuration update"
1450do_x11() 1460do_x11()
1451{ 1461{
1452 [ -n "$1" ] || err 3 "USAGE: do_x11 fix|check" 1462 [ -n "$1" ] || err 3 "USAGE: do_x11 fix|check"
1453 op="$1" 1463 op="$1"
1454 1464
1455 failed=0 1465 failed=0
1456 _etcx11="${DEST_DIR}/etc/X11" 1466 _etcx11="${DEST_DIR}/etc/X11"
1457 if [ ! -d "${_etcx11}" ]; then 1467 if [ ! -d "${_etcx11}" ]; then
1458 msg "${_etcx11} is not a directory; skipping check" 1468 msg "${_etcx11} is not a directory; skipping check"
1459 return 0 1469 return 0
1460 fi 1470 fi
1461 if [ -d "${DEST_DIR}/usr/X11R6/." ] 1471 if [ -d "${DEST_DIR}/usr/X11R6/." ]
1462 then 1472 then
1463 _libx11="${DEST_DIR}/usr/X11R6/lib/X11" 1473 _libx11="${DEST_DIR}/usr/X11R6/lib/X11"
1464 if [ ! -d "${_libx11}" ]; then 1474 if [ ! -d "${_libx11}" ]; then
1465 msg "${_libx11} is not a directory; skipping check" 1475 msg "${_libx11} is not a directory; skipping check"
1466 return 0 1476 return 0
1467 fi 1477 fi
1468 fi 1478 fi
1469 1479
1470 _notfixed="" 1480 _notfixed=""
1471 if [ "${op}" = "fix" ]; then 1481 if [ "${op}" = "fix" ]; then
1472 _notfixed="${NOT_FIXED}" 1482 _notfixed="${NOT_FIXED}"
1473 fi 1483 fi
1474 1484
1475 for d in \ 1485 for d in \
1476 fs lbxproxy proxymngr rstart twm xdm xinit xserver xsm \ 1486 fs lbxproxy proxymngr rstart twm xdm xinit xserver xsm \
1477 ; do 1487 ; do
1478 sd="${_libx11}/${d}" 1488 sd="${_libx11}/${d}"
1479 ld="/etc/X11/${d}" 1489 ld="/etc/X11/${d}"
1480 td="${DEST_DIR}${ld}" 1490 td="${DEST_DIR}${ld}"
1481 if [ -h "${sd}" ]; then 1491 if [ -h "${sd}" ]; then
1482 continue 1492 continue
1483 elif [ -d "${sd}" ]; then 1493 elif [ -d "${sd}" ]; then
1484 tdfiles="$(find "${td}" \! -type d)" 1494 tdfiles="$(find "${td}" \! -type d)"
1485 if [ -n "${tdfiles}" ]; then 1495 if [ -n "${tdfiles}" ]; then
1486 msg "${sd} exists yet ${td} already" \ 1496 msg "${sd} exists yet ${td} already" \
1487 "contains files${_notfixed}" 1497 "contains files${_notfixed}"
1488 else 1498 else
1489 msg "Migrate ${sd} to ${td}${_notfixed}" 1499 msg "Migrate ${sd} to ${td}${_notfixed}"
1490 fi 1500 fi
1491 failed=1 1501 failed=1
1492 elif [ -e "${sd}" ]; then 1502 elif [ -e "${sd}" ]; then
1493 msg "Unexpected file ${sd}${_notfixed}" 1503 msg "Unexpected file ${sd}${_notfixed}"
1494 continue 1504 continue
1495 else 1505 else
1496 continue 1506 continue
1497 fi 1507 fi
1498 done 1508 done
1499 1509
1500 return ${failed} 1510 return ${failed}
1501} 1511}
1502 1512
1503# 1513#
1504# xkb 1514# xkb
1505# 1515#
1506# /usr/X11R7/lib/X11/xkb/symbols/pc used to be a directory, but changed 1516# /usr/X11R7/lib/X11/xkb/symbols/pc used to be a directory, but changed
1507# to a file on 2009-06-12. Fixing this requires removing the directory 1517# to a file on 2009-06-12. Fixing this requires removing the directory
1508# (which we can do) and re-extracting the xbase set (which we can't do), 1518# (which we can do) and re-extracting the xbase set (which we can't do),
1509# or at least adding that one file (which we may be able to do if X11SRCDIR 1519# or at least adding that one file (which we may be able to do if X11SRCDIR
1510# is available). 1520# is available).
1511# 1521#
1512additem xkb "clean up for xkbdata to xkeyboard-config upgrade" 1522additem xkb "clean up for xkbdata to xkeyboard-config upgrade"
1513do_xkb() 1523do_xkb()
1514{ 1524{
1515 [ -n "$1" ] || err 3 "USAGE: do_xkb fix|check" 1525 [ -n "$1" ] || err 3 "USAGE: do_xkb fix|check"
1516 op="$1" 1526 op="$1"
1517 failed=0 1527 failed=0
1518 1528
1519 pcpath="/usr/X11R7/lib/X11/xkb/symbols/pc" 1529 pcpath="/usr/X11R7/lib/X11/xkb/symbols/pc"
1520 pcsrcdir="${X11SRCDIR}/external/mit/xkeyboard-config/dist/symbols" 1530 pcsrcdir="${X11SRCDIR}/external/mit/xkeyboard-config/dist/symbols"
1521 1531
1522 filemsg="\ 1532 filemsg="\
1523${pcpath} was a directory, should be a file. 1533${pcpath} was a directory, should be a file.
1524 To fix, extract the xbase set again." 1534 To fix, extract the xbase set again."
1525 1535
1526 _notfixed="" 1536 _notfixed=""
1527 if [ "${op}" = "fix" ]; then 1537 if [ "${op}" = "fix" ]; then
1528 _notfixed="${NOT_FIXED}" 1538 _notfixed="${NOT_FIXED}"
1529 fi 1539 fi
1530 1540
1531 if [ ! -d "${DESTDIR}${pcpath}" ]; then 1541 if [ ! -d "${DESTDIR}${pcpath}" ]; then
1532 return 0 1542 return 0
1533 fi 1543 fi
1534 1544
1535 # Delete obsolete files in the directory, and the directory 1545 # Delete obsolete files in the directory, and the directory
1536 # itself. If the directory contains unexpected extra files 1546 # itself. If the directory contains unexpected extra files
1537 # then it will not be deleted. 1547 # then it will not be deleted.
1538 ( [ -f "${DEST_DIR}"/var/db/obsolete/xbase ] \ 1548 ( [ -f "${DEST_DIR}"/var/db/obsolete/xbase ] \
1539 && sort -ru "${DEST_DIR}"/var/db/obsolete/xbase \ 1549 && sort -ru "${DEST_DIR}"/var/db/obsolete/xbase \
1540 | ${GREP} -E "^\\.?${pcpath}/" ; 1550 | ${GREP} -E "^\\.?${pcpath}/" ;
1541 echo "${pcpath}" ) \ 1551 echo "${pcpath}" ) \
1542 | obsolete_paths "${op}" 1552 | obsolete_paths "${op}"
1543 failed=$(( ${failed} + $? )) 1553 failed=$(( ${failed} + $? ))
1544 1554
1545 # If the directory was removed above, then try to replace it with 1555 # If the directory was removed above, then try to replace it with
1546 # a file. 1556 # a file.
1547 if [ -d "${DESTDIR}${pcpath}" ]; then 1557 if [ -d "${DESTDIR}${pcpath}" ]; then
1548 msg "${filemsg}${_notfixed}" 1558 msg "${filemsg}${_notfixed}"
1549 failed=$(( ${failed} + 1 )) 1559 failed=$(( ${failed} + 1 ))
1550 else 1560 else
1551 if ! find_file_in_dirlist pc "${pcpath}" \ 1561 if ! find_file_in_dirlist pc "${pcpath}" \
1552 "${pcsrcdir}" "${SRC_DIR}${pcpath%/*}" 1562 "${pcsrcdir}" "${SRC_DIR}${pcpath%/*}"
1553 then 1563 then
1554 msg "${filemsg}${_notfixed}" 1564 msg "${filemsg}${_notfixed}"
1555 failed=$(( ${failed} + 1 )) 1565 failed=$(( ${failed} + 1 ))
1556 else 1566 else
1557 # ${dir} is set by find_file_in_dirlist() 1567 # ${dir} is set by find_file_in_dirlist()
1558 populate_dir "${op}" true \ 1568 populate_dir "${op}" true \
1559 "${dir}" "${DEST_DIR}${pcpath%/*}" 444 \ 1569 "${dir}" "${DEST_DIR}${pcpath%/*}" 444 \
1560 pc 1570 pc
1561 failed=$(( ${failed} + $? )) 1571 failed=$(( ${failed} + $? ))
1562 fi 1572 fi
1563 fi 1573 fi
1564 1574
1565 return $failed 1575 return $failed
1566} 1576}
1567 1577
1568# 1578#
1569# uid 1579# uid
1570# 1580#
1571additem uid "required users in /etc/master.passwd" 1581additem uid "required users in /etc/master.passwd"
1572do_uid() 1582do_uid()
1573{ 1583{
1574 [ -n "$1" ] || err 3 "USAGE: do_uid fix|check" 1584 [ -n "$1" ] || err 3 "USAGE: do_uid fix|check"
1575 1585
1576 check_ids "$1" users "${DEST_DIR}/etc/master.passwd" \ 1586 check_ids "$1" users "${DEST_DIR}/etc/master.passwd" 12 \
1577 named ntpd postfix sshd _pflogd _rwhod _proxy _timedc \ 1587 postfix named ntpd sshd SKIP _pflogd _rwhod SKIP _proxy _timedc \
1578 _sdpd _httpd _mdnsd _tests _tcpdump _tss 1588 _sdpd _httpd _mdnsd _tests _tcpdump _tss
1579} 1589}
1580 1590
1581 1591
1582# 1592#
1583# varrwho 1593# varrwho
1584# 1594#
1585additem varrwho "required ownership of files in /var/rwho" 1595additem varrwho "required ownership of files in /var/rwho"
1586do_varrwho() 1596do_varrwho()
1587{ 1597{
1588 [ -n "$1" ] || err 3 "USAGE: do_varrwho fix|check" 1598 [ -n "$1" ] || err 3 "USAGE: do_varrwho fix|check"
1589 1599
1590 contents_owner "$1" "${DEST_DIR}/var/rwho" _rwhod _rwhod 1600 contents_owner "$1" "${DEST_DIR}/var/rwho" _rwhod _rwhod
1591} 1601}
1592 1602
1593 1603
1594# 1604#
1595# tcpdumpchroot 1605# tcpdumpchroot
1596# 1606#
1597additem tcpdumpchroot "remove /var/chroot/tcpdump/etc/protocols" 1607additem tcpdumpchroot "remove /var/chroot/tcpdump/etc/protocols"
1598do_tcpdumpchroot() 1608do_tcpdumpchroot()
1599{ 1609{
1600 [ -n "$1" ] || err 3 "USAGE: do_tcpdumpchroot fix|check" 1610 [ -n "$1" ] || err 3 "USAGE: do_tcpdumpchroot fix|check"
1601 1611
1602 failed=0; 1612 failed=0;
1603 if [ -r "${DEST_DIR}/var/chroot/tcpdump/etc/protocols" ]; then 1613 if [ -r "${DEST_DIR}/var/chroot/tcpdump/etc/protocols" ]; then
1604 if [ "$1" = "fix" ]; then 1614 if [ "$1" = "fix" ]; then
1605 rm "${DEST_DIR}/var/chroot/tcpdump/etc/protocols" 1615 rm "${DEST_DIR}/var/chroot/tcpdump/etc/protocols"
1606 failed=$(( ${failed} + $? )) 1616 failed=$(( ${failed} + $? ))
1607 rmdir "${DEST_DIR}/var/chroot/tcpdump/etc" 1617 rmdir "${DEST_DIR}/var/chroot/tcpdump/etc"
1608 failed=$(( ${failed} + $? )) 1618 failed=$(( ${failed} + $? ))
1609 else 1619 else
1610 failed=1 1620 failed=1
1611 fi 1621 fi
1612 fi 1622 fi
1613 return ${failed} 1623 return ${failed}
1614} 1624}
1615 1625
1616 1626
1617# 1627#
1618# atf 1628# atf
1619# 1629#
1620additem atf "install missing atf configuration files and validate them" 1630additem atf "install missing atf configuration files and validate them"
1621do_atf() 1631do_atf()
1622{ 1632{
1623 [ -n "$1" ] || err 3 "USAGE: do_atf fix|check" 1633 [ -n "$1" ] || err 3 "USAGE: do_atf fix|check"
1624 op="$1" 1634 op="$1"
1625 failed=0 1635 failed=0
1626 1636
1627 # Ensure atf configuration files are in place. 1637 # Ensure atf configuration files are in place.
1628 if find_file_in_dirlist NetBSD.conf "NetBSD.conf" \ 1638 if find_file_in_dirlist NetBSD.conf "NetBSD.conf" \
1629 "${SRC_DIR}/external/bsd/atf/etc/atf" \ 1639 "${SRC_DIR}/external/bsd/atf/etc/atf" \
1630 "${SRC_DIR}/etc/atf"; then 1640 "${SRC_DIR}/etc/atf"; then
1631 # ${dir} is set by find_file_in_dirlist() 1641 # ${dir} is set by find_file_in_dirlist()
1632 populate_dir "${op}" true "${dir}" "${DEST_DIR}/etc/atf" 644 \ 1642 populate_dir "${op}" true "${dir}" "${DEST_DIR}/etc/atf" 644 \
1633 NetBSD.conf common.conf || failed=1 1643 NetBSD.conf common.conf || failed=1
1634 else 1644 else
1635 failed=1 1645 failed=1
1636 fi 1646 fi
1637 if find_file_in_dirlist atf-run.hooks "atf-run.hooks" \ 1647 if find_file_in_dirlist atf-run.hooks "atf-run.hooks" \
1638 "${SRC_DIR}/external/bsd/atf/dist/atf-run/sample" \ 1648 "${SRC_DIR}/external/bsd/atf/dist/atf-run/sample" \
1639 "${SRC_DIR}/etc/atf"; then 1649 "${SRC_DIR}/etc/atf"; then
1640 # ${dir} is set by find_file_in_dirlist() 1650 # ${dir} is set by find_file_in_dirlist()
1641 populate_dir "${op}" true "${dir}" "${DEST_DIR}/etc/atf" 644 \ 1651 populate_dir "${op}" true "${dir}" "${DEST_DIR}/etc/atf" 644 \
1642 atf-run.hooks || failed=1 1652 atf-run.hooks || failed=1
1643 else 1653 else
1644 failed=1 1654 failed=1
1645 fi 1655 fi
1646 1656
1647 # Validate the _atf to _tests user/group renaming. 1657 # Validate the _atf to _tests user/group renaming.
1648 if [ -f "${DEST_DIR}/etc/atf/common.conf" ]; then 1658 if [ -f "${DEST_DIR}/etc/atf/common.conf" ]; then
1649 handle_atf_user "${op}" || failed=1 1659 handle_atf_user "${op}" || failed=1
1650 else 1660 else
1651 failed=1 1661 failed=1
1652 fi 1662 fi
1653 1663
1654 return ${failed} 1664 return ${failed}
1655} 1665}
1656 1666
1657handle_atf_user() 1667handle_atf_user()
1658{ 1668{
1659 local op="$1" 1669 local op="$1"
1660 local failed=0 1670 local failed=0
1661 1671
1662 local conf="${DEST_DIR}/etc/atf/common.conf" 1672 local conf="${DEST_DIR}/etc/atf/common.conf"
1663 if grep '[^#]*unprivileged-user[ \t]*=.*_atf' "${conf}" >/dev/null 1673 if grep '[^#]*unprivileged-user[ \t]*=.*_atf' "${conf}" >/dev/null
1664 then 1674 then
1665 if [ "$1" = "fix" ]; then 1675 if [ "$1" = "fix" ]; then
1666 sed -e \ 1676 sed -e \
1667 "/[^#]*unprivileged-user[\ t]*=/s/_atf/_tests/" \ 1677 "/[^#]*unprivileged-user[\ t]*=/s/_atf/_tests/" \
1668 "${conf}" >"${conf}.new" 1678 "${conf}" >"${conf}.new"
1669 failed=$(( ${failed} + $? )) 1679 failed=$(( ${failed} + $? ))
1670 mv "${conf}.new" "${conf}" 1680 mv "${conf}.new" "${conf}"
1671 failed=$(( ${failed} + $? )) 1681 failed=$(( ${failed} + $? ))
1672 msg "Set unprivileged-user=_tests in ${conf}" 1682 msg "Set unprivileged-user=_tests in ${conf}"
1673 else 1683 else
1674 msg "unprivileged-user=_atf in ${conf} should be" \ 1684 msg "unprivileged-user=_atf in ${conf} should be" \
1675 "unprivileged-user=_tests" 1685 "unprivileged-user=_tests"
1676 failed=1 1686 failed=1
1677 fi 1687 fi
1678 fi 1688 fi
1679 1689
1680 return ${failed} 1690 return ${failed}
1681} 1691}
1682 1692
1683# 1693#
1684# catpages 1694# catpages
1685# 1695#
1686obsolete_catpages() 1696obsolete_catpages()
1687{ 1697{
1688 basedir="$2" 1698 basedir="$2"
1689 section="$3" 1699 section="$3"
1690 mandir="${basedir}/man${section}" 1700 mandir="${basedir}/man${section}"
1691 catdir="${basedir}/cat${section}" 1701 catdir="${basedir}/cat${section}"
1692 test -d "$mandir" || return 0 1702 test -d "$mandir" || return 0
1693 test -d "$catdir" || return 0 1703 test -d "$catdir" || return 0
1694 (cd "$mandir" && find . -type f) | { 1704 (cd "$mandir" && find . -type f) | {
1695 failed=0 1705 failed=0
1696 while read manpage; do 1706 while read manpage; do
1697 manpage="${manpage#./}" 1707 manpage="${manpage#./}"
1698 case "$manpage" in 1708 case "$manpage" in
1699 *.Z) 1709 *.Z)
1700 catname="$catdir/${manpage%.*.Z}.0" 1710 catname="$catdir/${manpage%.*.Z}.0"
1701 ;; 1711 ;;
1702 *.gz) 1712 *.gz)
1703 catname="$catdir/${manpage%.*.gz}.0" 1713 catname="$catdir/${manpage%.*.gz}.0"
1704 ;; 1714 ;;
1705 *) 1715 *)
1706 catname="$catdir/${manpage%.*}.0" 1716 catname="$catdir/${manpage%.*}.0"
1707 ;; 1717 ;;
1708 esac 1718 esac
1709 test -e "$catname" -a "$catname" -ot "$mandir/$manpage" || continue 1719 test -e "$catname" -a "$catname" -ot "$mandir/$manpage" || continue
1710 if [ "$1" = "fix" ]; then 1720 if [ "$1" = "fix" ]; then
1711 rm "$catname" 1721 rm "$catname"
1712 failed=$(( ${failed} + $? )) 1722 failed=$(( ${failed} + $? ))
1713 msg "Removed obsolete cat page $catname" 1723 msg "Removed obsolete cat page $catname"
1714 else 1724 else
1715 msg "Obsolete cat page $catname" 1725 msg "Obsolete cat page $catname"
1716 failed=1 1726 failed=1
1717 fi 1727 fi
1718 done 1728 done
1719 exit $failed 1729 exit $failed
1720 } 1730 }
1721} 1731}
1722 1732
1723additem catpages "remove outdated cat pages" 1733additem catpages "remove outdated cat pages"
1724do_catpages() 1734do_catpages()
1725{ 1735{
1726 failed=0 1736 failed=0
1727 for manbase in /usr/share/man /usr/X11R6/man /usr/X11R7/man; do 1737 for manbase in /usr/share/man /usr/X11R6/man /usr/X11R7/man; do
1728 for sec in 1 2 3 4 5 6 7 8 9; do 1738 for sec in 1 2 3 4 5 6 7 8 9; do
1729 obsolete_catpages "$1" "${DEST_DIR}${manbase}" "${sec}" 1739 obsolete_catpages "$1" "${DEST_DIR}${manbase}" "${sec}"
1730 failed=$(( ${failed} + $? )) 1740 failed=$(( ${failed} + $? ))
1731 if [ "$1" = "fix" ]; then 1741 if [ "$1" = "fix" ]; then
1732 rmdir "${DEST_DIR}${manbase}/cat${sec}"/* \ 1742 rmdir "${DEST_DIR}${manbase}/cat${sec}"/* \
1733 2>/dev/null 1743 2>/dev/null
1734 rmdir "${DEST_DIR}${manbase}/cat${sec}" \ 1744 rmdir "${DEST_DIR}${manbase}/cat${sec}" \
1735 2>/dev/null 1745 2>/dev/null
1736 fi 1746 fi
1737 done 1747 done
1738 done 1748 done
1739 return $failed 1749 return $failed
1740} 1750}
1741 1751
1742# 1752#
1743# obsolete 1753# obsolete
1744# (this item is last to allow other items to move obsolete files) 1754# (this item is last to allow other items to move obsolete files)
1745# 1755#
1746additem obsolete "remove obsolete file sets and minor libraries" 1756additem obsolete "remove obsolete file sets and minor libraries"
1747do_obsolete() 1757do_obsolete()
1748{ 1758{
1749 [ -n "$1" ] || err 3 "USAGE: do_obsolete fix|check" 1759 [ -n "$1" ] || err 3 "USAGE: do_obsolete fix|check"
1750 op="$1" 1760 op="$1"
1751 failed=0 1761 failed=0
1752 1762
1753 sort -ru "${DEST_DIR}"/var/db/obsolete/* | obsolete_paths "${op}" 1763 sort -ru "${DEST_DIR}"/var/db/obsolete/* | obsolete_paths "${op}"
1754 failed=$(( ${failed} + $? )) 1764 failed=$(( ${failed} + $? ))
1755 1765
1756 ( 1766 (
1757 obsolete_libs /lib 1767 obsolete_libs /lib
1758 obsolete_libs /usr/lib 1768 obsolete_libs /usr/lib
1759 obsolete_libs /usr/lib/i18n 1769 obsolete_libs /usr/lib/i18n
1760 obsolete_libs /usr/X11R6/lib 1770 obsolete_libs /usr/X11R6/lib
1761 obsolete_libs /usr/X11R7/lib 1771 obsolete_libs /usr/X11R7/lib
1762 [ "$MACHINE" = "amd64" ] && obsolete_libs /usr/lib/i386 1772 [ "$MACHINE" = "amd64" ] && obsolete_libs /usr/lib/i386
1763 [ "$MACHINE" = "sparc64" ] && obsolete_libs /usr/lib/sparc 1773 [ "$MACHINE" = "sparc64" ] && obsolete_libs /usr/lib/sparc
1764 ) | obsolete_paths "${op}" 1774 ) | obsolete_paths "${op}"
1765 failed=$(( ${failed} + $? )) 1775 failed=$(( ${failed} + $? ))
1766 1776
1767 return ${failed} 1777 return ${failed}
1768} 1778}
1769 1779
1770 1780
1771# 1781#
1772# ptyfsoldnodes 1782# ptyfsoldnodes
1773# 1783#
1774additem ptyfsoldnodes "remove legacy device nodes when using ptyfs" 1784additem ptyfsoldnodes "remove legacy device nodes when using ptyfs"
1775do_ptyfsoldnodes() 1785do_ptyfsoldnodes()
1776{ 1786{
1777 [ -n "$1" ] || err 3 "USAGE: do_ptyfsoldnodes fix|check" 1787 [ -n "$1" ] || err 3 "USAGE: do_ptyfsoldnodes fix|check"
1778 _ptyfs_op="$1" 1788 _ptyfs_op="$1"
1779 1789
1780 # Check whether ptyfs is in use 1790 # Check whether ptyfs is in use
1781 failed=0; 1791 failed=0;
1782 if ! ${GREP} -E "^ptyfs" "${DEST_DIR}/etc/fstab" > /dev/null; then 1792 if ! ${GREP} -E "^ptyfs" "${DEST_DIR}/etc/fstab" > /dev/null; then
1783 msg "ptyfs is not in use" 1793 msg "ptyfs is not in use"
1784 return 0 1794 return 0
1785 fi 1795 fi
1786 1796
1787 # Find the device major numbers for the pty master and slave 1797 # Find the device major numbers for the pty master and slave
1788 # devices, by parsing the output from "MAKEDEV -s pty0". 1798 # devices, by parsing the output from "MAKEDEV -s pty0".
1789 # 1799 #
1790 # Output from MAKEDEV looks like this: 1800 # Output from MAKEDEV looks like this:
1791 # ./ttyp0 type=char device=netbsd,5,0 mode=666 gid=0 uid=0 1801 # ./ttyp0 type=char device=netbsd,5,0 mode=666 gid=0 uid=0
1792 # ./ptyp0 type=char device=netbsd,6,0 mode=666 gid=0 uid=0 1802 # ./ptyp0 type=char device=netbsd,6,0 mode=666 gid=0 uid=0
1793 # 1803 #
1794 # Output from awk, used in the eval statement, looks like this: 1804 # Output from awk, used in the eval statement, looks like this:
1795 # maj_ptym=6; maj_ptys=5; 1805 # maj_ptym=6; maj_ptys=5;
1796 # 1806 #
1797 eval "$( 1807 eval "$(
1798 ${HOST_SH} "${DEST_DIR}/dev/MAKEDEV" -s pty0 2>/dev/null \ 1808 ${HOST_SH} "${DEST_DIR}/dev/MAKEDEV" -s pty0 2>/dev/null \
1799 | ${AWK} '\ 1809 | ${AWK} '\
1800 BEGIN { before_re = ".*device=[a-zA-Z]*,"; after_re = ",.*"; } 1810 BEGIN { before_re = ".*device=[a-zA-Z]*,"; after_re = ",.*"; }
1801 /ptyp0/ { maj_ptym = gensub(before_re, "", 1, $0); 1811 /ptyp0/ { maj_ptym = gensub(before_re, "", 1, $0);
1802 maj_ptym = gensub(after_re, "", 1, maj_ptym); } 1812 maj_ptym = gensub(after_re, "", 1, maj_ptym); }
1803 /ttyp0/ { maj_ptys = gensub(before_re, "", 1, $0); 1813 /ttyp0/ { maj_ptys = gensub(before_re, "", 1, $0);
1804 maj_ptys = gensub(after_re, "", 1, maj_ptys); } 1814 maj_ptys = gensub(after_re, "", 1, maj_ptys); }
1805 END { print "maj_ptym=" maj_ptym "; maj_ptys=" maj_ptys ";"; } 1815 END { print "maj_ptym=" maj_ptym "; maj_ptys=" maj_ptys ";"; }
1806 ' 1816 '
1807 )" 1817 )"
1808 #msg "Major numbers are maj_ptym=${maj_ptym} maj_ptys=${maj_ptys}" 1818 #msg "Major numbers are maj_ptym=${maj_ptym} maj_ptys=${maj_ptys}"
1809 if [ -z "$maj_ptym" ] || [ -z "$maj_ptys" ]; then 1819 if [ -z "$maj_ptym" ] || [ -z "$maj_ptys" ]; then
1810 msg "Cannot find device major numbers for pty master and slave" 1820 msg "Cannot find device major numbers for pty master and slave"
1811 return 1 1821 return 1
1812 fi 1822 fi
1813 1823
1814 # look for /dev/[pt]ty[p-zP-T][0-9a-zA-Z], and check that they 1824 # look for /dev/[pt]ty[p-zP-T][0-9a-zA-Z], and check that they
1815 # have the expected device major numbers. ttyv* is typically not a 1825 # have the expected device major numbers. ttyv* is typically not a
1816 # pty device, but we check it anyway. 1826 # pty device, but we check it anyway.
1817 # 1827 #
1818 # The "for d1" loop is intended to avoid overflowing ARG_MAX; 1828 # The "for d1" loop is intended to avoid overflowing ARG_MAX;
1819 # otherwise we could have used a single glob pattern. 1829 # otherwise we could have used a single glob pattern.
1820 # 1830 #
1821 # If there are no files that match a particular pattern, 1831 # If there are no files that match a particular pattern,
1822 # then stat prints something like: 1832 # then stat prints something like:
1823 # stat: /dev/[pt]tyx?: lstat: No such file or directory 1833 # stat: /dev/[pt]tyx?: lstat: No such file or directory
1824 # and we ignore it. XXX: We also ignore other error messages. 1834 # and we ignore it. XXX: We also ignore other error messages.
1825 # 1835 #
1826 _ptyfs_tmp="$(mktemp /tmp/postinstall.ptyfs.XXXXXXXX)" 1836 _ptyfs_tmp="$(mktemp /tmp/postinstall.ptyfs.XXXXXXXX)"
1827 for d1 in p q r s t u v w x y z P Q R S T; do 1837 for d1 in p q r s t u v w x y z P Q R S T; do
1828 ${STAT} -f "%Hr %N" "${DEST_DIR}/dev/"[pt]ty${d1}? 2>&1 1838 ${STAT} -f "%Hr %N" "${DEST_DIR}/dev/"[pt]ty${d1}? 2>&1
1829 done \ 1839 done \
1830 | while read -r major node ; do 1840 | while read -r major node ; do
1831 case "$major" in 1841 case "$major" in
1832 ${maj_ptym}|${maj_ptys}) echo "$node" ;; 1842 ${maj_ptym}|${maj_ptys}) echo "$node" ;;
1833 esac 1843 esac
1834 done >"${_ptyfs_tmp}" 1844 done >"${_ptyfs_tmp}"
1835 1845
1836 _desc="legacy device node" 1846 _desc="legacy device node"
1837 while read node; do 1847 while read node; do
1838 if [ "${_ptyfs_op}" = "check" ]; then 1848 if [ "${_ptyfs_op}" = "check" ]; then
1839 msg "Remove ${_desc} ${node}" 1849 msg "Remove ${_desc} ${node}"
1840 failed=1 1850 failed=1
1841 else # "fix" 1851 else # "fix"
1842 if rm "${node}"; then 1852 if rm "${node}"; then
1843 msg "Removed ${_desc} ${node}" 1853 msg "Removed ${_desc} ${node}"
1844 else 1854 else
1845 warn "Failed to remove ${_desc} ${node}" 1855 warn "Failed to remove ${_desc} ${node}"
1846 failed=1 1856 failed=1
1847 fi 1857 fi
1848 fi 1858 fi
1849 done < "${_ptyfs_tmp}" 1859 done < "${_ptyfs_tmp}"
1850 rm "${_ptyfs_tmp}" 1860 rm "${_ptyfs_tmp}"
1851 1861
1852 return ${failed} 1862 return ${failed}
1853} 1863}
1854 1864
1855 1865
1856# 1866#
1857# end of items 1867# end of items
1858# ------------ 1868# ------------
1859# 1869#
1860 1870
1861 1871
1862usage() 1872usage()
1863{ 1873{
1864 cat 1>&2 << _USAGE_ 1874 cat 1>&2 << _USAGE_
1865Usage: ${PROGNAME} [-s srcdir] [-x xsrcdir] [-d destdir] [-m mach] [-a arch] op [item [...]] 1875Usage: ${PROGNAME} [-s srcdir] [-x xsrcdir] [-d destdir] [-m mach] [-a arch] op [item [...]]
1866 Perform post-installation checks and/or fixes on a system's 1876 Perform post-installation checks and/or fixes on a system's
1867 configuration files. 1877 configuration files.
1868 If no items are provided, a default set of checks or fixes is applied. 1878 If no items are provided, a default set of checks or fixes is applied.
1869 1879
1870 Options: 1880 Options:
1871 -s {srcdir|tgzfile|tempdir} 1881 -s {srcdir|tgzfile|tempdir}
1872 Location of the source files. This may be any 1882 Location of the source files. This may be any
1873 of the following: 1883 of the following:
1874 * A directory that contains a NetBSD source tree; 1884 * A directory that contains a NetBSD source tree;
1875 * A distribution set file such as "etc.tgz" or 1885 * A distribution set file such as "etc.tgz" or
1876 "xetc.tgz". Pass multiple -s options to specify 1886 "xetc.tgz". Pass multiple -s options to specify
1877 multiple such files; 1887 multiple such files;
1878 * A temporary directory in which one or both of 1888 * A temporary directory in which one or both of
1879 "etc.tgz" and "xetc.tgz" have been extracted. 1889 "etc.tgz" and "xetc.tgz" have been extracted.
1880 [${SRC_DIR:-/usr/src}] 1890 [${SRC_DIR:-/usr/src}]
1881 -x xsrcdir Location of the X11 source files. This must be 1891 -x xsrcdir Location of the X11 source files. This must be
1882 a directory that contains a NetBSD xsrc tree. 1892 a directory that contains a NetBSD xsrc tree.
1883 [${XSRC_DIR:-/usr/src/../xsrc}] 1893 [${XSRC_DIR:-/usr/src/../xsrc}]
1884 -d destdir Destination directory to check. [${DEST_DIR:-/}] 1894 -d destdir Destination directory to check. [${DEST_DIR:-/}]
1885 -m mach MACHINE. [${MACHINE}] 1895 -m mach MACHINE. [${MACHINE}]
1886 -a arch MACHINE_ARCH. [${MACHINE_ARCH}] 1896 -a arch MACHINE_ARCH. [${MACHINE_ARCH}]
1887 1897
1888 Operation may be one of: 1898 Operation may be one of:
1889 help Display this help. 1899 help Display this help.
1890 list List available items. 1900 list List available items.
1891 check Perform post-installation checks on items. 1901 check Perform post-installation checks on items.
1892 diff [diff(1) options ...] 1902 diff [diff(1) options ...]
1893 Similar to 'check' but also output difference of files. 1903 Similar to 'check' but also output difference of files.
1894 fix Apply fixes that 'check' determines need to be applied. 1904 fix Apply fixes that 'check' determines need to be applied.
1895 usage Display this usage. 1905 usage Display this usage.
1896_USAGE_ 1906_USAGE_
1897 exit 2 1907 exit 2
1898} 1908}
1899 1909
1900 1910
1901list() 1911list()
1902{ 1912{
1903 echo "Default set of items (to apply if no items are provided by user):" 1913 echo "Default set of items (to apply if no items are provided by user):"
1904 echo " Item Description" 1914 echo " Item Description"
1905 echo " ---- -----------" 1915 echo " ---- -----------"
1906 for i in ${defaultitems}; do 1916 for i in ${defaultitems}; do
1907 eval desc=\"\${desc_${i}}\" 1917 eval desc=\"\${desc_${i}}\"
1908 printf " %-12s %s\n" "${i}" "${desc}" 1918 printf " %-12s %s\n" "${i}" "${desc}"
1909 done 1919 done
1910 echo "Items disabled by default (must be requested explicitly):" 1920 echo "Items disabled by default (must be requested explicitly):"
1911 echo " Item Description" 1921 echo " Item Description"
1912 echo " ---- -----------" 1922 echo " ---- -----------"
1913 for i in ${otheritems}; do 1923 for i in ${otheritems}; do
1914 eval desc=\"\${desc_${i}}\" 1924 eval desc=\"\${desc_${i}}\"
1915 printf " %-12s %s\n" "${i}" "${desc}" 1925 printf " %-12s %s\n" "${i}" "${desc}"
1916 done 1926 done
1917 1927
1918} 1928}
1919 1929
1920 1930
1921main() 1931main()
1922{ 1932{
1923 TGZLIST= # quoted list list of tgz files 1933 TGZLIST= # quoted list list of tgz files
1924 SRC_ARGLIST= # quoted list of one or more "-s" args 1934 SRC_ARGLIST= # quoted list of one or more "-s" args
1925 SRC_DIR="${SRC_ARG}" # set default value for early usage() 1935 SRC_DIR="${SRC_ARG}" # set default value for early usage()
1926 XSRC_DIR="${SRC_ARG}/../xsrc" 1936 XSRC_DIR="${SRC_ARG}/../xsrc"
1927 N_SRC_ARGS=0 # number of "-s" args 1937 N_SRC_ARGS=0 # number of "-s" args
1928 TGZMODE=false # true if "-s" specifies a tgz file 1938 TGZMODE=false # true if "-s" specifies a tgz file
1929 DIRMODE=false # true if "-s" specified a directory 1939 DIRMODE=false # true if "-s" specified a directory
1930 SOURCEMODE=false # true if "-s" specified a source directory 1940 SOURCEMODE=false # true if "-s" specified a source directory
1931 1941
1932 while getopts s:x:d:m:a: ch; do 1942 while getopts s:x:d:m:a: ch; do
1933 case "${ch}" in 1943 case "${ch}" in
1934 s) 1944 s)
1935 qarg="$(shell_quote "${OPTARG}")" 1945 qarg="$(shell_quote "${OPTARG}")"
1936 N_SRC_ARGS=$(( $N_SRC_ARGS + 1 )) 1946 N_SRC_ARGS=$(( $N_SRC_ARGS + 1 ))
1937 SRC_ARGLIST="${SRC_ARGLIST}${SRC_ARGLIST:+ }-s ${qarg}" 1947 SRC_ARGLIST="${SRC_ARGLIST}${SRC_ARGLIST:+ }-s ${qarg}"
1938 if [ -f "${OPTARG}" ]; then 1948 if [ -f "${OPTARG}" ]; then
1939 # arg refers to a *.tgz file. 1949 # arg refers to a *.tgz file.
1940 # This may happen twice, for both 1950 # This may happen twice, for both
1941 # etc.tgz and xetc.tgz, so we build up a 1951 # etc.tgz and xetc.tgz, so we build up a
1942 # quoted list in TGZLIST. 1952 # quoted list in TGZLIST.
1943 TGZMODE=true 1953 TGZMODE=true
1944 TGZLIST="${TGZLIST}${TGZLIST:+ }${qarg}" 1954 TGZLIST="${TGZLIST}${TGZLIST:+ }${qarg}"
1945 # Note that, when TGZMODE is true, 1955 # Note that, when TGZMODE is true,
1946 # SRC_ARG is used only for printing 1956 # SRC_ARG is used only for printing
1947 # human-readable messages. 1957 # human-readable messages.
1948 SRC_ARG="${TGZLIST}" 1958 SRC_ARG="${TGZLIST}"
1949 elif [ -d "${OPTARG}" ]; then 1959 elif [ -d "${OPTARG}" ]; then
1950 # arg refers to a directory. 1960 # arg refers to a directory.
1951 # It might be a source directory, or a 1961 # It might be a source directory, or a
1952 # directory where the sets have already 1962 # directory where the sets have already
1953 # been extracted. 1963 # been extracted.
1954 DIRMODE=true 1964 DIRMODE=true
1955 SRC_ARG="${OPTARG}" 1965 SRC_ARG="${OPTARG}"
1956 if [ -f "${OPTARG}/etc/Makefile" ]; then 1966 if [ -f "${OPTARG}/etc/Makefile" ]; then
1957 SOURCEMODE=true 1967 SOURCEMODE=true
1958 fi 1968 fi
1959 else 1969 else
1960 err 2 "Invalid argument for -s option" 1970 err 2 "Invalid argument for -s option"
1961 fi 1971 fi
1962 ;; 1972 ;;
1963 x) 1973 x)
1964 if [ -d "${OPTARG}" ]; then 1974 if [ -d "${OPTARG}" ]; then
1965 # arg refers to a directory. 1975 # arg refers to a directory.
1966 XSRC_DIR="${OPTARG}" 1976 XSRC_DIR="${OPTARG}"
1967 else 1977 else
1968 err 2 "Not a directory for -x option" 1978 err 2 "Not a directory for -x option"
1969 fi 1979 fi
1970 ;; 1980 ;;
1971 d) 1981 d)
1972 DEST_DIR="${OPTARG}" 1982 DEST_DIR="${OPTARG}"
1973 ;; 1983 ;;
1974 m) 1984 m)
1975 MACHINE="${OPTARG}" 1985 MACHINE="${OPTARG}"
1976 ;; 1986 ;;
1977 a) 1987 a)
1978 MACHINE_ARCH="${OPTARG}" 1988 MACHINE_ARCH="${OPTARG}"
1979 ;; 1989 ;;
1980 *) 1990 *)
1981 usage 1991 usage
1982 ;; 1992 ;;
1983 esac 1993 esac
1984 done 1994 done
1985 shift $((${OPTIND} - 1)) 1995 shift $((${OPTIND} - 1))
1986 [ $# -gt 0 ] || usage 1996 [ $# -gt 0 ] || usage
1987 1997
1988 if [ "$N_SRC_ARGS" -gt 1 ] && $DIRMODE; then 1998 if [ "$N_SRC_ARGS" -gt 1 ] && $DIRMODE; then
1989 err 2 "Multiple -s args are allowed only with tgz files" 1999 err 2 "Multiple -s args are allowed only with tgz files"
1990 fi 2000 fi
1991 if [ "$N_SRC_ARGS" -eq 0 ]; then 2001 if [ "$N_SRC_ARGS" -eq 0 ]; then
1992 # The default SRC_ARG was set elsewhere 2002 # The default SRC_ARG was set elsewhere
1993 DIRMODE=true 2003 DIRMODE=true
1994 SOURCEMODE=true 2004 SOURCEMODE=true
1995 SRC_ARGLIST="-s $(shell_quote "${SRC_ARG}")" 2005 SRC_ARGLIST="-s $(shell_quote "${SRC_ARG}")"
1996 fi 2006 fi
1997 2007
1998 # 2008 #
1999 # If '-s' arg or args specified tgz files, extract them 2009 # If '-s' arg or args specified tgz files, extract them
2000 # to a scratch directory. 2010 # to a scratch directory.
2001 # 2011 #
2002 if $TGZMODE; then 2012 if $TGZMODE; then
2003 ETCTGZDIR="${SCRATCHDIR}/etc.tgz" 2013 ETCTGZDIR="${SCRATCHDIR}/etc.tgz"
2004 echo "Note: Creating temporary directory ${ETCTGZDIR}" 2014 echo "Note: Creating temporary directory ${ETCTGZDIR}"
2005 if ! mkdir "${ETCTGZDIR}"; then 2015 if ! mkdir "${ETCTGZDIR}"; then
2006 err 2 "Can't create ${ETCTGZDIR}" 2016 err 2 "Can't create ${ETCTGZDIR}"
2007 fi 2017 fi
2008 ( # subshell to localise changes to "$@" 2018 ( # subshell to localise changes to "$@"
2009 eval "set -- ${TGZLIST}" 2019 eval "set -- ${TGZLIST}"
2010 for tgz in "$@"; do 2020 for tgz in "$@"; do
2011 echo "Note: Extracting files from ${tgz}" 2021 echo "Note: Extracting files from ${tgz}"
2012 cat "${tgz}" | ( 2022 cat "${tgz}" | (
2013 cd "${ETCTGZDIR}" && 2023 cd "${ETCTGZDIR}" &&
2014 tar -zxf - 2024 tar -zxf -
2015 ) || err 2 "Can't extract ${tgz}" 2025 ) || err 2 "Can't extract ${tgz}"
2016 done 2026 done
2017 ) 2027 )
2018 SRC_DIR="${ETCTGZDIR}" 2028 SRC_DIR="${ETCTGZDIR}"
2019 else 2029 else
2020 SRC_DIR="${SRC_ARG}" 2030 SRC_DIR="${SRC_ARG}"
2021 fi 2031 fi
2022 2032
2023 [ -d "${SRC_DIR}" ] || err 2 "${SRC_DIR} is not a directory" 2033 [ -d "${SRC_DIR}" ] || err 2 "${SRC_DIR} is not a directory"
2024 [ -d "${DEST_DIR}" ] || err 2 "${DEST_DIR} is not a directory" 2034 [ -d "${DEST_DIR}" ] || err 2 "${DEST_DIR} is not a directory"
2025 [ -n "${MACHINE}" ] || err 2 "\${MACHINE} is not defined" 2035 [ -n "${MACHINE}" ] || err 2 "\${MACHINE} is not defined"
2026 [ -n "${MACHINE_ARCH}" ] || err 2 "\${MACHINE_ARCH} is not defined" 2036 [ -n "${MACHINE_ARCH}" ] || err 2 "\${MACHINE_ARCH} is not defined"
2027 if ! $SOURCEMODE && ! [ -f "${SRC_DIR}/etc/mtree/set.etc" ]; then 2037 if ! $SOURCEMODE && ! [ -f "${SRC_DIR}/etc/mtree/set.etc" ]; then
2028 err 2 "Files from the etc.tgz set are missing" 2038 err 2 "Files from the etc.tgz set are missing"
2029 fi 2039 fi
2030 2040
2031 # If directories are /, clear them, so various messages 2041 # If directories are /, clear them, so various messages
2032 # don't have leading "//". However, this requires 2042 # don't have leading "//". However, this requires
2033 # the use of ${foo:-/} to display the variables. 2043 # the use of ${foo:-/} to display the variables.
2034 # 2044 #
2035 [ "${SRC_DIR}" = "/" ] && SRC_DIR="" 2045 [ "${SRC_DIR}" = "/" ] && SRC_DIR=""
2036 [ "${DEST_DIR}" = "/" ] && DEST_DIR="" 2046 [ "${DEST_DIR}" = "/" ] && DEST_DIR=""
2037 2047
2038 detect_x11 2048 detect_x11
2039 2049
2040 op="$1" 2050 op="$1"
2041 shift 2051 shift
2042 2052
2043 case "${op}" in 2053 case "${op}" in
2044 diff) 2054 diff)
2045 op=check 2055 op=check
2046 DIFF_STYLE=n # default style is RCS 2056 DIFF_STYLE=n # default style is RCS
2047 OPTIND=1 2057 OPTIND=1
2048 while getopts bcenpuw ch; do 2058 while getopts bcenpuw ch; do
2049 case "${ch}" in 2059 case "${ch}" in
2050 c|e|n|u) 2060 c|e|n|u)
2051 if [ "${DIFF_STYLE}" != "n" -a \ 2061 if [ "${DIFF_STYLE}" != "n" -a \
2052 "${DIFF_STYLE}" != "${ch}" ]; then 2062 "${DIFF_STYLE}" != "${ch}" ]; then
2053 err 2 "conflicting output style: ${ch}" 2063 err 2 "conflicting output style: ${ch}"
2054 fi 2064 fi
2055 DIFF_STYLE="${ch}" 2065 DIFF_STYLE="${ch}"
2056 ;; 2066 ;;
2057 b|p|w) 2067 b|p|w)
2058 DIFF_OPT="${DIFF_OPT} -${ch}" 2068 DIFF_OPT="${DIFF_OPT} -${ch}"
2059 ;; 2069 ;;
2060 *) 2070 *)
2061 err 2 "unknown diff option" 2071 err 2 "unknown diff option"
2062 ;; 2072 ;;
2063 esac 2073 esac
2064 done 2074 done
2065 shift $((${OPTIND} - 1)) 2075 shift $((${OPTIND} - 1))
2066 ;; 2076 ;;
2067 esac 2077 esac
2068 2078
2069 case "${op}" in 2079 case "${op}" in
2070 2080
2071 usage|help) 2081 usage|help)
2072 usage 2082 usage
2073 ;; 2083 ;;
2074 2084
2075 list) 2085 list)
2076 echo "Source directory: ${SRC_DIR:-/}" 2086 echo "Source directory: ${SRC_DIR:-/}"
2077 echo "Target directory: ${DEST_DIR:-/}" 2087 echo "Target directory: ${DEST_DIR:-/}"
2078 if $TGZMODE; then 2088 if $TGZMODE; then
2079 echo " (extracted from: ${SRC_ARG})" 2089 echo " (extracted from: ${SRC_ARG})"
2080 fi 2090 fi
2081 list 2091 list
2082 ;; 2092 ;;
2083 2093
2084 check|fix) 2094 check|fix)
2085 todo="$*" 2095 todo="$*"
2086 : ${todo:="${defaultitems}"} 2096 : ${todo:="${defaultitems}"}
2087 2097
2088 # ensure that all supplied items are valid 2098 # ensure that all supplied items are valid
2089 # 2099 #
2090 for i in ${todo}; do 2100 for i in ${todo}; do
2091 eval desc=\"\${desc_${i}}\" 2101 eval desc=\"\${desc_${i}}\"
2092 [ -n "${desc}" ] || err 2 "Unsupported ${op} '"${i}"'" 2102 [ -n "${desc}" ] || err 2 "Unsupported ${op} '"${i}"'"
2093 done 2103 done
2094 2104
2095 # perform each check/fix 2105 # perform each check/fix
2096 # 2106 #
2097 echo "Source directory: ${SRC_DIR:-/}" 2107 echo "Source directory: ${SRC_DIR:-/}"
2098 if $TGZMODE; then 2108 if $TGZMODE; then
2099 echo " (extracted from: ${SRC_ARG})" 2109 echo " (extracted from: ${SRC_ARG})"
2100 fi 2110 fi
2101 echo "Target directory: ${DEST_DIR:-/}" 2111 echo "Target directory: ${DEST_DIR:-/}"
2102 items_passed= 2112 items_passed=
2103 items_failed= 2113 items_failed=
2104 for i in ${todo}; do 2114 for i in ${todo}; do
2105 echo "${i} ${op}:" 2115 echo "${i} ${op}:"
2106 ( eval do_${i} ${op} ) 2116 ( eval do_${i} ${op} )
2107 if [ $? -eq 0 ]; then 2117 if [ $? -eq 0 ]; then
2108 items_passed="${items_passed} ${i}" 2118 items_passed="${items_passed} ${i}"
2109 else 2119 else
2110 items_failed="${items_failed} ${i}" 2120 items_failed="${items_failed} ${i}"
2111 fi 2121 fi
2112 done 2122 done
2113 2123
2114 if [ "${op}" = "check" ]; then 2124 if [ "${op}" = "check" ]; then
2115 plural="checks" 2125 plural="checks"
2116 else 2126 else
2117 plural="fixes" 2127 plural="fixes"
2118 fi 2128 fi
2119 2129
2120 echo "${PROGNAME} ${plural} passed:${items_passed}" 2130 echo "${PROGNAME} ${plural} passed:${items_passed}"
2121 echo "${PROGNAME} ${plural} failed:${items_failed}" 2131 echo "${PROGNAME} ${plural} failed:${items_failed}"
2122 if [ -n "${items_failed}" ]; then 2132 if [ -n "${items_failed}" ]; then
2123 exitstatus=1; 2133 exitstatus=1;
2124 if [ "${op}" = "check" ]; then 2134 if [ "${op}" = "check" ]; then
2125 [ "$MACHINE" = "$(uname -m)" ] && m= || m=" -m $MACHINE" 2135 [ "$MACHINE" = "$(uname -m)" ] && m= || m=" -m $MACHINE"
2126 cat <<_Fix_me_ 2136 cat <<_Fix_me_
2127To fix, run: 2137To fix, run:
2128 ${HOST_SH} ${0} ${SRC_ARGLIST} -d ${DEST_DIR:-/}$m fix${items_failed} 2138 ${HOST_SH} ${0} ${SRC_ARGLIST} -d ${DEST_DIR:-/}$m fix${items_failed}
2129Note that this may overwrite local changes. 2139Note that this may overwrite local changes.
2130_Fix_me_ 2140_Fix_me_
2131 fi 2141 fi
2132 fi 2142 fi
2133 2143
2134 ;; 2144 ;;
2135  2145
2136 *) 2146 *)
2137 warn "Unknown operation '"${op}"'" 2147 warn "Unknown operation '"${op}"'"
2138 usage 2148 usage
2139 ;; 2149 ;;
2140 2150
2141 esac 2151 esac
2142} 2152}
2143 2153
2144# defaults 2154# defaults
2145# 2155#
2146PROGNAME="${0##*/}" 2156PROGNAME="${0##*/}"
2147SRC_ARG="/usr/src" 2157SRC_ARG="/usr/src"
2148DEST_DIR="/" 2158DEST_DIR="/"
2149: ${MACHINE:="$( uname -m )"} # assume native build if $MACHINE is not set 2159: ${MACHINE:="$( uname -m )"} # assume native build if $MACHINE is not set
2150: ${MACHINE_ARCH:="$( uname -p )"}# assume native build if not set 2160: ${MACHINE_ARCH:="$( uname -p )"}# assume native build if not set
2151 2161
2152DIFF_STYLE= 2162DIFF_STYLE=
2153NOT_FIXED=" (FIX MANUALLY)" 2163NOT_FIXED=" (FIX MANUALLY)"
2154SCRATCHDIR="$( mkdtemp )" || err 2 "Can't create scratch directory" 2164SCRATCHDIR="$( mkdtemp )" || err 2 "Can't create scratch directory"
2155trap "/bin/rm -rf \"\${SCRATCHDIR}\" ; exit 0" 1 2 3 15 # HUP INT QUIT TERM 2165trap "/bin/rm -rf \"\${SCRATCHDIR}\" ; exit 0" 1 2 3 15 # HUP INT QUIT TERM
2156 2166
2157umask 022 2167umask 022
2158exec 3>/dev/null 2168exec 3>/dev/null
2159exec 4>/dev/null 2169exec 4>/dev/null
2160exitstatus=0 2170exitstatus=0
2161 2171
2162main "$@" 2172main "$@"
2163/bin/rm -rf "${SCRATCHDIR}" 2173/bin/rm -rf "${SCRATCHDIR}"
2164exit $exitstatus 2174exit $exitstatus