postinstall.in revision 1.27 1 #!/bin/sh
2 #
3 # $NetBSD: postinstall.in,v 1.27 2020/06/15 21:56:49 christos Exp $
4 #
5 # Copyright (c) 2002-2015 The NetBSD Foundation, Inc.
6 # All rights reserved.
7 #
8 # This code is derived from software contributed to The NetBSD Foundation
9 # by Luke Mewburn.
10 #
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
13 # are met:
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
19 #
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
22 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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
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
30 # POSSIBILITY OF SUCH DAMAGE.
31 #
32 # postinstall
33 # Check for or fix configuration changes that occur
34 # over time as NetBSD evolves.
35 #
36
37 #
38 # XXX BE SURE TO USE ${DEST_DIR} PREFIX BEFORE ALL REAL FILE OPERATIONS XXX
39 #
40
41 #
42 # checks to add:
43 # - sysctl(8) renames (net.inet6.ip6.bindv6only -> net.inet6.ip6.v6only)
44 # - de* -> tlp* migration (/etc/ifconfig.de*, $ifconfig_de*, ...) ?
45 # - support quiet/verbose mode ?
46 # - differentiate between failures caused by missing source
47 # and real failures
48 # - install moduli into usr/share/examples/ssh and use from there?
49 # - differentiate between "needs fix" versus "can't fix" issues
50 #
51
52 # This script is executed as part of a cross build. Allow the build
53 # environment to override the locations of some tools.
54 : ${AWK:=awk}
55 : ${DB:=db}
56 : ${GREP:=grep}
57 : ${HOST_SH:=sh}
58 : ${MAKE:=make}
59 : ${PWD_MKDB:=/usr/sbin/pwd_mkdb}
60 : ${SED:=sed}
61 : ${SORT:=sort}
62 : ${STAT:=stat}
63
64 #
65 # helper functions
66 #
67
68 err()
69 {
70 exitval=$1
71 shift
72 echo 1>&2 "${PROGNAME}: $*"
73 if [ -n "${SCRATCHDIR}" ]; then
74 /bin/rm -rf "${SCRATCHDIR}"
75 fi
76 exit ${exitval}
77 }
78
79 warn()
80 {
81 echo 1>&2 "${PROGNAME}: $*"
82 }
83
84 msg()
85 {
86 echo " $*"
87 }
88
89 mkdtemp()
90 {
91 # Make sure we don't loop forever if mkdir will always fail.
92 [ -d /tmp ] || err 2 /tmp is not a directory
93 [ -w /tmp ] || err 2 /tmp is not writable
94
95 _base="/tmp/_postinstall.$$"
96 _serial=0
97
98 while true; do
99 _dir="${_base}.${_serial}"
100 mkdir -m 0700 "${_dir}" && break
101 _serial=$((${_serial} + 1))
102 done
103 echo "${_dir}"
104 }
105
106 # Quote args to make them safe in the shell.
107 # Usage: quotedlist="$(shell_quote args...)"
108 #
109 # After building up a quoted list, use it by evaling it inside
110 # double quotes, like this:
111 # eval "set -- $quotedlist"
112 # or like this:
113 # eval "\$command $quotedlist \$filename"
114 #
115 shell_quote()
116 {(
117 local result=''
118 local arg qarg
119 LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
120 for arg in "$@" ; do
121 case "${arg}" in
122 '')
123 qarg="''"
124 ;;
125 *[!-./a-zA-Z0-9]*)
126 # Convert each embedded ' to '\'',
127 # then insert ' at the beginning of the first line,
128 # and append ' at the end of the last line.
129 # Finally, elide unnecessary '' pairs at the
130 # beginning and end of the result and as part of
131 # '\'''\'' sequences that result from multiple
132 # adjacent quotes in he input.
133 qarg="$(printf "%s\n" "$arg" | \
134 ${SED:-sed} -e "s/'/'\\\\''/g" \
135 -e "1s/^/'/" -e "\$s/\$/'/" \
136 -e "1s/^''//" -e "\$s/''\$//" \
137 -e "s/'''/'/g"
138 )"
139 ;;
140 *)
141 # Arg is not the empty string, and does not contain
142 # any unsafe characters. Leave it unchanged for
143 # readability.
144 qarg="${arg}"
145 ;;
146 esac
147 result="${result}${result:+ }${qarg}"
148 done
149 printf "%s\n" "$result"
150 )}
151
152 # Convert arg $1 to a basic regular expression (as in sed)
153 # that will match the arg. This works by inserting backslashes
154 # before characters that are special in basic regular expressions.
155 # It also inserts backslashes before the extra characters specified
156 # in $2 (which defaults to "/,").
157 # XXX: Does not handle embedded newlines.
158 # Usage: regex="$(bre_quote "${string}")"
159 bre_quote()
160 {
161 local arg="$1"
162 local extra="${2-/,}"
163 printf "%s\n" "${arg}" | ${SED} -e 's/[][^$.*\\'"${extra}"']/\\&/g'
164 }
165
166 # unprefix dir
167 # Remove any dir prefix from a list of paths on stdin,
168 # and write the result to stdout. Useful for converting
169 # from ${DEST_DIR}/path to /path.
170 #
171 unprefix()
172 {
173 [ $# -eq 1 ] || err 3 "USAGE: unprefix dir"
174 local prefix="${1%/}"
175 prefix="$(bre_quote "${prefix}")"
176
177 ${SED} -e "s,^${prefix}/,/,"
178 }
179
180 # additem item description
181 # Add item to list of supported items to check/fix,
182 # which are checked/fixed by default if no item is requested by user.
183 #
184 additem()
185 {
186 [ $# -eq 2 ] || err 3 "USAGE: additem item description"
187 defaultitems="${defaultitems}${defaultitems:+ }$1"
188 eval desc_$1=\"\$2\"
189 }
190
191 # adddisableditem item description
192 # Add item to list of supported items to check/fix,
193 # but execute the item only if the user asks for it explicitly.
194 #
195 adddisableditem()
196 {
197 [ $# -eq 2 ] || err 3 "USAGE: adddisableditem item description"
198 otheritems="${otheritems}${otheritems:+ }$1"
199 eval desc_$1=\"\$2\"
200 }
201
202 # checkdir op dir mode
203 # Ensure dir exists, and if not, create it with the appropriate mode.
204 # Returns 0 if ok, 1 otherwise.
205 #
206 check_dir()
207 {
208 [ $# -eq 3 ] || err 3 "USAGE: check_dir op dir mode"
209 _cdop="$1"
210 _cddir="$2"
211 _cdmode="$3"
212 [ -d "${_cddir}" ] && return 0
213 if [ "${_cdop}" = "check" ]; then
214 msg "${_cddir} is not a directory"
215 return 1
216 elif ! mkdir -m "${_cdmode}" "${_cddir}" ; then
217 msg "Can't create missing ${_cddir}"
218 return 1
219 else
220 msg "Missing ${_cddir} created"
221 fi
222 return 0
223 }
224
225 # check_ids op type file srcfile start id [...]
226 # Check if file of type "users" or "groups" contains the relevant IDs.
227 # Use srcfile as a reference for the expected contents.
228 # The specified "id" names should be given in numerical order,
229 # with the first name corresponding to numerical value "start",
230 # and with the special name "SKIP" being used to mark gaps in the
231 # sequence.
232 # Returns 0 if ok, 1 otherwise.
233 #
234 check_ids()
235 {
236 [ $# -ge 6 ] || err 3 "USAGE: checks_ids op type file start srcfile id [...]"
237 _op="$1"
238 _type="$2"
239 _file="$3"
240 _srcfile="$4"
241 _start="$5"
242 shift 5
243 #_ids="$@"
244
245 if [ ! -f "${_file}" ]; then
246 msg "${_file} doesn't exist; can't check for missing ${_type}"
247 return 1
248 fi
249 if [ ! -r "${_file}" ]; then
250 msg "${_file} is not readable; can't check for missing ${_type}"
251 return 1
252 fi
253 _notfixed=""
254 if [ "${_op}" = "fix" ]; then
255 _notfixed="${NOT_FIXED}"
256 fi
257 _missing="$(${AWK} -v start=$_start -F: '
258 BEGIN {
259 for (x = 1; x < ARGC; x++) {
260 if (ARGV[x] == "SKIP")
261 continue;
262 idlist[ARGV[x]]++;
263 value[ARGV[x]] = start + x - 1;
264 }
265 ARGC=1
266 }
267 {
268 found[$1]++
269 number[$1] = $3
270 }
271 END {
272 for (id in idlist) {
273 if (!(id in found))
274 printf("%s (missing)\n", id)
275 else if (number[id] != value[id])
276 printf("%s (%d != %d)\n", id,
277 number[id], value[id])
278 start++;
279 }
280 }
281 ' "$@" < "${_file}")" || return 1
282 if [ -n "${_missing}" ]; then
283 msg "Error ${_type}${_notfixed}:" $(echo ${_missing})
284 msg "Use the following as a template:"
285 set -- ${_missing}
286 while [ $# -gt 0 ]
287 do
288 ${GREP} -E "^${1}:" ${_srcfile}
289 shift 2
290 done
291 msg "and adjust if necessary."
292 return 1
293 fi
294 return 0
295 }
296
297 # populate_dir op onlynew src dest mode file [file ...]
298 # Perform op ("check" or "fix") on files in src/ against dest/
299 # If op = "check" display missing or changed files, optionally with diffs.
300 # If op != "check" copies any missing or changed files.
301 # If onlynew evaluates to true, changed files are ignored.
302 # Returns 0 if ok, 1 otherwise.
303 #
304 populate_dir()
305 {
306 [ $# -ge 5 ] || err 3 "USAGE: populate_dir op onlynew src dest mode file [...]"
307 _op="$1"
308 _onlynew="$2"
309 _src="$3"
310 _dest="$4"
311 _mode="$5"
312 shift 5
313 #_files="$@"
314
315 if [ ! -d "${_src}" ]; then
316 msg "${_src} is not a directory; skipping check"
317 return 1
318 fi
319 check_dir "${_op}" "${_dest}" 755 || return 1
320
321 _cmpdir_rv=0
322 for f in "$@"; do
323 fs="${_src}/${f}"
324 fd="${_dest}/${f}"
325 _error=""
326 if [ ! -f "${fd}" ]; then
327 _error="${fd} does not exist"
328 elif ! cmp -s "${fs}" "${fd}" ; then
329 if $_onlynew; then # leave existing ${fd} alone
330 continue;
331 fi
332 _error="${fs} != ${fd}"
333 else
334 continue
335 fi
336 if [ "${_op}" = "check" ]; then
337 msg "${_error}"
338 if [ -n "${DIFF_STYLE}" -a -f "${fd}" ]; then
339 diff -${DIFF_STYLE} ${DIFF_OPT} "${fd}" "${fs}"
340 fi
341 _cmpdir_rv=1
342 elif ! rm -f "${fd}" ||
343 ! cp -f "${fs}" "${fd}"; then
344 msg "Can't copy ${fs} to ${fd}"
345 _cmpdir_rv=1
346 elif ! chmod "${_mode}" "${fd}"; then
347 msg "Can't change mode of ${fd} to ${_mode}"
348 _cmpdir_rv=1
349 else
350 msg "Copied ${fs} to ${fd}"
351 fi
352 done
353 return ${_cmpdir_rv}
354 }
355
356 # compare_dir op src dest mode file [file ...]
357 # Perform op ("check" or "fix") on files in src/ against dest/
358 # If op = "check" display missing or changed files, optionally with diffs.
359 # If op != "check" copies any missing or changed files.
360 # Returns 0 if ok, 1 otherwise.
361 #
362 compare_dir()
363 {
364 [ $# -ge 4 ] || err 3 "USAGE: compare_dir op src dest mode file [...]"
365 _op="$1"
366 _src="$2"
367 _dest="$3"
368 _mode="$4"
369 shift 4
370 #_files="$@"
371
372 populate_dir "$_op" false "$_src" "$_dest" "$_mode" "$@"
373 }
374
375 # move_file op src dest --
376 # Check (op == "check") or move (op != "check") from src to dest.
377 # Returns 0 if ok, 1 otherwise.
378 #
379 move_file()
380 {
381 [ $# -eq 3 ] || err 3 "USAGE: move_file op src dest"
382 _fm_op="$1"
383 _fm_src="$2"
384 _fm_dest="$3"
385
386 if [ -f "${_fm_src}" -a ! -f "${_fm_dest}" ]; then
387 if [ "${_fm_op}" = "check" ]; then
388 msg "Move ${_fm_src} to ${_fm_dest}"
389 return 1
390 fi
391 if ! mv "${_fm_src}" "${_fm_dest}"; then
392 msg "Can't move ${_fm_src} to ${_fm_dest}"
393 return 1
394 fi
395 msg "Moved ${_fm_src} to ${_fm_dest}"
396 fi
397 return 0
398 }
399
400 # rcconf_is_set op name var [verbose] --
401 # Load the rcconf for name, and check if obsolete rc.conf(5) variable
402 # var is defined or not.
403 # Returns 0 if defined (even to ""), otherwise 1.
404 # If verbose != "", print an obsolete warning if the var is defined.
405 #
406 rcconf_is_set()
407 {
408 [ $# -ge 3 ] || err 3 "USAGE: rcconf_is_set op name var [verbose]"
409 _rcis_op="$1"
410 _rcis_name="$2"
411 _rcis_var="$3"
412 _rcis_verbose="$4"
413 _rcis_notfixed=""
414 if [ "${_rcis_op}" = "fix" ]; then
415 _rcis_notfixed="${NOT_FIXED}"
416 fi
417 (
418 for f in \
419 "${DEST_DIR}/etc/rc.conf" \
420 "${DEST_DIR}/etc/rc.conf.d/${_rcis_name}"; do
421 [ -f "${f}" ] && . "${f}"
422 done
423 eval echo -n \"\${${_rcis_var}}\" 1>&3
424 if eval "[ -n \"\${${_rcis_var}}\" \
425 -o \"\${${_rcis_var}-UNSET}\" != \"UNSET\" ]"; then
426 if [ -n "${_rcis_verbose}" ]; then
427 msg \
428 "Obsolete rc.conf(5) variable '\$${_rcis_var}' found.${_rcis_notfixed}"
429 fi
430 exit 0
431 else
432 exit 1
433 fi
434 )
435 }
436
437 # rcvar_is_enabled var
438 # Check if rcvar is enabled
439 #
440 rcvar_is_enabled()
441 {
442 [ $# -eq 1 ] || err 3 "USAGE: rcvar_is_enabled var"
443 _rcie_var="$1"
444 (
445 [ -f "${DEST_DIR}/etc/rc.conf" ] && . "${DEST_DIR}/etc/rc.conf"
446 eval _rcie_val=\"\${${_rcie_var}}\"
447 case $_rcie_val in
448 # "yes", "true", "on", or "1"
449 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
450 exit 0
451 ;;
452
453 *)
454 exit 1
455 ;;
456 esac
457 )
458 }
459
460 # find_file_in_dirlist() file message dir1 [...] --
461 # Find which directory file is in, and sets ${dir} to match.
462 # Returns 0 if matched, otherwise 1 (and sets ${dir} to "").
463 #
464 # Generally, check the directory for the "checking from source" case,
465 # and then the directory for the "checking from extracted etc.tgz" case.
466 #
467 find_file_in_dirlist()
468 {
469 [ $# -ge 3 ] || err 3 "USAGE: find_file_in_dirlist file msg dir1 [...]"
470
471 _file="$1" ; shift
472 _msg="$1" ; shift
473 _dir1st= # first dir in list
474 for dir in "$@"; do
475 : ${_dir1st:="${dir}"}
476 if [ -f "${dir}/${_file}" ]; then
477 if [ "${_dir1st}" != "${dir}" ]; then
478 msg \
479 "(Checking for ${_msg} from ${dir} instead of ${_dir1st})"
480 fi
481 return 0
482 fi
483 done
484 msg "Can't find source directory for ${_msg}"
485 return 1
486 }
487
488 # file_exists_exact path
489 # Returns true if a file exists in the ${DEST_DIR} whose name
490 # is exactly ${path}, interpreted in a case-sensitive way
491 # even if the underlying file system is case-insensitive.
492 #
493 # The path must begin with '/' or './', and is interpreted as
494 # being relative to ${DEST_DIR}.
495 #
496 file_exists_exact()
497 {
498 [ -n "$1" ] || err 3 "USAGE: file_exists_exact path"
499 _path="${1#.}"
500 [ -h "${DEST_DIR}${_path}" ] || \
501 [ -e "${DEST_DIR}${_path}" ] || return 1
502 while [ "${_path}" != "/" -a "${_path}" != "." ] ; do
503 _dirname="$(dirname "${_path}" 2>/dev/null)"
504 _basename="$(basename "${_path}" 2>/dev/null)"
505 ls -fa "${DEST_DIR}${_dirname}" 2> /dev/null \
506 | ${GREP} -F -x "${_basename}" >/dev/null \
507 || return 1
508 _path="${_dirname}"
509 done
510 return 0
511 }
512
513 # obsolete_paths op
514 # Obsolete the list of paths provided on stdin.
515 # Each path should start with '/' or './', and
516 # will be interpreted relative to ${DEST_DIR}.
517 #
518 obsolete_paths()
519 {
520 [ -n "$1" ] || err 3 "USAGE: obsolete_paths fix|check"
521 op="$1"
522
523 failed=0
524 while read ofile; do
525 if ! ${file_exists_exact} "${ofile}"; then
526 continue
527 fi
528 ofile="${DEST_DIR}${ofile#.}"
529 cmd="rm"
530 ftype="file"
531 if [ -h "${ofile}" ]; then
532 ftype="link"
533 elif [ -d "${ofile}" ]; then
534 ftype="directory"
535 cmd="rmdir"
536 elif [ ! -e "${ofile}" ]; then
537 continue
538 fi
539 if [ "${op}" = "check" ]; then
540 msg "Remove obsolete ${ftype} ${ofile}"
541 failed=1
542 elif ! eval "${cmd} \"\${ofile}\""; then
543 msg "Can't remove obsolete ${ftype} ${ofile}"
544 failed=1
545 else
546 msg "Removed obsolete ${ftype} ${ofile}"
547 fi
548 done
549 return ${failed}
550 }
551
552 # obsolete_libs dir
553 # Display the minor/teeny shared libraries in dir that are considered
554 # to be obsolete.
555 #
556 # The implementation supports removing obsolete major libraries
557 # if the awk variable AllLibs is set, although there is no way to
558 # enable that in the enclosing shell function as this time.
559 #
560 obsolete_libs()
561 {
562 [ $# -eq 1 ] || err 3 "USAGE: obsolete_libs dir"
563 dir="$1"
564
565 _obsolete_libs "${dir}"
566 _obsolete_libs "/usr/libdata/debug/${dir}"
567 }
568
569 exclude()
570 {
571 local dollar
572 case "$1" in
573 -t)
574 dollar='$'
575 shift
576 ;;
577 *)
578 dollar=
579 ;;
580 esac
581 if [ -z "$*" ]; then
582 cat
583 else
584 eval ${GREP} -v -E "'(^$(echo $* | \
585 ${SED} -e s/\\./\\\\./g -e 's/ /'${dollar}'|^/'g)${dollar})'"
586 fi
587 }
588
589 #
590 # find all the target symlinks of shared libaries and exclude them
591 # from consideration for removal
592 #
593 exclude_libs() {
594 local target="$(ls -l -d lib*.so.* 2> /dev/null \
595 | ${AWK} '{ print $11; }' \
596 | ${SED} -e 's@.*/@@' | ${SORT} -u)"
597 exclude -t ${target}
598 }
599
600 _obsolete_libs()
601 {
602 dir="$1"
603
604 (
605
606 if [ ! -e "${DEST_DIR}/${dir}" ]
607 then
608 return 0
609 fi
610
611 cd "${DEST_DIR}/${dir}" || err 2 "can't cd to ${DEST_DIR}/${dir}"
612 echo lib*.so.* \
613 | tr ' ' '\n' \
614 | ${AWK} -v LibDir="${dir}/" '
615 #{
616
617 function digit(v, c, n) { return (n <= c) ? v[n] : 0 }
618
619 function checklib(results, line, regex) {
620 if (! match(line, regex))
621 return
622 lib = substr(line, RSTART, RLENGTH)
623 rev = substr($0, RLENGTH+1)
624 if (! (lib in results)) {
625 results[lib] = rev
626 return
627 }
628 orevc = split(results[lib], orev, ".")
629 nrevc = split(rev, nrev, ".")
630 maxc = (orevc > nrevc) ? orevc : nrevc
631 for (i = 1; i <= maxc; i++) {
632 res = digit(orev, orevc, i) - digit(nrev, nrevc, i)
633 if (res < 0) {
634 print LibDir lib results[lib]
635 results[lib] = rev
636 return
637 } else if (res > 0) {
638 print LibDir lib rev
639 return
640 }
641 }
642 }
643
644 /^lib.*\.so\.[0-9]+\.[0-9]+(\.[0-9]+)?(\.debug)?$/ {
645 if (AllLibs)
646 checklib(minor, $0, "^lib.*\\.so\\.")
647 else
648 checklib(found, $0, "^lib.*\\.so\\.[0-9]+\\.")
649 }
650
651 /^lib.*\.so\.[0-9]+$/ {
652 if (AllLibs)
653 checklib(major, $0, "^lib.*\\.so\\.")
654 }
655
656 #}' | exclude_libs
657
658 )
659 }
660
661 # obsolete_stand dir
662 # Prints the names of all obsolete files and subdirs below the
663 # provided dir. dir should be something like /stand/${MACHINE}.
664 # The input dir and all output paths are interpreted
665 # relative to ${DEST_DIR}.
666 #
667 # Assumes that the numerically largest subdir is current, and all
668 # others are obsolete.
669 #
670 obsolete_stand()
671 {
672 [ $# -eq 1 ] || err 3 "USAGE: obsolete_stand dir"
673 local dir="$1"
674 local subdir
675
676 if ! [ -d "${DEST_DIR}${dir}" ]; then
677 msg "${DEST_DIR}${dir} doesn't exist; can't check for obsolete files"
678 return 1
679 fi
680
681 ( cd "${DEST_DIR}${dir}" && ls -1d [0-9]*[0-9]/. ) \
682 | ${GREP} -v '[^0-9./]' \
683 | sort -t. -r -n -k1,1 -k2,2 -k3,3 \
684 | tail -n +2 \
685 | while read subdir ; do
686 subdir="${subdir%/.}"
687 find "${DEST_DIR}${dir}/${subdir}" -depth -print
688 done \
689 | unprefix "${DEST_DIR}"
690 }
691
692 # modify_file op srcfile scratchfile awkprog
693 # Apply awkprog to srcfile sending output to scratchfile, and
694 # if appropriate replace srcfile with scratchfile.
695 #
696 modify_file()
697 {
698 [ $# -eq 4 ] || err 3 "USAGE: modify_file op file scratch awkprog"
699
700 _mfop="$1"
701 _mffile="$2"
702 _mfscratch="$3"
703 _mfprog="$4"
704 _mffailed=0
705
706 ${AWK} "${_mfprog}" < "${_mffile}" > "${_mfscratch}"
707 if ! cmp -s "${_mffile}" "${_mfscratch}"; then
708 diff "${_mffile}" "${_mfscratch}" > "${_mfscratch}.diffs"
709 if [ "${_mfop}" = "check" ]; then
710 msg "${_mffile} needs the following changes:"
711 _mffailed=1
712 elif ! rm -f "${_mffile}" ||
713 ! cp -f "${_mfscratch}" "${_mffile}"; then
714 msg "${_mffile} changes not applied:"
715 _mffailed=1
716 else
717 msg "${_mffile} changes applied:"
718 fi
719 while read _line; do
720 msg " ${_line}"
721 done < "${_mfscratch}.diffs"
722 fi
723 return ${_mffailed}
724 }
725
726
727 # contents_owner op directory user group
728 # Make sure directory and contents are owned (and group-owned)
729 # as specified.
730 #
731 contents_owner()
732 {
733 [ $# -eq 4 ] || err 3 "USAGE: contents_owner op dir user group"
734
735 _op="$1"
736 _dir="$2"
737 _user="$3"
738 _grp="$4"
739
740 if [ "${_op}" = "check" ]; then
741 _files=$(find "${_dir}" \( \( ! -user "${_user}" \) -o \
742 \( ! -group "${_grp}" \) \) )
743 _error=$?
744 if [ ! -z "$_files" ] || [ $_error != 0 ]; then
745 msg "${_dir} and contents not all owned by" \
746 "${_user}:${_grp}"
747 return 1
748 else
749 return 0
750 fi
751 elif [ "${_op}" = "fix" ]; then
752 find "${_dir}" \( \( ! -user "${_user}" \) -o \
753 \( ! -group "${_grp}" \) \) \
754 -exec chown "${_user}:${_grp}" -- {} \;
755 fi
756 }
757
758 # get_makevar var [var ...]
759 # Retrieve the value of a user-settable system make variable
760 get_makevar()
761 {
762 $SOURCEMODE || err 3 "get_makevar must be used in source mode"
763 [ $# -eq 0 ] && err 3 "USAGE: get_makevar var [var ...]"
764
765 for _var in "$@"; do
766 _value="$(echo '.include <bsd.own.mk>' | \
767 ${MAKE} -f - -V "\${${_var}}")"
768
769 eval ${_var}=\"\${_value}\"
770 done
771 }
772
773 # detect_x11
774 # Detect if X11 components should be analysed and set values of
775 # relevant variables.
776 detect_x11()
777 {
778 if $SOURCEMODE; then
779 get_makevar MKX11 X11ROOTDIR X11SRCDIR
780 else
781 if [ -f "${SRC_DIR}/etc/mtree/set.xetc" ]; then
782 MKX11=yes
783 X11ROOTDIR=/this/value/isnt/used/yet
784 else
785 MKX11=no
786 X11ROOTDIR=
787 fi
788 X11SRCDIR=/nonexistent/xsrc
789 fi
790 }
791
792 #
793 # find out where MAKEDEV lives, set MAKEDEV_DIR appropriately
794 #
795 find_makedev()
796 {
797 if [ -e "${DEST_DIR}/dev/MAKEDEV" ]; then
798 MAKEDEV_DIR="${DEST_DIR}/dev"
799 elif [ -e "${DEST_DIR}/etc/MAKEDEV" ]; then
800 MAKEDEV_DIR="${DEST_DIR}/etc"
801 else
802 MAKEDEV_DIR="${DEST_DIR}/dev"
803 fi
804 }
805
806
807 #
808 # items
809 # -----
810 #
811
812 #
813 # Bluetooth
814 #
815
816 additem bluetooth "Bluetooth configuration is up to date"
817 do_bluetooth()
818 {
819 [ -n "$1" ] || err 3 "USAGE: do_bluetooth fix|check"
820 op="$1"
821 failed=0
822
823 populate_dir "${op}" true \
824 "${SRC_DIR}/etc/bluetooth" "${DEST_DIR}/etc/bluetooth" 644 \
825 hosts protocols btattach.conf btdevctl.conf
826 failed=$(( ${failed} + $? ))
827
828 move_file "${op}" "${DEST_DIR}/var/db/btdev.xml" \
829 "${DEST_DIR}/var/db/btdevctl.plist"
830 failed=$(( ${failed} + $? ))
831
832 notfixed=""
833 if [ "${op}" = "fix" ]; then
834 notfixed="${NOT_FIXED}"
835 fi
836 for _v in btattach btconfig btdevctl; do
837 if rcvar_is_enabled "${_v}"; then
838 msg \
839 "${_v} is obsolete in rc.conf(5)${notfixed}: use bluetooth=YES"
840 failed=$(( ${failed} + 1 ))
841 fi
842 done
843
844 return ${failed}
845 }
846
847 fixblock() {
848 for i; do
849 if [ ! -f "$i" ]; then
850 continue
851 fi
852 local p=$(stat -f %Lp "$i")
853 chmod u+w "$i"
854 sed -i -e 's/\([bB]\)lack/\1lock/g' "$i"
855 chmod "$p" "$i"
856 done
857 }
858
859 #
860 # blocklist update
861 #
862 additem blocklist "rename old files to blocklist"
863 do_blocklist()
864 {
865 local rcfiles="/etc/rc.conf /etc/npf.conf /etc/defaults/rc.conf"
866
867 # if we are actually using blocklistd
868 if [ -f /var/db/blacklist.db ]; then
869 mv /var/db/blacklist.db /var/db/blocklist.db
870 fi
871 if [ -f /etc/blacklistd.conf ]; then
872 mv /etc/blacklistd.conf /etc/blocklistd.conf
873 fixblock /etc/blocklistd.conf
874 fi
875
876 # if we have fixed the rc files we are done
877 if ! grep -qs $rcfiles; then
878 return
879 fi
880
881 fixblock $rcfiles
882 }
883
884 #
885 # ddbonpanic
886 #
887 additem ddbonpanic "verify ddb.onpanic is configured in sysctl.conf"
888 do_ddbonpanic()
889 {
890 [ -n "$1" ] || err 3 "USAGE: do_ddbonpanic fix|check"
891
892 if ${GREP} -E '^#*[[:space:]]*ddb\.onpanic[[:space:]]*\??=[[:space:]]*[[:digit:]]+' \
893 "${DEST_DIR}/etc/sysctl.conf" >/dev/null 2>&1
894 then
895 result=0
896 else
897 if [ "$1" = check ]; then
898 msg \
899 "The ddb.onpanic behaviour is not explicitly specified in /etc/sysctl.conf"
900 result=1
901 else
902 echo >> "${DEST_DIR}/etc/sysctl.conf"
903 ${SED} < "${SRC_DIR}/etc/sysctl.conf" \
904 -e '/^ddb\.onpanic/q' | \
905 ${SED} -e '1,/^$/d' >> \
906 "${DEST_DIR}/etc/sysctl.conf"
907 result=$?
908 fi
909 fi
910 return ${result}
911 }
912
913 #
914 # defaults
915 #
916 additem defaults "/etc/defaults/ being up to date"
917 do_defaults()
918 {
919 [ -n "$1" ] || err 3 "USAGE: do_defaults fix|check"
920 local op="$1"
921 local failed=0
922 local etcsets=$(getetcsets)
923
924 local rc_exclude_scripts=""
925 if $SOURCEMODE; then
926 # For most architectures rc.conf(5) should be the same as the
927 # one obtained from a source directory, except for the ones
928 # that have an append file for it.
929 local rc_conf_app="${SRC_DIR}/etc/etc.${MACHINE}/rc.conf.append"
930 if [ -f "${rc_conf_app}" ]; then
931 rc_exclude_scripts="rc.conf"
932
933 # Generate and compare the correct rc.conf(5) file
934 mkdir "${SCRATCHDIR}/defaults"
935
936 cat "${SRC_DIR}/etc/defaults/rc.conf" "${rc_conf_app}" \
937 > "${SCRATCHDIR}/defaults/rc.conf"
938
939 compare_dir "${op}" "${SCRATCHDIR}/defaults" \
940 "${DEST_DIR}/etc/defaults" \
941 444 \
942 "rc.conf"
943 failed=$(( ${failed} + $? ))
944 fi
945 fi
946
947 find_file_in_dirlist pf.boot.conf "pf.boot.conf" \
948 "${SRC_DIR}/usr.sbin/pf/etc/defaults" "${SRC_DIR}/etc/defaults" \
949 || return 1
950 # ${dir} is set by find_file_in_dirlist()
951 compare_dir "$op" "${dir}" "${DEST_DIR}/etc/defaults" 444 pf.boot.conf
952 failed=$(( ${failed} + $? ))
953
954 rc_exclude_scripts="${rc_exclude_scripts} pf.boot.conf"
955
956 local rc_default_conf_files="$(select_set_files /etc/defaults/ \
957 "/etc/defaults/\([^[:space:]]*\.conf\)" ${etcsets} | \
958 exclude ${rc_exclude_scripts})"
959 compare_dir "$op" "${SRC_DIR}/etc/defaults" "${DEST_DIR}/etc/defaults" \
960 444 \
961 ${rc_default_conf_files}
962 failed=$(( ${failed} + $? ))
963
964
965 return ${failed}
966 }
967
968 #
969 # dhcpcd
970 #
971 additem dhcpcd "dhcpcd configuration is up to date"
972 do_dhcpcd()
973 {
974 [ -n "$1" ] || err 3 "USAGE: do_dhcpcd fix|check"
975 op="$1"
976 failed=0
977
978 find_file_in_dirlist dhcpcd.conf "dhcpcd.conf" \
979 "${SRC_DIR}/external/bsd/dhcpcd/dist/src" \
980 "${SRC_DIR}/etc" || return 1
981 # ${dir} is set by find_file_in_dirlist()
982 populate_dir "$op" true "${dir}" "${DEST_DIR}/etc" 644 dhcpcd.conf
983 failed=$(( ${failed} + $? ))
984
985 check_dir "${op}" "${DEST_DIR}/var/db/dhcpcd" 755
986 failed=$(( ${failed} + $? ))
987
988 move_file "${op}" \
989 "${DEST_DIR}/etc/dhcpcd.duid" \
990 "${DEST_DIR}/var/db/dhcpcd/duid"
991 failed=$(( ${failed} + $? ))
992
993 move_file "${op}" \
994 "${DEST_DIR}/etc/dhcpcd.secret" \
995 "${DEST_DIR}/var/db/dhcpcd/secret"
996 failed=$(( ${failed} + $? ))
997
998 move_file "${op}" \
999 "${DEST_DIR}/var/db/dhcpcd-rdm.monotonic" \
1000 "${DEST_DIR}/var/db/dhcpcd/rdm_monotonic"
1001 failed=$(( ${failed} + $? ))
1002
1003 for lease in "${DEST_DIR}/var/db/dhcpcd-"*.lease*; do
1004 [ -f "${lease}" ] || continue
1005 new_lease=$(basename "${lease}" | ${SED} -e 's/dhcpcd-//')
1006 new_lease="${DEST_DIR}/var/db/dhcpcd/${new_lease}"
1007 move_file "${op}" "${lease}" "${new_lease}"
1008 failed=$(( ${failed} + $? ))
1009 done
1010
1011 chroot_dir="${DEST_DIR}/var/chroot/dhcpcd"
1012 move_file "${op}" \
1013 "${chroot_dir}/var/db/dhcpcd/duid" \
1014 "${DEST_DIR}/var/db/dhcpcd/duid"
1015 failed=$(( ${failed} + $? ))
1016
1017 move_file "${op}" \
1018 "${chroot_dir}/var/db/dhcpcd/secret" \
1019 "${DEST_DIR}/var/db/dhcpcd/secret"
1020 failed=$(( ${failed} + $? ))
1021
1022 move_file "${op}" \
1023 "${chroot_dir}/var/db/dhcpcd/rdm_monotonic" \
1024 "${DEST_DIR}/var/db/dhcpcd/rdm_monotonic"
1025 failed=$(( ${failed} + $? ))
1026
1027 for lease in "${chroot_dir}/var/db/dhcpcd/"*.lease*; do
1028 [ -f "${lease}" ] || continue
1029 new_lease="${DEST_DIR}/var/db/dhcpcd/$(basename ${lease})"
1030 move_file "${op}" "${lease}" "${new_lease}"
1031 failed=$(( ${failed} + $? ))
1032 done
1033
1034 # Ensure chroot is now empty
1035 for dir in \
1036 $(find ${chroot_dir} ! -type d) \
1037 $(find ${chroot_dir} -type d -mindepth 1 | sort -r)
1038 do
1039 echo "/var/chroot/dhcpcd${dir##${chroot_dir}}"
1040 done | obsolete_paths "${op}"
1041 failed=$(( ${failed} + $? ))
1042
1043 contents_owner "${op}" "${DEST_DIR}/var/db/dhcpcd" root wheel
1044 failed=$(( ${failed} + $? ))
1045
1046 return ${failed}
1047 }
1048
1049 #
1050 # dhcpcdrundir
1051 #
1052 additem dhcpcdrundir "accidentaly created /@RUNDIR@ does not exist"
1053 do_dhcpcdrundir()
1054 {
1055 [ -n "$1" ] || err 3 "USAGE: do_dhcpcdrundir fix|check"
1056 op="$1"
1057 failed=0
1058
1059 if [ -d "${DEST_DIR}/@RUNDIR@" ]; then
1060 if [ "${op}" = "check" ]; then
1061 msg "Remove eroneously created /@RUNDIR@"
1062 failed=1
1063 elif ! rm -r "${DEST_DIR}/@RUNDIR@"; then
1064 msg "Failed to remove ${DEST_DIR}/@RUNDIR@"
1065 failed=1
1066 else
1067 msg "Removed eroneously created ${DEST_DIR}/@RUNDIR@"
1068 fi
1069 fi
1070 return ${failed}
1071 }
1072
1073 #
1074 # envsys
1075 #
1076 additem envsys "envsys configuration is up to date"
1077 do_envsys()
1078 {
1079 [ -n "$1" ] || err 3 "USAGE: do_envsys fix|check"
1080 local op="$1"
1081 local failed=0
1082 local etcsets=$(getetcsets)
1083
1084 populate_dir "$op" true "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
1085 envsys.conf
1086 failed=$(( ${failed} + $? ))
1087
1088 local powerd_scripts="$(select_set_files /etc/powerd/scripts/ \
1089 "/etc/powerd/scripts/\([^[:space:]/]*\)" ${etcsets})"
1090
1091 populate_dir "$op" true "${SRC_DIR}/etc/powerd/scripts" \
1092 "${DEST_DIR}/etc/powerd/scripts" \
1093 555 \
1094 ${powerd_scripts}
1095 failed=$(( ${failed} + $? ))
1096
1097 return ${failed}
1098 }
1099
1100 #
1101 # autofs config files
1102 #
1103 additem autofsconfig "automounter configuration files"
1104 do_autofsconfig()
1105 {
1106 [ -n "$1" ] || err 3 "USAGE: do_autofsconfig fix|check"
1107 local autofs_files="
1108 include_ldap
1109 include_nis
1110 special_hosts
1111 special_media
1112 special_noauto
1113 special_null
1114 "
1115 op="$1"
1116 failed=0
1117 if [ "$op" = "fix" ]; then
1118 mkdir -p "${DEST_DIR}/etc/autofs"
1119 fi
1120 failed=$(( ${failed} + $? ))
1121 populate_dir "$op" false "${SRC_DIR}/etc" \
1122 "${DEST_DIR}/etc" \
1123 644 \
1124 auto_master
1125 failed=$(( ${failed} + $? ))
1126 populate_dir "$op" false "${SRC_DIR}/etc/autofs" \
1127 "${DEST_DIR}/etc/autofs" \
1128 644 \
1129 ${autofs_files}
1130 return ${failed}
1131 }
1132
1133
1134 #
1135 # X11 fontconfig
1136 #
1137 additem fontconfig "X11 font configuration is up to date"
1138 do_fontconfig()
1139 {
1140 [ -n "$1" ] || err 3 "USAGE: do_fontconfig fix|check"
1141 op="$1"
1142 failed=0
1143
1144 # First, check for updates we can handle.
1145 if ! $SOURCEMODE; then
1146 FONTCONFIG_DIR="${SRC_DIR}/etc/fonts/conf.avail"
1147 else
1148 FONTCONFIG_DIR="${XSRC_DIR}/external/mit/fontconfig/dist/conf.d"
1149 fi
1150
1151 if [ ! -d "${FONTCONFIG_DIR}" ]; then
1152 msg "${FONTCONFIG_DIR} is not a directory; skipping check"
1153 return 0
1154 fi
1155 local regular_fonts="
1156 10-autohint.conf
1157 10-no-sub-pixel.conf
1158 10-scale-bitmap-fonts.conf
1159 10-sub-pixel-bgr.conf
1160 10-sub-pixel-rgb.conf
1161 10-sub-pixel-vbgr.conf
1162 10-sub-pixel-vrgb.conf
1163 10-unhinted.conf
1164 11-lcdfilter-default.conf
1165 11-lcdfilter-legacy.conf
1166 11-lcdfilter-light.conf
1167 20-unhint-small-vera.conf
1168 25-unhint-nonlatin.conf
1169 30-metric-aliases.conf
1170 40-nonlatin.conf
1171 45-generic.conf
1172 45-latin.conf
1173 49-sansserif.conf
1174 50-user.conf
1175 51-local.conf
1176 60-generic.conf
1177 60-latin.conf
1178 65-fonts-persian.conf
1179 65-khmer.conf
1180 65-nonlatin.conf
1181 69-unifont.conf
1182 70-no-bitmaps.conf
1183 70-yes-bitmaps.conf
1184 80-delicious.conf
1185 90-synthetic.conf
1186 "
1187 populate_dir "$op" false "${FONTCONFIG_DIR}" \
1188 "${DEST_DIR}/etc/fonts/conf.avail" \
1189 444 \
1190 ${regular_fonts}
1191 failed=$(( ${failed} + $? ))
1192
1193 if ! $SOURCEMODE; then
1194 FONTS_DIR="${SRC_DIR}/etc/fonts"
1195 else
1196 FONTS_DIR="${SRC_DIR}/external/mit/xorg/lib/fontconfig/etc"
1197 fi
1198
1199 populate_dir "$op" false "${FONTS_DIR}" "${DEST_DIR}/etc/fonts" 444 \
1200 fonts.conf
1201 failed=$(( ${failed} + $? ))
1202
1203 # We can't modify conf.d easily; someone might have removed a file.
1204
1205 # Look for old files that need to be deleted.
1206 obsolete_fonts="
1207 10-autohint.conf
1208 10-no-sub-pixel.conf
1209 10-sub-pixel-bgr.conf
1210 10-sub-pixel-rgb.conf
1211 10-sub-pixel-vbgr.conf
1212 10-sub-pixel-vrgb.conf
1213 10-unhinted.conf
1214 25-unhint-nonlatin.conf
1215 65-khmer.conf
1216 70-no-bitmaps.conf
1217 70-yes-bitmaps.conf
1218 "
1219 failed_fonts=""
1220 for i in ${obsolete_fonts}; do
1221 if [ -f "${DEST_DIR}/etc/fonts/conf.d/$i" ]; then
1222 conf_d_failed=1
1223 failed_fonts="$failed_fonts $i"
1224 fi
1225 done
1226
1227 if [ -n "$failed_fonts" ]; then
1228 msg \
1229 "Broken fontconfig configuration found; please delete these files:"
1230 msg "[$failed_fonts]"
1231 failed=$(( ${failed} + 1 ))
1232 fi
1233
1234 return ${failed}
1235 }
1236
1237 #
1238 # gid
1239 #
1240 additem gid "required groups in /etc/group"
1241 do_gid()
1242 {
1243 [ -n "$1" ] || err 3 "USAGE: do_gid fix|check"
1244
1245 check_ids "$1" groups "${DEST_DIR}/etc/group" \
1246 "${SRC_DIR}/etc/group" 14 \
1247 named ntpd sshd SKIP _pflogd _rwhod staff _proxy _timedc \
1248 _sdpd _httpd _mdnsd _tests _tcpdump _tss _gpio _rtadvd SKIP \
1249 _unbound _nsd nvmm _dhcpcd
1250 }
1251
1252 #
1253 # gpio
1254 #
1255 additem gpio "gpio configuration is up to date"
1256 do_gpio()
1257 {
1258 [ -n "$1" ] || err 3 "USAGE: do_gpio fix|check"
1259 op="$1"
1260 failed=0
1261
1262 populate_dir "$op" true "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
1263 gpio.conf
1264 failed=$(( ${failed} + $? ))
1265
1266 return ${failed}
1267 }
1268
1269 #
1270 # hosts
1271 #
1272 additem hosts "/etc/hosts being up to date"
1273 do_hosts()
1274 {
1275 [ -n "$1" ] || err 3 "USAGE: do_hosts fix|check"
1276
1277 modify_file "$1" "${DEST_DIR}/etc/hosts" "${SCRATCHDIR}/hosts" '
1278 /^(127\.0\.0\.1|::1)[ ]+[^\.]*$/ {
1279 print $0, "localhost."
1280 next
1281 }
1282 { print }
1283 '
1284 return $?
1285 }
1286
1287 #
1288 # iscsi
1289 #
1290 additem iscsi "/etc/iscsi is populated"
1291 do_iscsi()
1292 {
1293 [ -n "$1" ] || err 3 "USAGE: do_iscsi fix|check"
1294
1295 populate_dir "${op}" true \
1296 "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 600 auths
1297 populate_dir "${op}" true \
1298 "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 644 targets
1299 return $?
1300 }
1301
1302 #
1303 # makedev
1304 #
1305 additem makedev "/dev/MAKEDEV being up to date"
1306 do_makedev()
1307 {
1308 [ -n "$1" ] || err 3 "USAGE: do_makedev fix|check"
1309 failed=0
1310
1311 if [ -f "${SRC_DIR}/etc/MAKEDEV.tmpl" ]; then
1312 # generate MAKEDEV from source if source is available
1313 env MACHINE="${MACHINE}" \
1314 MACHINE_ARCH="${MACHINE_ARCH}" \
1315 NETBSDSRCDIR="${SRC_DIR}" \
1316 ${AWK} -f "${SRC_DIR}/etc/MAKEDEV.awk" \
1317 "${SRC_DIR}/etc/MAKEDEV.tmpl" > "${SCRATCHDIR}/MAKEDEV"
1318 fi
1319
1320 find_file_in_dirlist MAKEDEV "MAKEDEV" \
1321 "${SCRATCHDIR}" "${SRC_DIR}/dev" \
1322 || return 1
1323 # ${dir} is set by find_file_in_dirlist()
1324 find_makedev
1325 compare_dir "$1" "${dir}" "${MAKEDEV_DIR}" 555 MAKEDEV
1326 failed=$(( ${failed} + $? ))
1327
1328 find_file_in_dirlist MAKEDEV.local "MAKEDEV.local" \
1329 "${SRC_DIR}/etc" "${SRC_DIR}/dev" \
1330 || return 1
1331 # ${dir} is set by find_file_in_dirlist()
1332 compare_dir "$1" "${dir}" "${DEST_DIR}/dev" 555 MAKEDEV.local
1333 failed=$(( ${failed} + $? ))
1334
1335 return ${failed}
1336 }
1337
1338 #
1339 # motd
1340 #
1341 additem motd "contents of motd"
1342 do_motd()
1343 {
1344 [ -n "$1" ] || err 3 "USAGE: do_motd fix|check"
1345
1346 if ${GREP} -i 'http://www.NetBSD.org/Misc/send-pr.html' \
1347 "${DEST_DIR}/etc/motd" >/dev/null 2>&1 \
1348 || ${GREP} -i 'https*://www.NetBSD.org/support/send-pr.html' \
1349 "${DEST_DIR}/etc/motd" >/dev/null 2>&1
1350 then
1351 tmp1="$(mktemp /tmp/postinstall.motd.XXXXXXXX)"
1352 tmp2="$(mktemp /tmp/postinstall.motd.XXXXXXXX)"
1353 ${SED} '1,2d' <"${SRC_DIR}/etc/motd" >"${tmp1}"
1354 ${SED} '1,2d' <"${DEST_DIR}/etc/motd" >"${tmp2}"
1355
1356 if [ "$1" = check ]; then
1357 cmp -s "${tmp1}" "${tmp2}"
1358 result=$?
1359 if [ "${result}" -ne 0 ]; then
1360 msg \
1361 "Bug reporting messages do not seem to match the installed release"
1362 fi
1363 else
1364 head -n 2 "${DEST_DIR}/etc/motd" >"${tmp1}"
1365 ${SED} '1,2d' <"${SRC_DIR}/etc/motd" >>"${tmp1}"
1366 cp "${tmp1}" "${DEST_DIR}/etc/motd"
1367 result=0
1368 fi
1369
1370 rm -f "${tmp1}" "${tmp2}"
1371 else
1372 result=0
1373 fi
1374
1375 return ${result}
1376 }
1377
1378 #
1379 # mtree
1380 #
1381 additem mtree "/etc/mtree/ being up to date"
1382 do_mtree()
1383 {
1384 [ -n "$1" ] || err 3 "USAGE: do_mtree fix|check"
1385 failed=0
1386
1387 compare_dir "$1" "${SRC_DIR}/etc/mtree" "${DEST_DIR}/etc/mtree" 444 special
1388 failed=$(( ${failed} + $? ))
1389
1390 if ! $SOURCEMODE; then
1391 MTREE_DIR="${SRC_DIR}/etc/mtree"
1392 else
1393 /bin/rm -rf "${SCRATCHDIR}/obj"
1394 mkdir "${SCRATCHDIR}/obj"
1395 ${MAKE} -s -C "${SRC_DIR}/etc/mtree" TOOL_AWK="${AWK}" \
1396 MAKEOBJDIR="${SCRATCHDIR}/obj" emit_dist_file > \
1397 "${SCRATCHDIR}/NetBSD.dist"
1398 MTREE_DIR="${SCRATCHDIR}"
1399 /bin/rm -rf "${SCRATCHDIR}/obj"
1400 fi
1401 compare_dir "$1" "${MTREE_DIR}" "${DEST_DIR}/etc/mtree" 444 NetBSD.dist
1402 failed=$(( ${failed} + $? ))
1403
1404 return ${failed}
1405 }
1406
1407 #
1408 # named
1409 #
1410 additem named "named configuration update"
1411 do_named()
1412 {
1413 [ -n "$1" ] || err 3 "USAGE: do_named fix|check"
1414 op="$1"
1415
1416 move_file "${op}" \
1417 "${DEST_DIR}/etc/namedb/named.conf" \
1418 "${DEST_DIR}/etc/named.conf"
1419
1420 compare_dir "${op}" "${SRC_DIR}/etc/namedb" "${DEST_DIR}/etc/namedb" \
1421 644 \
1422 root.cache
1423 }
1424
1425 #
1426 # pam
1427 #
1428 additem pam "/etc/pam.d is populated"
1429 do_pam()
1430 {
1431 [ -n "$1" ] || err 3 "USAGE: do_pam fix|check"
1432 op="$1"
1433 failed=0
1434
1435 populate_dir "${op}" true "${SRC_DIR}/etc/pam.d" \
1436 "${DEST_DIR}/etc/pam.d" 644 \
1437 README cron display_manager ftpd gdm imap kde login other \
1438 passwd pop3 ppp racoon rexecd rsh sshd su system telnetd \
1439 xdm xserver
1440
1441 failed=$(( ${failed} + $? ))
1442
1443 return ${failed}
1444 }
1445
1446 #
1447 # periodic
1448 #
1449 additem periodic "/etc/{daily,weekly,monthly,security} being up to date"
1450 do_periodic()
1451 {
1452 [ -n "$1" ] || err 3 "USAGE: do_periodic fix|check"
1453
1454 compare_dir "$1" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
1455 daily weekly monthly security
1456 }
1457
1458 #
1459 # pf
1460 #
1461 additem pf "pf configuration being up to date"
1462 do_pf()
1463 {
1464 [ -n "$1" ] || err 3 "USAGE: do_pf fix|check"
1465 op="$1"
1466 failed=0
1467
1468 find_file_in_dirlist pf.os "pf.os" \
1469 "${SRC_DIR}/dist/pf/etc" "${SRC_DIR}/etc" \
1470 || return 1
1471 # ${dir} is set by find_file_in_dirlist()
1472 populate_dir "${op}" true \
1473 "${dir}" "${DEST_DIR}/etc" 644 \
1474 pf.conf
1475 failed=$(( ${failed} + $? ))
1476
1477 compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 pf.os
1478 failed=$(( ${failed} + $? ))
1479
1480 return ${failed}
1481 }
1482
1483 #
1484 # pwd_mkdb
1485 #
1486 additem pwd_mkdb "passwd database version"
1487 do_pwd_mkdb()
1488 {
1489 [ -n "$1" ] || err 3 "USAGE: do_pwd_mkdb fix|check"
1490 op="$1"
1491 failed=0
1492
1493 # XXX Ideally, we should figure out the endianness of the
1494 # target machine, and add "-E B"/"-E L" to the db(1) flags,
1495 # and "-B"/"-L" to the pwd_mkdb(8) flags if the target is not
1496 # the same as the host machine. It probably doesn't matter,
1497 # because we don't expect "postinstall fix pwd_mkdb" to be
1498 # invoked during a cross build.
1499
1500 set -- $(${DB} -q -Sb -Ub -To -N hash "${DEST_DIR}/etc/pwd.db" \
1501 'VERSION\0')
1502 case "$2" in
1503 '\001\000\000\000') return 0 ;; # version 1, little-endian
1504 '\000\000\000\001') return 0 ;; # version 1, big-endian
1505 esac
1506
1507 if [ "${op}" = "check" ]; then
1508 msg "Update format of passwd database"
1509 failed=1
1510 elif ! ${PWD_MKDB} -V 1 -d "${DEST_DIR:-/}" \
1511 "${DEST_DIR}/etc/master.passwd";
1512 then
1513 msg "Can't update format of passwd database"
1514 failed=1
1515 else
1516 msg "Updated format of passwd database"
1517 fi
1518
1519 return ${failed}
1520 }
1521
1522 #
1523 # rc
1524 #
1525
1526 # There is no info in src/distrib or /etc/mtree which rc* files
1527 # can be overwritten unconditionally on upgrade. See PR/54741.
1528 rc_644_files="
1529 rc
1530 rc.subr
1531 rc.shutdown
1532 "
1533
1534 rc_obsolete_vars="
1535 amd amd_master
1536 btcontrol btcontrol_devices
1537 critical_filesystems critical_filesystems_beforenet
1538 mountcritlocal mountcritremote
1539 network ip6forwarding
1540 network nfsiod_flags
1541 sdpd sdpd_control
1542 sdpd sdpd_groupname
1543 sdpd sdpd_username
1544 sysctl defcorename
1545 "
1546
1547 update_rc()
1548 {
1549 local op=$1
1550 local dir=$2
1551 local name=$3
1552 local bindir=$4
1553 local rcdir=$5
1554
1555 if [ ! -x "${DEST_DIR}/${bindir}/${name}" ]; then
1556 return 0
1557 fi
1558
1559 if ! find_file_in_dirlist "${name}" "${name}" \
1560 "${rcdir}" "${SRC_DIR}/etc/rc.d"; then
1561 return 1
1562 fi
1563 populate_dir "${op}" false "${dir}" "${DEST_DIR}/etc/rc.d" 555 "${name}"
1564 return $?
1565 }
1566
1567 # select non-obsolete files in a sets file
1568 # $1: directory pattern
1569 # $2: file pattern
1570 # $3: filename
1571 select_set_files()
1572 {
1573 local qdir="$(echo $1 | ${SED} -e s@/@\\\\/@g -e s/\\./\\\\./g)"
1574 ${SED} -n -e /obsolete/d \
1575 -e "/^\.${qdir}/s@^.$2[[:space:]].*@\1@p" $3
1576 }
1577
1578 # select obsolete files in a sets file
1579 # $1: directory pattern
1580 # $2: file pattern
1581 # $3: setname
1582 select_obsolete_files()
1583 {
1584 if $SOURCEMODE; then
1585 ${SED} -n -e "/obsolete/s@\.$1$2[[:space:]].*@\1@p" \
1586 ${SRC_DIR}/distrib/sets/lists/$3/mi
1587 return
1588 fi
1589
1590 # On upgrade builds we don't extract the "etc" set so we
1591 # try to use the source set instead. See PR/54730 for
1592 # ways to better handle this.
1593
1594 local obsolete_dir
1595
1596 if [ $3 = "etc" ] ;then
1597 obsolete_dir=${SRC_DIR}/var/db/obsolete
1598 else
1599 obsolete_dir=${DEST_DIR}/var/db/obsolete
1600 fi
1601 ${SED} -n -e "s@\.$1$2\$@\1@p" "${obsolete_dir}/$3"
1602 }
1603
1604 getetcsets()
1605 {
1606 if $SOURCEMODE; then
1607 echo "${SRC_DIR}/distrib/sets/lists/etc/mi"
1608 else
1609 echo "${SRC_DIR}/etc/mtree/set.etc"
1610 fi
1611 }
1612
1613 additem rc "/etc/rc* and /etc/rc.d/ being up to date"
1614 do_rc()
1615 {
1616 [ -n "$1" ] || err 3 "USAGE: do_rc fix|check"
1617 local op="$1"
1618 local failed=0
1619 local generated_scripts=""
1620 local etcsets=$(getetcsets)
1621 if [ "${MKX11}" != "no" ]; then
1622 generated_scripts="${generated_scripts} xdm xfs"
1623 fi
1624
1625 # Directories of external programs that have rc files (in bsd)
1626 local rc_external_files="blocklist nsd unbound"
1627
1628 # rc* files in /etc/
1629 # XXX: at least rc.conf and rc.local shouldn't be updated. PR/54741
1630 #local rc_644_files="$(select_set_files /etc/rc \
1631 # "/etc/\(rc[^[:space:]/]*\)" ${etcsets})"
1632
1633 # no-obsolete rc files in /etc/rc.d
1634 local rc_555_files="$(select_set_files /etc/rc.d/ \
1635 "/etc/rc\.d/\([^[:space:]]*\)" ${etcsets} | \
1636 exclude ${rc_external_files})"
1637
1638 # obsolete rc file in /etc/rc.d
1639 local rc_obsolete_files="$(select_obsolete_files /etc/rc.d/ \
1640 "\([^[:space:]]*\)" etc)"
1641
1642 compare_dir "${op}" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
1643 ${rc_644_files}
1644 failed=$(( ${failed} + $? ))
1645
1646 local extra_scripts
1647 if ! $SOURCEMODE; then
1648 extra_scripts="${generated_scripts}"
1649 else
1650 extra_scripts=""
1651 fi
1652
1653 compare_dir "${op}" "${SRC_DIR}/etc/rc.d" "${DEST_DIR}/etc/rc.d" 555 \
1654 ${rc_555_files} \
1655 ${extra_scripts}
1656 failed=$(( ${failed} + $? ))
1657
1658 for i in ${rc_external_files}; do
1659 local rc_file
1660 case $i in
1661 *d) rc_file=${i};;
1662 *) rc_file=${i}d;;
1663 esac
1664
1665 update_rc "${op}" "${dir}" ${rc_file} /sbin \
1666 "${SRC_DIR}/external/bsd/$i/etc/rc.d"
1667 failed=$(( ${failed} + $? ))
1668 done
1669
1670 if $SOURCEMODE && [ -n "${generated_scripts}" ]; then
1671 # generate scripts
1672 mkdir "${SCRATCHDIR}/rc"
1673 for f in ${generated_scripts}; do
1674 ${SED} -e "s,@X11ROOTDIR@,${X11ROOTDIR},g" \
1675 < "${SRC_DIR}/etc/rc.d/${f}.in" \
1676 > "${SCRATCHDIR}/rc/${f}"
1677 done
1678 compare_dir "${op}" "${SCRATCHDIR}/rc" \
1679 "${DEST_DIR}/etc/rc.d" 555 \
1680 ${generated_scripts}
1681 failed=$(( ${failed} + $? ))
1682 fi
1683
1684 # check for obsolete rc.d files
1685 for f in ${rc_obsolete_files}; do
1686 local fd="/etc/rc.d/${f}"
1687 [ -e "${DEST_DIR}${fd}" ] && echo "${fd}"
1688 done | obsolete_paths "${op}"
1689 failed=$(( ${failed} + $? ))
1690
1691 # check for obsolete rc.conf(5) variables
1692 set -- ${rc_obsolete_vars}
1693 while [ $# -gt 1 ]; do
1694 if rcconf_is_set "${op}" "$1" "$2" 1; then
1695 failed=1
1696 fi
1697 shift 2
1698 done
1699
1700 return ${failed}
1701 }
1702
1703 #
1704 # sendmail
1705 #
1706 adddisableditem sendmail "remove obsolete sendmail configuration files and scripts"
1707 do_sendmail()
1708 {
1709 [ -n "$1" ] || err 3 "USAGE: do_sendmail fix|check"
1710 op="$1"
1711 failed=0
1712
1713 # Don't complain if the "sendmail" package is installed because the
1714 # files might still be in use.
1715 if /usr/sbin/pkg_info -qe sendmail >/dev/null 2>&1; then
1716 return 0
1717 fi
1718
1719 for f in /etc/mail/helpfile /etc/mail/local-host-names \
1720 /etc/mail/sendmail.cf /etc/mail/submit.cf /etc/rc.d/sendmail \
1721 /etc/rc.d/smmsp /usr/share/misc/sendmail.hf \
1722 $( ( find "${DEST_DIR}/usr/share/sendmail" -type f ; \
1723 find "${DEST_DIR}/usr/share/sendmail" -type d \
1724 ) | unprefix "${DEST_DIR}" ) \
1725 /var/log/sendmail.st \
1726 /var/spool/clientmqueue \
1727 /var/spool/mqueue
1728 do
1729 [ -e "${DEST_DIR}${f}" ] && echo "${f}"
1730 done | obsolete_paths "${op}"
1731 failed=$(( ${failed} + $? ))
1732
1733 return ${failed}
1734 }
1735
1736 #
1737 # mailerconf
1738 #
1739 adddisableditem mailerconf "update /etc/mailer.conf after sendmail removal"
1740 do_mailerconf()
1741 {
1742 [ -n "$1" ] || err 3 "USAGE: do_mailterconf fix|check"
1743 op="$1"
1744
1745 failed=0
1746 mta_path="$(${AWK} '/^sendmail[ \t]/{print$2}' \
1747 "${DEST_DIR}/etc/mailer.conf")"
1748 old_sendmail_path="/usr/libexec/sendmail/sendmail"
1749 if [ "${mta_path}" = "${old_sendmail_path}" ]; then
1750 if [ "$op" = check ]; then
1751 msg "mailer.conf points to obsolete ${old_sendmail_path}"
1752 failed=1;
1753 else
1754 populate_dir "${op}" false \
1755 "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 mailer.conf
1756 failed=$?
1757 fi
1758 fi
1759
1760 return ${failed}
1761 }
1762
1763 #
1764 # ssh
1765 #
1766 additem ssh "ssh configuration update"
1767 do_ssh()
1768 {
1769 [ -n "$1" ] || err 3 "USAGE: do_ssh fix|check"
1770 op="$1"
1771
1772 failed=0
1773 _etcssh="${DEST_DIR}/etc/ssh"
1774 if ! check_dir "${op}" "${_etcssh}" 755; then
1775 failed=1
1776 fi
1777
1778 if [ ${failed} -eq 0 ]; then
1779 for f in \
1780 ssh_known_hosts ssh_known_hosts2 \
1781 ssh_host_dsa_key ssh_host_dsa_key.pub \
1782 ssh_host_rsa_key ssh_host_rsa_key.pub \
1783 ssh_host_key ssh_host_key.pub \
1784 ; do
1785 if ! move_file "${op}" \
1786 "${DEST_DIR}/etc/${f}" "${_etcssh}/${f}" ; then
1787 failed=1
1788 fi
1789 done
1790 for f in sshd.conf ssh.conf ; do
1791 # /etc/ssh/ssh{,d}.conf -> ssh{,d}_config
1792 #
1793 if ! move_file "${op}" \
1794 "${_etcssh}/${f}" "${_etcssh}/${f%.conf}_config" ;
1795 then
1796 failed=1
1797 fi
1798 # /etc/ssh{,d}.conf -> /etc/ssh/ssh{,d}_config
1799 #
1800 if ! move_file "${op}" \
1801 "${DEST_DIR}/etc/${f}" \
1802 "${_etcssh}/${f%.conf}_config" ;
1803 then
1804 failed=1
1805 fi
1806 done
1807 fi
1808
1809 sshdconf=""
1810 for f in \
1811 "${_etcssh}/sshd_config" \
1812 "${_etcssh}/sshd.conf" \
1813 "${DEST_DIR}/etc/sshd.conf" ; do
1814 if [ -f "${f}" ]; then
1815 sshdconf="${f}"
1816 break
1817 fi
1818 done
1819 if [ -n "${sshdconf}" ]; then
1820 modify_file "${op}" "${sshdconf}" "${SCRATCHDIR}/sshdconf" '
1821 /^[^#$]/ {
1822 kw = tolower($1)
1823 if (kw == "hostkey" &&
1824 $2 ~ /^\/etc\/+ssh_host(_[dr]sa)?_key$/ ) {
1825 sub(/\/etc\/+/, "/etc/ssh/")
1826 }
1827 if (kw == "rhostsauthentication" ||
1828 kw == "verifyreversemapping" ||
1829 kw == "reversemappingcheck") {
1830 sub(/^/, "# DEPRECATED:\t")
1831 }
1832 }
1833 { print }
1834 '
1835 failed=$(( ${failed} + $? ))
1836 fi
1837
1838 if ! find_file_in_dirlist moduli "moduli" \
1839 "${SRC_DIR}/crypto/external/bsd/openssh/dist" "${SRC_DIR}/etc" ; then
1840 failed=1
1841 # ${dir} is set by find_file_in_dirlist()
1842 elif ! compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 moduli; then
1843 failed=1
1844 fi
1845
1846 if ! check_dir "${op}" "${DEST_DIR}/var/chroot/sshd" 755 ; then
1847 failed=1
1848 fi
1849
1850 if rcconf_is_set "${op}" sshd sshd_conf_dir 1; then
1851 failed=1
1852 fi
1853
1854 return ${failed}
1855 }
1856
1857 #
1858 # wscons
1859 #
1860 additem wscons "wscons configuration file update"
1861 do_wscons()
1862 {
1863 [ -n "$1" ] || err 3 "USAGE: do_wscons fix|check"
1864 op="$1"
1865
1866 [ -f "${DEST_DIR}/etc/wscons.conf" ] || return 0
1867
1868 failed=0
1869 notfixed=""
1870 if [ "${op}" = "fix" ]; then
1871 notfixed="${NOT_FIXED}"
1872 fi
1873 while read _type _arg1 _rest; do
1874 if [ "${_type}" = "mux" -a "${_arg1}" = "1" ]; then
1875 msg \
1876 "Obsolete wscons.conf(5) entry \""${_type} ${_arg1}"\" found.${notfixed}"
1877 failed=1
1878 fi
1879 done < "${DEST_DIR}/etc/wscons.conf"
1880
1881 return ${failed}
1882 }
1883
1884 #
1885 # X11
1886 #
1887 additem x11 "x11 configuration update"
1888 do_x11()
1889 {
1890 [ -n "$1" ] || err 3 "USAGE: do_x11 fix|check"
1891 op="$1"
1892
1893 failed=0
1894 _etcx11="${DEST_DIR}/etc/X11"
1895 if [ ! -d "${_etcx11}" ]; then
1896 msg "${_etcx11} is not a directory; skipping check"
1897 return 0
1898 fi
1899 if [ -d "${DEST_DIR}/usr/X11R6/." ]
1900 then
1901 _libx11="${DEST_DIR}/usr/X11R6/lib/X11"
1902 if [ ! -d "${_libx11}" ]; then
1903 msg "${_libx11} is not a directory; skipping check"
1904 return 0
1905 fi
1906 fi
1907
1908 _notfixed=""
1909 if [ "${op}" = "fix" ]; then
1910 _notfixed="${NOT_FIXED}"
1911 fi
1912
1913 for d in \
1914 fs lbxproxy proxymngr rstart twm xdm xinit xserver xsm \
1915 ; do
1916 sd="${_libx11}/${d}"
1917 ld="/etc/X11/${d}"
1918 td="${DEST_DIR}${ld}"
1919 if [ -h "${sd}" ]; then
1920 continue
1921 elif [ -d "${sd}" ]; then
1922 tdfiles="$(find "${td}" \! -type d)"
1923 if [ -n "${tdfiles}" ]; then
1924 msg "${sd} exists yet ${td} already" \
1925 "contains files${_notfixed}"
1926 else
1927 msg "Migrate ${sd} to ${td}${_notfixed}"
1928 fi
1929 failed=1
1930 elif [ -e "${sd}" ]; then
1931 msg "Unexpected file ${sd}${_notfixed}"
1932 continue
1933 else
1934 continue
1935 fi
1936 done
1937
1938 # check if xdm resources have been updated
1939 if [ -r ${_etcx11}/xdm/Xresources ] && \
1940 ! ${GREP} 'inpColor:' ${_etcx11}/xdm/Xresources > /dev/null; then
1941 msg "Update ${_etcx11}/xdm/Xresources${_notfixed}"
1942 failed=1
1943 fi
1944
1945 return ${failed}
1946 }
1947
1948 #
1949 # xkb
1950 #
1951 # /usr/X11R7/lib/X11/xkb/symbols/pc used to be a directory, but changed
1952 # to a file on 2009-06-12. Fixing this requires removing the directory
1953 # (which we can do) and re-extracting the xbase set (which we can't do),
1954 # or at least adding that one file (which we may be able to do if X11SRCDIR
1955 # is available).
1956 #
1957 additem xkb "clean up for xkbdata to xkeyboard-config upgrade"
1958 do_xkb()
1959 {
1960 [ -n "$1" ] || err 3 "USAGE: do_xkb fix|check"
1961 op="$1"
1962 failed=0
1963
1964 pcpath="/usr/X11R7/lib/X11/xkb/symbols/pc"
1965 pcsrcdir="${X11SRCDIR}/external/mit/xkeyboard-config/dist/symbols"
1966
1967 filemsg="\
1968 ${pcpath} was a directory, should be a file.
1969 To fix, extract the xbase set again."
1970
1971 _notfixed=""
1972 if [ "${op}" = "fix" ]; then
1973 _notfixed="${NOT_FIXED}"
1974 fi
1975
1976 if [ ! -d "${DEST_DIR}${pcpath}" ]; then
1977 return 0
1978 fi
1979
1980 # Delete obsolete files in the directory, and the directory
1981 # itself. If the directory contains unexpected extra files
1982 # then it will not be deleted.
1983 ( [ -f "${DEST_DIR}"/var/db/obsolete/xbase ] \
1984 && ${SORT} -ru "${DEST_DIR}"/var/db/obsolete/xbase \
1985 | ${GREP} -E "^\\.?${pcpath}/" ;
1986 echo "${pcpath}" ) \
1987 | obsolete_paths "${op}"
1988 failed=$(( ${failed} + $? ))
1989
1990 # If the directory was removed above, then try to replace it with
1991 # a file.
1992 if [ -d "${DEST_DIR}${pcpath}" ]; then
1993 msg "${filemsg}${_notfixed}"
1994 failed=$(( ${failed} + 1 ))
1995 else
1996 if ! find_file_in_dirlist pc "${pcpath}" \
1997 "${pcsrcdir}" "${SRC_DIR}${pcpath%/*}"
1998 then
1999 msg "${filemsg}${_notfixed}"
2000 failed=$(( ${failed} + 1 ))
2001 else
2002 # ${dir} is set by find_file_in_dirlist()
2003 populate_dir "${op}" true \
2004 "${dir}" "${DEST_DIR}${pcpath%/*}" 444 \
2005 pc
2006 failed=$(( ${failed} + $? ))
2007 fi
2008 fi
2009
2010 return $failed
2011 }
2012
2013 #
2014 # uid
2015 #
2016 additem uid "required users in /etc/master.passwd"
2017 do_uid()
2018 {
2019 [ -n "$1" ] || err 3 "USAGE: do_uid fix|check"
2020
2021 check_ids "$1" users "${DEST_DIR}/etc/master.passwd" \
2022 "${SRC_DIR}/etc/master.passwd" 12 \
2023 postfix SKIP named ntpd sshd SKIP _pflogd _rwhod SKIP _proxy \
2024 _timedc _sdpd _httpd _mdnsd _tests _tcpdump _tss SKIP _rtadvd \
2025 SKIP _unbound _nsd SKIP _dhcpcd
2026 }
2027
2028
2029 #
2030 # varrwho
2031 #
2032 additem varrwho "required ownership of files in /var/rwho"
2033 do_varrwho()
2034 {
2035 [ -n "$1" ] || err 3 "USAGE: do_varrwho fix|check"
2036
2037 contents_owner "$1" "${DEST_DIR}/var/rwho" _rwhod _rwhod
2038 }
2039
2040
2041 #
2042 # tcpdumpchroot
2043 #
2044 additem tcpdumpchroot "remove /var/chroot/tcpdump/etc/protocols"
2045 do_tcpdumpchroot()
2046 {
2047 [ -n "$1" ] || err 3 "USAGE: do_tcpdumpchroot fix|check"
2048
2049 failed=0;
2050 if [ -r "${DEST_DIR}/var/chroot/tcpdump/etc/protocols" ]; then
2051 if [ "$1" = "fix" ]; then
2052 rm "${DEST_DIR}/var/chroot/tcpdump/etc/protocols"
2053 failed=$(( ${failed} + $? ))
2054 rmdir "${DEST_DIR}/var/chroot/tcpdump/etc"
2055 failed=$(( ${failed} + $? ))
2056 else
2057 failed=1
2058 fi
2059 fi
2060 return ${failed}
2061 }
2062
2063
2064 #
2065 # atf
2066 #
2067 additem atf "install missing atf configuration files and validate them"
2068 do_atf()
2069 {
2070 [ -n "$1" ] || err 3 "USAGE: do_atf fix|check"
2071 op="$1"
2072 failed=0
2073
2074 # Ensure atf configuration files are in place.
2075 if find_file_in_dirlist NetBSD.conf "NetBSD.conf" \
2076 "${SRC_DIR}/external/bsd/atf/etc/atf" \
2077 "${SRC_DIR}/etc/atf"; then
2078 # ${dir} is set by find_file_in_dirlist()
2079 populate_dir "${op}" true "${dir}" "${DEST_DIR}/etc/atf" 644 \
2080 NetBSD.conf common.conf || failed=1
2081 else
2082 failed=1
2083 fi
2084 if find_file_in_dirlist atf-run.hooks "atf-run.hooks" \
2085 "${SRC_DIR}/external/bsd/atf/dist/tools/sample" \
2086 "${SRC_DIR}/etc/atf"; then
2087 # ${dir} is set by find_file_in_dirlist()
2088 populate_dir "${op}" true "${dir}" "${DEST_DIR}/etc/atf" 644 \
2089 atf-run.hooks || failed=1
2090 else
2091 failed=1
2092 fi
2093
2094 # Validate the _atf to _tests user/group renaming.
2095 if [ -f "${DEST_DIR}/etc/atf/common.conf" ]; then
2096 handle_atf_user "${op}" || failed=1
2097 else
2098 failed=1
2099 fi
2100
2101 return ${failed}
2102 }
2103
2104 handle_atf_user()
2105 {
2106 local op="$1"
2107 local failed=0
2108
2109 local conf="${DEST_DIR}/etc/atf/common.conf"
2110 if grep '[^#]*unprivileged-user[ \t]*=.*_atf' "${conf}" >/dev/null
2111 then
2112 if [ "$1" = "fix" ]; then
2113 ${SED} -e \
2114 "/[^#]*unprivileged-user[\ t]*=/s/_atf/_tests/" \
2115 "${conf}" >"${conf}.new"
2116 failed=$(( ${failed} + $? ))
2117 mv "${conf}.new" "${conf}"
2118 failed=$(( ${failed} + $? ))
2119 msg "Set unprivileged-user=_tests in ${conf}"
2120 else
2121 msg "unprivileged-user=_atf in ${conf} should be" \
2122 "unprivileged-user=_tests"
2123 failed=1
2124 fi
2125 fi
2126
2127 return ${failed}
2128 }
2129
2130 #
2131 # catpages
2132 #
2133 obsolete_catpages()
2134 {
2135 basedir="$2"
2136 section="$3"
2137 mandir="${basedir}/man${section}"
2138 catdir="${basedir}/cat${section}"
2139 test -d "$mandir" || return 0
2140 test -d "$catdir" || return 0
2141 (cd "$mandir" && find . -type f) | {
2142 failed=0
2143 while read manpage; do
2144 manpage="${manpage#./}"
2145 case "$manpage" in
2146 *.Z)
2147 catname="$catdir/${manpage%.*.Z}.0"
2148 ;;
2149 *.gz)
2150 catname="$catdir/${manpage%.*.gz}.0"
2151 ;;
2152 *)
2153 catname="$catdir/${manpage%.*}.0"
2154 ;;
2155 esac
2156 test -e "$catname" -a "$catname" -ot "$mandir/$manpage" || continue
2157 if [ "$1" = "fix" ]; then
2158 rm "$catname"
2159 failed=$(( ${failed} + $? ))
2160 msg "Removed obsolete cat page $catname"
2161 else
2162 msg "Obsolete cat page $catname"
2163 failed=1
2164 fi
2165 done
2166 exit $failed
2167 }
2168 }
2169
2170 additem catpages "remove outdated cat pages"
2171 do_catpages()
2172 {
2173 failed=0
2174 for manbase in /usr/share/man /usr/X11R6/man /usr/X11R7/man; do
2175 for sec in 1 2 3 4 5 6 7 8 9; do
2176 obsolete_catpages "$1" "${DEST_DIR}${manbase}" "${sec}"
2177 failed=$(( ${failed} + $? ))
2178 if [ "$1" = "fix" ]; then
2179 rmdir "${DEST_DIR}${manbase}/cat${sec}"/* \
2180 2>/dev/null
2181 rmdir "${DEST_DIR}${manbase}/cat${sec}" \
2182 2>/dev/null
2183 fi
2184 done
2185 done
2186 return $failed
2187 }
2188
2189 #
2190 # man.conf
2191 #
2192 additem manconf "check for a mandoc usage in /etc/man.conf"
2193 do_manconf()
2194 {
2195 [ -n "$1" ] || err 3 "USAGE: do_manconf fix|check"
2196 op="$1"
2197 failed=0
2198
2199 [ -f "${DEST_DIR}/etc/man.conf" ] || return 0
2200 if ${GREP} -w "mandoc" "${DEST_DIR}/etc/man.conf" >/dev/null 2>&1;
2201 then
2202 failed=0;
2203 else
2204 failed=1
2205 notfixed=""
2206 if [ "${op}" = "fix" ]; then
2207 notfixed="${NOT_FIXED}"
2208 fi
2209 msg "The file /etc/man.conf has not been adapted to mandoc usage; you"
2210 msg "probably want to copy a new version over. ${notfixed}"
2211 fi
2212
2213 return ${failed}
2214 }
2215
2216
2217 #
2218 # ptyfsoldnodes
2219 #
2220 additem ptyfsoldnodes "remove legacy device nodes when using ptyfs"
2221 do_ptyfsoldnodes()
2222 {
2223 [ -n "$1" ] || err 3 "USAGE: do_ptyfsoldnodes fix|check"
2224 _ptyfs_op="$1"
2225
2226 # Check whether ptyfs is in use
2227 failed=0;
2228 if ! ${GREP} -E "^ptyfs" "${DEST_DIR}/etc/fstab" > /dev/null; then
2229 msg "ptyfs is not in use"
2230 return 0
2231 fi
2232
2233 if [ ! -e "${DEST_DIR}/dev/pts" ]; then
2234 msg "ptyfs is not properly configured: missing /dev/pts"
2235 return 1
2236 fi
2237
2238 # Find the device major numbers for the pty master and slave
2239 # devices, by parsing the output from "MAKEDEV -s pty0".
2240 #
2241 # Output from MAKEDEV looks like this:
2242 # ./ttyp0 type=char device=netbsd,5,0 mode=666 gid=0 uid=0
2243 # ./ptyp0 type=char device=netbsd,6,0 mode=666 gid=0 uid=0
2244 #
2245 # Output from awk, used in the eval statement, looks like this:
2246 # maj_ptym=6; maj_ptys=5;
2247 #
2248 find_makedev
2249 eval "$(
2250 ${HOST_SH} "${MAKEDEV_DIR}/MAKEDEV" -s pty0 2>/dev/null \
2251 | ${AWK} '\
2252 BEGIN { before_re = ".*device=[a-zA-Z]*,"; after_re = ",.*"; }
2253 /ptyp0/ { maj_ptym = gensub(before_re, "", 1, $0);
2254 maj_ptym = gensub(after_re, "", 1, maj_ptym); }
2255 /ttyp0/ { maj_ptys = gensub(before_re, "", 1, $0);
2256 maj_ptys = gensub(after_re, "", 1, maj_ptys); }
2257 END { print "maj_ptym=" maj_ptym "; maj_ptys=" maj_ptys ";"; }
2258 '
2259 )"
2260 #msg "Major numbers are maj_ptym=${maj_ptym} maj_ptys=${maj_ptys}"
2261 if [ -z "$maj_ptym" ] || [ -z "$maj_ptys" ]; then
2262 msg "Cannot find device major numbers for pty master and slave"
2263 return 1
2264 fi
2265
2266 # look for /dev/[pt]ty[p-zP-T][0-9a-zA-Z], and check that they
2267 # have the expected device major numbers. ttyv* is typically not a
2268 # pty device, but we check it anyway.
2269 #
2270 # The "for d1" loop is intended to avoid overflowing ARG_MAX;
2271 # otherwise we could have used a single glob pattern.
2272 #
2273 # If there are no files that match a particular pattern,
2274 # then stat prints something like:
2275 # stat: /dev/[pt]tyx?: lstat: No such file or directory
2276 # and we ignore it. XXX: We also ignore other error messages.
2277 #
2278 _ptyfs_tmp="$(mktemp /tmp/postinstall.ptyfs.XXXXXXXX)"
2279 for d1 in p q r s t u v w x y z P Q R S T; do
2280 ${STAT} -f "%Hr %N" "${DEST_DIR}/dev/"[pt]ty${d1}? 2>&1
2281 done \
2282 | while read -r major node ; do
2283 case "$major" in
2284 ${maj_ptym}|${maj_ptys}) echo "$node" ;;
2285 esac
2286 done >"${_ptyfs_tmp}"
2287
2288 _desc="legacy device node"
2289 while read node; do
2290 if [ "${_ptyfs_op}" = "check" ]; then
2291 msg "Remove ${_desc} ${node}"
2292 failed=1
2293 else # "fix"
2294 if rm "${node}"; then
2295 msg "Removed ${_desc} ${node}"
2296 else
2297 warn "Failed to remove ${_desc} ${node}"
2298 failed=1
2299 fi
2300 fi
2301 done < "${_ptyfs_tmp}"
2302 rm "${_ptyfs_tmp}"
2303
2304 return ${failed}
2305 }
2306
2307
2308 #
2309 # varshm
2310 #
2311 additem varshm "check for a tmpfs mounted on /var/shm"
2312 do_varshm()
2313 {
2314 [ -n "$1" ] || err 3 "USAGE: do_varshm fix|check"
2315 op="$1"
2316 failed=0
2317
2318 [ -f "${DEST_DIR}/etc/fstab" ] || return 0
2319 if ${GREP} -E "^var_shm_symlink" "${DEST_DIR}/etc/rc.conf" >/dev/null 2>&1;
2320 then
2321 failed=0;
2322 elif ${GREP} -w "/var/shm" "${DEST_DIR}/etc/fstab" >/dev/null 2>&1;
2323 then
2324 failed=0;
2325 else
2326 if [ "${op}" = "check" ]; then
2327 failed=1
2328 msg "No /var/shm mount found in ${DEST_DIR}/etc/fstab"
2329 elif [ "${op}" = "fix" ]; then
2330 printf '\ntmpfs\t/var/shm\ttmpfs\trw,-m1777,-sram%%25\n' \
2331 >> "${DEST_DIR}/etc/fstab"
2332 msg "Added tmpfs with 25% ram limit as /var/shm"
2333
2334 fi
2335 fi
2336
2337 return ${failed}
2338 }
2339
2340 #
2341 # obsolete_stand
2342 #
2343 obsolete_stand_internal()
2344 {
2345 local prefix="$1"
2346 shift
2347 [ -n "$1" ] || err 3 "USAGE: do_obsolete_stand fix|check"
2348 local op="$1"
2349 local failed=0
2350
2351 for dir in \
2352 ${prefix}/stand/${MACHINE} \
2353 ${prefix}/stand/${MACHINE}-4xx \
2354 ${prefix}/stand/${MACHINE}-booke \
2355 ${prefix}/stand/${MACHINE}-xen \
2356 ${prefix}/stand/${MACHINE}pae-xen
2357 do
2358 [ -d "${DESTDIR}${dir}" ] && obsolete_stand "${dir}"
2359 done | obsolete_paths "${op}"
2360 failed=$(( ${failed} + $? ))
2361
2362 return ${failed}
2363 }
2364
2365 adddisableditem obsolete_stand "remove obsolete files from /stand"
2366 do_obsolete_stand()
2367 {
2368 obsolete_stand_internal "" "$@"
2369 return $?
2370 }
2371
2372 adddisableditem obsolete_stand_debug "remove obsolete files from /usr/libdata/debug/stand"
2373 do_obsolete_stand_debug()
2374 {
2375 obsolete_stand_internal "/usr/libdata/debug" "$@"
2376 return $?
2377 }
2378
2379 listarchsubdirs() {
2380 if ! $SOURCEMODE; then
2381 echo "@ARCHSUBDIRS@"
2382 else
2383 ${SED} -n -e '/ARCHDIR_SUBDIR/s/[[:space:]]//gp' \
2384 ${SRC_DIR}/compat/archdirs.mk
2385 fi
2386 }
2387
2388
2389 getarchsubdirs() {
2390 local m
2391 case ${MACHINE_ARCH} in
2392 *arm*|*aarch64*) m=arm;;
2393 x86_64) m=amd64;;
2394 *) m=${MACHINE_ARCH};;
2395 esac
2396
2397 for i in $(listarchsubdirs); do
2398 echo $i
2399 done | ${SORT} -u | ${SED} -n -e "/=${m}/s@.*=${m}/\(.*\)@\1@p"
2400 }
2401
2402 getcompatlibdirs() {
2403 for i in $(getarchsubdirs); do
2404 if [ -d "${DEST_DIR}/usr/lib/$i" ]; then
2405 echo /usr/lib/$i
2406 fi
2407 done
2408 }
2409
2410 #
2411 # obsolete
2412 # (this item is last to allow other items to move obsolete files)
2413 #
2414 additem obsolete "remove obsolete file sets and minor libraries"
2415 do_obsolete()
2416 {
2417 [ -n "$1" ] || err 3 "USAGE: do_obsolete fix|check"
2418 op="$1"
2419 failed=0
2420
2421 ${SORT} -ru "${DEST_DIR}"/var/db/obsolete/* | obsolete_paths "${op}"
2422 failed=$(( ${failed} + $? ))
2423
2424 (
2425 obsolete_libs /lib
2426 obsolete_libs /usr/lib
2427 obsolete_libs /usr/lib/i18n
2428 obsolete_libs /usr/X11R6/lib
2429 obsolete_libs /usr/X11R7/lib
2430 for i in $(getcompatlibdirs); do
2431 obsolete_libs $i
2432 done
2433 ) | obsolete_paths "${op}"
2434 failed=$(( ${failed} + $? ))
2435
2436 return ${failed}
2437 }
2438
2439 #
2440 # end of items
2441 # ------------
2442 #
2443
2444
2445 usage()
2446 {
2447 cat 1>&2 << _USAGE_
2448 Usage: ${PROGNAME} [-s srcdir] [-x xsrcdir] [-d destdir] [-m mach] [-a arch] op [item [...]]
2449 Perform post-installation checks and/or fixes on a system's
2450 configuration files.
2451 If no items are provided, a default set of checks or fixes is applied.
2452
2453 Options:
2454 -s {srcdir|tgzfile|tempdir}
2455 Location of the source files. This may be any
2456 of the following:
2457 * A directory that contains a NetBSD source tree;
2458 * A distribution set file such as "etc.tgz" or
2459 "xetc.tgz". Pass multiple -s options to specify
2460 multiple such files;
2461 * A temporary directory in which one or both of
2462 "etc.tgz" and "xetc.tgz" have been extracted.
2463 [${SRC_DIR:-/usr/src}]
2464 -x xsrcdir Location of the X11 source files. This must be
2465 a directory that contains a NetBSD xsrc tree.
2466 [${XSRC_DIR:-/usr/src/../xsrc}]
2467 -d destdir Destination directory to check. [${DEST_DIR:-/}]
2468 -m mach MACHINE. [${MACHINE}]
2469 -a arch MACHINE_ARCH. [${MACHINE_ARCH}]
2470
2471 Operation may be one of:
2472 help Display this help.
2473 list List available items.
2474 check Perform post-installation checks on items.
2475 diff [diff(1) options ...]
2476 Similar to 'check' but also output difference of files.
2477 fix Apply fixes that 'check' determines need to be applied.
2478 usage Display this usage.
2479 _USAGE_
2480 exit 2
2481 }
2482
2483
2484 list()
2485 {
2486 echo "Default set of items (to apply if no items are provided by user):"
2487 echo " Item Description"
2488 echo " ---- -----------"
2489 for i in ${defaultitems}; do
2490 eval desc=\"\${desc_${i}}\"
2491 printf " %-12s %s\n" "${i}" "${desc}"
2492 done
2493 echo "Items disabled by default (must be requested explicitly):"
2494 echo " Item Description"
2495 echo " ---- -----------"
2496 for i in ${otheritems}; do
2497 eval desc=\"\${desc_${i}}\"
2498 printf " %-12s %s\n" "${i}" "${desc}"
2499 done
2500
2501 }
2502
2503
2504 main()
2505 {
2506 TGZLIST= # quoted list list of tgz files
2507 SRC_ARGLIST= # quoted list of one or more "-s" args
2508 SRC_DIR="${SRC_ARG}" # set default value for early usage()
2509 XSRC_DIR="${SRC_ARG}/../xsrc"
2510 N_SRC_ARGS=0 # number of "-s" args
2511 TGZMODE=false # true if "-s" specifies a tgz file
2512 DIRMODE=false # true if "-s" specified a directory
2513 SOURCEMODE=false # true if "-s" specified a source directory
2514
2515 case "$(uname -s)" in
2516 Darwin)
2517 # case sensitive match for case insensitive fs
2518 file_exists_exact=file_exists_exact
2519 ;;
2520 *)
2521 file_exists_exact=:
2522 ;;
2523 esac
2524
2525 while getopts s:x:d:m:a: ch; do
2526 case "${ch}" in
2527 s)
2528 qarg="$(shell_quote "${OPTARG}")"
2529 N_SRC_ARGS=$(( $N_SRC_ARGS + 1 ))
2530 SRC_ARGLIST="${SRC_ARGLIST}${SRC_ARGLIST:+ }-s ${qarg}"
2531 if [ -f "${OPTARG}" ]; then
2532 # arg refers to a *.tgz file.
2533 # This may happen twice, for both
2534 # etc.tgz and xetc.tgz, so we build up a
2535 # quoted list in TGZLIST.
2536 TGZMODE=true
2537 TGZLIST="${TGZLIST}${TGZLIST:+ }${qarg}"
2538 # Note that, when TGZMODE is true,
2539 # SRC_ARG is used only for printing
2540 # human-readable messages.
2541 SRC_ARG="${TGZLIST}"
2542 elif [ -d "${OPTARG}" ]; then
2543 # arg refers to a directory.
2544 # It might be a source directory, or a
2545 # directory where the sets have already
2546 # been extracted.
2547 DIRMODE=true
2548 SRC_ARG="${OPTARG}"
2549 if [ -f "${OPTARG}/etc/Makefile" ]; then
2550 SOURCEMODE=true
2551 fi
2552 else
2553 err 2 "Invalid argument for -s option"
2554 fi
2555 ;;
2556 x)
2557 if [ -d "${OPTARG}" ]; then
2558 # arg refers to a directory.
2559 XSRC_DIR="${OPTARG}"
2560 XSRC_DIR_FIX="-x ${OPTARG} "
2561 else
2562 err 2 "Not a directory for -x option"
2563 fi
2564 ;;
2565 d)
2566 DEST_DIR="${OPTARG}"
2567 ;;
2568 m)
2569 MACHINE="${OPTARG}"
2570 ;;
2571 a)
2572 MACHINE_ARCH="${OPTARG}"
2573 ;;
2574 *)
2575 usage
2576 ;;
2577 esac
2578 done
2579 shift $((${OPTIND} - 1))
2580 [ $# -gt 0 ] || usage
2581
2582 if [ "$N_SRC_ARGS" -gt 1 ] && $DIRMODE; then
2583 err 2 "Multiple -s args are allowed only with tgz files"
2584 fi
2585 if [ "$N_SRC_ARGS" -eq 0 ]; then
2586 # The default SRC_ARG was set elsewhere
2587 DIRMODE=true
2588 SOURCEMODE=true
2589 SRC_ARGLIST="-s $(shell_quote "${SRC_ARG}")"
2590 fi
2591
2592 #
2593 # If '-s' arg or args specified tgz files, extract them
2594 # to a scratch directory.
2595 #
2596 if $TGZMODE; then
2597 ETCTGZDIR="${SCRATCHDIR}/etc.tgz"
2598 echo "Note: Creating temporary directory ${ETCTGZDIR}"
2599 if ! mkdir "${ETCTGZDIR}"; then
2600 err 2 "Can't create ${ETCTGZDIR}"
2601 fi
2602 ( # subshell to localise changes to "$@"
2603 eval "set -- ${TGZLIST}"
2604 for tgz in "$@"; do
2605 echo "Note: Extracting files from ${tgz}"
2606 cat "${tgz}" | (
2607 cd "${ETCTGZDIR}" &&
2608 tar -zxf -
2609 ) || err 2 "Can't extract ${tgz}"
2610 done
2611 )
2612 SRC_DIR="${ETCTGZDIR}"
2613 else
2614 SRC_DIR="${SRC_ARG}"
2615 fi
2616
2617 [ -d "${SRC_DIR}" ] || err 2 "${SRC_DIR} is not a directory"
2618 [ -d "${DEST_DIR}" ] || err 2 "${DEST_DIR} is not a directory"
2619 [ -n "${MACHINE}" ] || err 2 "\${MACHINE} is not defined"
2620 [ -n "${MACHINE_ARCH}" ] || err 2 "\${MACHINE_ARCH} is not defined"
2621 if ! $SOURCEMODE && ! [ -f "${SRC_DIR}/etc/mtree/set.etc" ]; then
2622 err 2 "Files from the etc.tgz set are missing"
2623 fi
2624
2625 # If directories are /, clear them, so various messages
2626 # don't have leading "//". However, this requires
2627 # the use of ${foo:-/} to display the variables.
2628 #
2629 [ "${SRC_DIR}" = "/" ] && SRC_DIR=""
2630 [ "${DEST_DIR}" = "/" ] && DEST_DIR=""
2631
2632 detect_x11
2633
2634 op="$1"
2635 shift
2636
2637 case "${op}" in
2638 diff)
2639 op=check
2640 DIFF_STYLE=n # default style is RCS
2641 OPTIND=1
2642 while getopts bcenpuw ch; do
2643 case "${ch}" in
2644 c|e|n|u)
2645 if [ "${DIFF_STYLE}" != "n" -a \
2646 "${DIFF_STYLE}" != "${ch}" ]; then
2647 err 2 "conflicting output style: ${ch}"
2648 fi
2649 DIFF_STYLE="${ch}"
2650 ;;
2651 b|p|w)
2652 DIFF_OPT="${DIFF_OPT} -${ch}"
2653 ;;
2654 *)
2655 err 2 "unknown diff option"
2656 ;;
2657 esac
2658 done
2659 shift $((${OPTIND} - 1))
2660 ;;
2661 esac
2662
2663 case "${op}" in
2664
2665 usage|help)
2666 usage
2667 ;;
2668
2669 list)
2670 echo "Source directory: ${SRC_DIR:-/}"
2671 echo "Target directory: ${DEST_DIR:-/}"
2672 if $TGZMODE; then
2673 echo " (extracted from: ${SRC_ARG})"
2674 fi
2675 list
2676 ;;
2677
2678 check|fix)
2679 todo="$*"
2680 : ${todo:="${defaultitems}"}
2681
2682 # ensure that all supplied items are valid
2683 #
2684 for i in ${todo}; do
2685 eval desc=\"\${desc_${i}}\"
2686 [ -n "${desc}" ] || err 2 "Unsupported ${op} '"${i}"'"
2687 done
2688
2689 # perform each check/fix
2690 #
2691 echo "Source directory: ${SRC_DIR:-/}"
2692 if $TGZMODE; then
2693 echo " (extracted from: ${SRC_ARG})"
2694 fi
2695 echo "Target directory: ${DEST_DIR:-/}"
2696 items_passed=
2697 items_failed=
2698 for i in ${todo}; do
2699 echo "${i} ${op}:"
2700 ( eval do_${i} ${op} )
2701 if [ $? -eq 0 ]; then
2702 items_passed="${items_passed} ${i}"
2703 else
2704 items_failed="${items_failed} ${i}"
2705 fi
2706 done
2707
2708 if [ "${op}" = "check" ]; then
2709 plural="checks"
2710 else
2711 plural="fixes"
2712 fi
2713
2714 echo "${PROGNAME} ${plural} passed:${items_passed}"
2715 echo "${PROGNAME} ${plural} failed:${items_failed}"
2716 if [ -n "${items_failed}" ]; then
2717 exitstatus=1;
2718 if [ "${op}" = "check" ]; then
2719 [ "$MACHINE" = "$(uname -m)" ] && m= || m=" -m $MACHINE"
2720 cat <<_Fix_me_
2721 To fix, run:
2722 ${HOST_SH} ${0} ${SRC_ARGLIST} ${XSRC_DIR_FIX}-d ${DEST_DIR:-/}$m fix${items_failed}
2723 Note that this may overwrite local changes.
2724 _Fix_me_
2725 fi
2726 fi
2727
2728 ;;
2729
2730 *)
2731 warn "Unknown operation '"${op}"'"
2732 usage
2733 ;;
2734
2735 esac
2736 }
2737
2738 if [ -n "$POSTINSTALL_FUNCTION" ]; then
2739 eval "$POSTINSTALL_FUNCTION"
2740 exit 0
2741 fi
2742
2743 # defaults
2744 #
2745 PROGNAME="${0##*/}"
2746 SRC_ARG="/usr/src"
2747 DEST_DIR="/"
2748 : ${MACHINE:="$( uname -m )"} # assume native build if $MACHINE is not set
2749 : ${MACHINE_ARCH:="$( uname -p )"}# assume native build if not set
2750
2751 DIFF_STYLE=
2752 NOT_FIXED=" (FIX MANUALLY)"
2753 SCRATCHDIR="$( mkdtemp )" || err 2 "Can't create scratch directory"
2754 trap "/bin/rm -rf \"\${SCRATCHDIR}\" ; exit 0" 1 2 3 15 # HUP INT QUIT TERM
2755
2756 umask 022
2757 exec 3>/dev/null
2758 exec 4>/dev/null
2759 exitstatus=0
2760
2761 main "$@"
2762 /bin/rm -rf "${SCRATCHDIR}"
2763 exit $exitstatus
2764