postinstall.in revision 1.17 1 #!/bin/sh
2 #
3 # $NetBSD: postinstall.in,v 1.17 2020/04/02 13:44:46 roy 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 if [ ! -z "`find "${_dir}" \( ! -user "${_user}" \) -o \
742 \( ! -group "${_grp}" \)`" ]; then
743 msg \
744 "${_dir} and contents not all owned by ${_user}:${_grp}"
745 return 1
746 else
747 return 0
748 fi
749 elif [ "${_op}" = "fix" ]; then
750 find "${_dir}" \( \( ! -user "${_user}" \) -o \
751 \( ! -group "${_grp}" \) \) -a -print0 \
752 | xargs -0 chown "${_user}:${_grp}"
753 fi
754 }
755
756 # get_makevar var [var ...]
757 # Retrieve the value of a user-settable system make variable
758 get_makevar()
759 {
760 $SOURCEMODE || err 3 "get_makevar must be used in source mode"
761 [ $# -eq 0 ] && err 3 "USAGE: get_makevar var [var ...]"
762
763 for _var in "$@"; do
764 _value="$(echo '.include <bsd.own.mk>' | \
765 ${MAKE} -f - -V "\${${_var}}")"
766
767 eval ${_var}=\"\${_value}\"
768 done
769 }
770
771 # detect_x11
772 # Detect if X11 components should be analysed and set values of
773 # relevant variables.
774 detect_x11()
775 {
776 if $SOURCEMODE; then
777 get_makevar MKX11 X11ROOTDIR X11SRCDIR
778 else
779 if [ -f "${SRC_DIR}/etc/mtree/set.xetc" ]; then
780 MKX11=yes
781 X11ROOTDIR=/this/value/isnt/used/yet
782 else
783 MKX11=no
784 X11ROOTDIR=
785 fi
786 X11SRCDIR=/nonexistent/xsrc
787 fi
788 }
789
790 #
791 # find out where MAKEDEV lives, set MAKEDEV_DIR appropriately
792 #
793 find_makedev()
794 {
795 if [ -e "${DEST_DIR}/dev/MAKEDEV" ]; then
796 MAKEDEV_DIR="${DEST_DIR}/dev"
797 elif [ -e "${DEST_DIR}/etc/MAKEDEV" ]; then
798 MAKEDEV_DIR="${DEST_DIR}/etc"
799 else
800 MAKEDEV_DIR="${DEST_DIR}/dev"
801 fi
802 }
803
804
805 #
806 # items
807 # -----
808 #
809
810 #
811 # Bluetooth
812 #
813
814 additem bluetooth "Bluetooth configuration is up to date"
815 do_bluetooth()
816 {
817 [ -n "$1" ] || err 3 "USAGE: do_bluetooth fix|check"
818 op="$1"
819 failed=0
820
821 populate_dir "${op}" true \
822 "${SRC_DIR}/etc/bluetooth" "${DEST_DIR}/etc/bluetooth" 644 \
823 hosts protocols btattach.conf btdevctl.conf
824 failed=$(( ${failed} + $? ))
825
826 move_file "${op}" "${DEST_DIR}/var/db/btdev.xml" \
827 "${DEST_DIR}/var/db/btdevctl.plist"
828 failed=$(( ${failed} + $? ))
829
830 notfixed=""
831 if [ "${op}" = "fix" ]; then
832 notfixed="${NOT_FIXED}"
833 fi
834 for _v in btattach btconfig btdevctl; do
835 if rcvar_is_enabled "${_v}"; then
836 msg \
837 "${_v} is obsolete in rc.conf(5)${notfixed}: use bluetooth=YES"
838 failed=$(( ${failed} + 1 ))
839 fi
840 done
841
842 return ${failed}
843 }
844
845 #
846 # ddbonpanic
847 #
848 additem ddbonpanic "verify ddb.onpanic is configured in sysctl.conf"
849 do_ddbonpanic()
850 {
851 [ -n "$1" ] || err 3 "USAGE: do_ddbonpanic fix|check"
852
853 if ${GREP} -E '^#*[[:space:]]*ddb\.onpanic[[:space:]]*\??=[[:space:]]*[[:digit:]]+' \
854 "${DEST_DIR}/etc/sysctl.conf" >/dev/null 2>&1
855 then
856 result=0
857 else
858 if [ "$1" = check ]; then
859 msg \
860 "The ddb.onpanic behaviour is not explicitly specified in /etc/sysctl.conf"
861 result=1
862 else
863 echo >> "${DEST_DIR}/etc/sysctl.conf"
864 ${SED} < "${SRC_DIR}/etc/sysctl.conf" \
865 -e '/^ddb\.onpanic/q' | \
866 ${SED} -e '1,/^$/d' >> \
867 "${DEST_DIR}/etc/sysctl.conf"
868 result=$?
869 fi
870 fi
871 return ${result}
872 }
873
874 #
875 # defaults
876 #
877 additem defaults "/etc/defaults/ being up to date"
878 do_defaults()
879 {
880 [ -n "$1" ] || err 3 "USAGE: do_defaults fix|check"
881 local op="$1"
882 local failed=0
883 local etcsets=$(getetcsets)
884
885 local rc_exclude_scripts=""
886 if $SOURCEMODE; then
887 # For most architectures rc.conf(5) should be the same as the
888 # one obtained from a source directory, except for the ones
889 # that have an append file for it.
890 local rc_conf_app="${SRC_DIR}/etc/etc.${MACHINE}/rc.conf.append"
891 if [ -f "${rc_conf_app}" ]; then
892 rc_exclude_scripts="rc.conf"
893
894 # Generate and compare the correct rc.conf(5) file
895 mkdir "${SCRATCHDIR}/defaults"
896
897 cat "${SRC_DIR}/etc/defaults/rc.conf" "${rc_conf_app}" \
898 > "${SCRATCHDIR}/defaults/rc.conf"
899
900 compare_dir "${op}" "${SCRATCHDIR}/defaults" \
901 "${DEST_DIR}/etc/defaults" \
902 444 \
903 "rc.conf"
904 failed=$(( ${failed} + $? ))
905 fi
906 fi
907
908 find_file_in_dirlist pf.boot.conf "pf.boot.conf" \
909 "${SRC_DIR}/usr.sbin/pf/etc/defaults" "${SRC_DIR}/etc/defaults" \
910 || return 1
911 # ${dir} is set by find_file_in_dirlist()
912 compare_dir "$op" "${dir}" "${DEST_DIR}/etc/defaults" 444 pf.boot.conf
913 failed=$(( ${failed} + $? ))
914
915 rc_exclude_scripts="${rc_exclude_scripts} pf.boot.conf"
916
917 local rc_default_conf_files="$(select_set_files /etc/defaults/ \
918 "/etc/defaults/\([^[:space:]]*\.conf\)" ${etcsets} | \
919 exclude ${rc_exclude_scripts})"
920 compare_dir "$op" "${SRC_DIR}/etc/defaults" "${DEST_DIR}/etc/defaults" \
921 444 \
922 ${rc_default_conf_files}
923 failed=$(( ${failed} + $? ))
924
925
926 return ${failed}
927 }
928
929 #
930 # dhcpcd
931 #
932 additem dhcpcd "dhcpcd configuration is up to date"
933 do_dhcpcd()
934 {
935 [ -n "$1" ] || err 3 "USAGE: do_dhcpcd fix|check"
936 op="$1"
937 failed=0
938
939 find_file_in_dirlist dhcpcd.conf "dhcpcd.conf" \
940 "${SRC_DIR}/external/bsd/dhcpcd/dist/src" \
941 "${SRC_DIR}/etc" || return 1
942 # ${dir} is set by find_file_in_dirlist()
943 populate_dir "$op" true "${dir}" "${DEST_DIR}/etc" 644 dhcpcd.conf
944 failed=$(( ${failed} + $? ))
945
946 dstdir="${DESTDIR}/var/chroot/dhcpcd"
947
948 check_dir "${op}" "${dstdir}/var/db/dhcpcd" 755
949 failed=$(( ${failed} + $? ))
950
951 move_file "${op}" \
952 "${DEST_DIR}/etc/dhcpcd.duid" \
953 "${dstdir}/var/db/dhcpcd/duid"
954 failed=$(( ${failed} + $? ))
955
956 move_file "${op}" \
957 "${DEST_DIR}/etc/dhcpcd.secret" \
958 "${dstdir}/var/db/dhcpcd/secret"
959 failed=$(( ${failed} + $? ))
960
961 move_file "${op}" \
962 "${DEST_DIR}/var/db/dhcpcd-rdm.monotonic" \
963 "${dstdir}/var/db/dhcpcd/rdm_monotonic"
964 failed=$(( ${failed} + $? ))
965
966 for lease in "${DEST_DIR}/var/db/dhcpcd-"*.lease*; do
967 [ -f "${lease}" ] || continue
968 new_lease=$(basename "${lease}" | ${SED} -e 's/dhcpcd-//')
969 new_lease="${dstdir}/var/db/dhcpcd/${new_lease}"
970 move_file "${op}" "${lease}" "${new_lease}"
971 failed=$(( ${failed} + $? ))
972 done
973
974 move_file "${op}" \
975 "${DEST_DIR}/var/db/dhcpcd/duid" \
976 "${dstdir}/var/db/dhcpcd/duid"
977 failed=$(( ${failed} + $? ))
978
979 move_file "${op}" \
980 "${DEST_DIR}/var/db/dhcpcd/secret" \
981 "${dstdir}/var/db/dhcpcd/secret"
982 failed=$(( ${failed} + $? ))
983
984 move_file "${op}" \
985 "${DEST_DIR}/var/db/dhcpcd/rdm_monotonic" \
986 "${dstdir}/var/db/dhcpcd/rdm_monotonic"
987 failed=$(( ${failed} + $? ))
988
989 for lease in "${DEST_DIR}/var/db/dhcpcd/"*.lease*; do
990 [ -f "${lease}" ] || continue
991 new_lease="${dstdir}/var/db/dhcpcd/$(basename ${lease})"
992 move_file "${op}" "${lease}" "${new_lease}"
993 failed=$(( ${failed} + $? ))
994 done
995
996 contents_owner "${op}" "${dstdir}/var/db/dhcpcd" _dhcpcd _dhcpcd
997 failed=$(( ${failed} + $? ))
998
999 return ${failed}
1000 }
1001
1002 #
1003 # dhcpcdrundir
1004 #
1005 additem dhcpcdrundir "accidentaly created /@RUNDIR@ does not exist"
1006 do_dhcpcdrundir()
1007 {
1008 [ -n "$1" ] || err 3 "USAGE: do_dhcpcdrundir fix|check"
1009 op="$1"
1010 failed=0
1011
1012 if [ -d "${DEST_DIR}/@RUNDIR@" ]; then
1013 if [ "${op}" = "check" ]; then
1014 msg "Remove eroneously created /@RUNDIR@"
1015 failed=1
1016 elif ! rm -r "${DEST_DIR}/@RUNDIR@"; then
1017 msg "Failed to remove ${DEST_DIR}/@RUNDIR@"
1018 failed=1
1019 else
1020 msg "Removed eroneously created ${DEST_DIR}/@RUNDIR@"
1021 fi
1022 fi
1023 return ${failed}
1024 }
1025
1026 #
1027 # envsys
1028 #
1029 additem envsys "envsys configuration is up to date"
1030 do_envsys()
1031 {
1032 [ -n "$1" ] || err 3 "USAGE: do_envsys fix|check"
1033 local op="$1"
1034 local failed=0
1035 local etcsets=$(getetcsets)
1036
1037 populate_dir "$op" true "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
1038 envsys.conf
1039 failed=$(( ${failed} + $? ))
1040
1041 local powerd_scripts="$(select_set_files /etc/powerd/scripts/ \
1042 "/etc/powerd/scripts/\([^[:space:]/]*\)" ${etcsets})"
1043
1044 populate_dir "$op" true "${SRC_DIR}/etc/powerd/scripts" \
1045 "${DEST_DIR}/etc/powerd/scripts" \
1046 555 \
1047 ${powerd_scripts}
1048 failed=$(( ${failed} + $? ))
1049
1050 return ${failed}
1051 }
1052
1053 #
1054 # autofs config files
1055 #
1056 additem autofsconfig "automounter configuration files"
1057 do_autofsconfig()
1058 {
1059 [ -n "$1" ] || err 3 "USAGE: do_autofsconfig fix|check"
1060 local autofs_files="
1061 include_ldap
1062 include_nis
1063 special_hosts
1064 special_media
1065 special_noauto
1066 special_null
1067 "
1068 op="$1"
1069 failed=0
1070 if [ "$op" = "fix" ]; then
1071 mkdir -p "${DEST_DIR}/etc/autofs"
1072 fi
1073 failed=$(( ${failed} + $? ))
1074 populate_dir "$op" false "${SRC_DIR}/etc" \
1075 "${DEST_DIR}/etc" \
1076 644 \
1077 auto_master
1078 failed=$(( ${failed} + $? ))
1079 populate_dir "$op" false "${SRC_DIR}/etc/autofs" \
1080 "${DEST_DIR}/etc/autofs" \
1081 644 \
1082 ${autofs_files}
1083 return ${failed}
1084 }
1085
1086
1087 #
1088 # X11 fontconfig
1089 #
1090 additem fontconfig "X11 font configuration is up to date"
1091 do_fontconfig()
1092 {
1093 [ -n "$1" ] || err 3 "USAGE: do_fontconfig fix|check"
1094 op="$1"
1095 failed=0
1096
1097 # First, check for updates we can handle.
1098 if ! $SOURCEMODE; then
1099 FONTCONFIG_DIR="${SRC_DIR}/etc/fonts/conf.avail"
1100 else
1101 FONTCONFIG_DIR="${XSRC_DIR}/external/mit/fontconfig/dist/conf.d"
1102 fi
1103
1104 if [ ! -d "${FONTCONFIG_DIR}" ]; then
1105 msg "${FONTCONFIG_DIR} is not a directory; skipping check"
1106 return 0
1107 fi
1108 local regular_fonts="
1109 10-autohint.conf
1110 10-no-sub-pixel.conf
1111 10-scale-bitmap-fonts.conf
1112 10-sub-pixel-bgr.conf
1113 10-sub-pixel-rgb.conf
1114 10-sub-pixel-vbgr.conf
1115 10-sub-pixel-vrgb.conf
1116 10-unhinted.conf
1117 11-lcdfilter-default.conf
1118 11-lcdfilter-legacy.conf
1119 11-lcdfilter-light.conf
1120 20-unhint-small-vera.conf
1121 25-unhint-nonlatin.conf
1122 30-metric-aliases.conf
1123 40-nonlatin.conf
1124 45-generic.conf
1125 45-latin.conf
1126 49-sansserif.conf
1127 50-user.conf
1128 51-local.conf
1129 60-generic.conf
1130 60-latin.conf
1131 65-fonts-persian.conf
1132 65-khmer.conf
1133 65-nonlatin.conf
1134 69-unifont.conf
1135 70-no-bitmaps.conf
1136 70-yes-bitmaps.conf
1137 80-delicious.conf
1138 90-synthetic.conf
1139 "
1140 populate_dir "$op" false "${FONTCONFIG_DIR}" \
1141 "${DEST_DIR}/etc/fonts/conf.avail" \
1142 444 \
1143 ${regular_fonts}
1144 failed=$(( ${failed} + $? ))
1145
1146 if ! $SOURCEMODE; then
1147 FONTS_DIR="${SRC_DIR}/etc/fonts"
1148 else
1149 FONTS_DIR="${SRC_DIR}/external/mit/xorg/lib/fontconfig/etc"
1150 fi
1151
1152 populate_dir "$op" false "${FONTS_DIR}" "${DEST_DIR}/etc/fonts" 444 \
1153 fonts.conf
1154 failed=$(( ${failed} + $? ))
1155
1156 # We can't modify conf.d easily; someone might have removed a file.
1157
1158 # Look for old files that need to be deleted.
1159 obsolete_fonts="
1160 10-autohint.conf
1161 10-no-sub-pixel.conf
1162 10-sub-pixel-bgr.conf
1163 10-sub-pixel-rgb.conf
1164 10-sub-pixel-vbgr.conf
1165 10-sub-pixel-vrgb.conf
1166 10-unhinted.conf
1167 25-unhint-nonlatin.conf
1168 65-khmer.conf
1169 70-no-bitmaps.conf
1170 70-yes-bitmaps.conf
1171 "
1172 failed_fonts=""
1173 for i in ${obsolete_fonts}; do
1174 if [ -f "${DEST_DIR}/etc/fonts/conf.d/$i" ]; then
1175 conf_d_failed=1
1176 failed_fonts="$failed_fonts $i"
1177 fi
1178 done
1179
1180 if [ -n "$failed_fonts" ]; then
1181 msg \
1182 "Broken fontconfig configuration found; please delete these files:"
1183 msg "[$failed_fonts]"
1184 failed=$(( ${failed} + 1 ))
1185 fi
1186
1187 return ${failed}
1188 }
1189
1190 #
1191 # gid
1192 #
1193 additem gid "required groups in /etc/group"
1194 do_gid()
1195 {
1196 [ -n "$1" ] || err 3 "USAGE: do_gid fix|check"
1197
1198 check_ids "$1" groups "${DEST_DIR}/etc/group" \
1199 "${SRC_DIR}/etc/group" 14 \
1200 named ntpd sshd SKIP _pflogd _rwhod staff _proxy _timedc \
1201 _sdpd _httpd _mdnsd _tests _tcpdump _tss _gpio _rtadvd SKIP \
1202 _unbound _nsd nvmm _dhcpcd
1203 }
1204
1205 #
1206 # gpio
1207 #
1208 additem gpio "gpio configuration is up to date"
1209 do_gpio()
1210 {
1211 [ -n "$1" ] || err 3 "USAGE: do_gpio fix|check"
1212 op="$1"
1213 failed=0
1214
1215 populate_dir "$op" true "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
1216 gpio.conf
1217 failed=$(( ${failed} + $? ))
1218
1219 return ${failed}
1220 }
1221
1222 #
1223 # hosts
1224 #
1225 additem hosts "/etc/hosts being up to date"
1226 do_hosts()
1227 {
1228 [ -n "$1" ] || err 3 "USAGE: do_hosts fix|check"
1229
1230 modify_file "$1" "${DEST_DIR}/etc/hosts" "${SCRATCHDIR}/hosts" '
1231 /^(127\.0\.0\.1|::1)[ ]+[^\.]*$/ {
1232 print $0, "localhost."
1233 next
1234 }
1235 { print }
1236 '
1237 return $?
1238 }
1239
1240 #
1241 # iscsi
1242 #
1243 additem iscsi "/etc/iscsi is populated"
1244 do_iscsi()
1245 {
1246 [ -n "$1" ] || err 3 "USAGE: do_iscsi fix|check"
1247
1248 populate_dir "${op}" true \
1249 "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 600 auths
1250 populate_dir "${op}" true \
1251 "${SRC_DIR}/etc/iscsi" "${DEST_DIR}/etc/iscsi" 644 targets
1252 return $?
1253 }
1254
1255 #
1256 # makedev
1257 #
1258 additem makedev "/dev/MAKEDEV being up to date"
1259 do_makedev()
1260 {
1261 [ -n "$1" ] || err 3 "USAGE: do_makedev fix|check"
1262 failed=0
1263
1264 if [ -f "${SRC_DIR}/etc/MAKEDEV.tmpl" ]; then
1265 # generate MAKEDEV from source if source is available
1266 env MACHINE="${MACHINE}" \
1267 MACHINE_ARCH="${MACHINE_ARCH}" \
1268 NETBSDSRCDIR="${SRC_DIR}" \
1269 ${AWK} -f "${SRC_DIR}/etc/MAKEDEV.awk" \
1270 "${SRC_DIR}/etc/MAKEDEV.tmpl" > "${SCRATCHDIR}/MAKEDEV"
1271 fi
1272
1273 find_file_in_dirlist MAKEDEV "MAKEDEV" \
1274 "${SCRATCHDIR}" "${SRC_DIR}/dev" \
1275 || return 1
1276 # ${dir} is set by find_file_in_dirlist()
1277 find_makedev
1278 compare_dir "$1" "${dir}" "${MAKEDEV_DIR}" 555 MAKEDEV
1279 failed=$(( ${failed} + $? ))
1280
1281 find_file_in_dirlist MAKEDEV.local "MAKEDEV.local" \
1282 "${SRC_DIR}/etc" "${SRC_DIR}/dev" \
1283 || return 1
1284 # ${dir} is set by find_file_in_dirlist()
1285 compare_dir "$1" "${dir}" "${DEST_DIR}/dev" 555 MAKEDEV.local
1286 failed=$(( ${failed} + $? ))
1287
1288 return ${failed}
1289 }
1290
1291 #
1292 # motd
1293 #
1294 additem motd "contents of motd"
1295 do_motd()
1296 {
1297 [ -n "$1" ] || err 3 "USAGE: do_motd fix|check"
1298
1299 if ${GREP} -i 'http://www.NetBSD.org/Misc/send-pr.html' \
1300 "${DEST_DIR}/etc/motd" >/dev/null 2>&1 \
1301 || ${GREP} -i 'https*://www.NetBSD.org/support/send-pr.html' \
1302 "${DEST_DIR}/etc/motd" >/dev/null 2>&1
1303 then
1304 tmp1="$(mktemp /tmp/postinstall.motd.XXXXXXXX)"
1305 tmp2="$(mktemp /tmp/postinstall.motd.XXXXXXXX)"
1306 ${SED} '1,2d' <"${SRC_DIR}/etc/motd" >"${tmp1}"
1307 ${SED} '1,2d' <"${DEST_DIR}/etc/motd" >"${tmp2}"
1308
1309 if [ "$1" = check ]; then
1310 cmp -s "${tmp1}" "${tmp2}"
1311 result=$?
1312 if [ "${result}" -ne 0 ]; then
1313 msg \
1314 "Bug reporting messages do not seem to match the installed release"
1315 fi
1316 else
1317 head -n 2 "${DEST_DIR}/etc/motd" >"${tmp1}"
1318 ${SED} '1,2d' <"${SRC_DIR}/etc/motd" >>"${tmp1}"
1319 cp "${tmp1}" "${DEST_DIR}/etc/motd"
1320 result=0
1321 fi
1322
1323 rm -f "${tmp1}" "${tmp2}"
1324 else
1325 result=0
1326 fi
1327
1328 return ${result}
1329 }
1330
1331 #
1332 # mtree
1333 #
1334 additem mtree "/etc/mtree/ being up to date"
1335 do_mtree()
1336 {
1337 [ -n "$1" ] || err 3 "USAGE: do_mtree fix|check"
1338 failed=0
1339
1340 compare_dir "$1" "${SRC_DIR}/etc/mtree" "${DEST_DIR}/etc/mtree" 444 special
1341 failed=$(( ${failed} + $? ))
1342
1343 if ! $SOURCEMODE; then
1344 MTREE_DIR="${SRC_DIR}/etc/mtree"
1345 else
1346 /bin/rm -rf "${SCRATCHDIR}/obj"
1347 mkdir "${SCRATCHDIR}/obj"
1348 ${MAKE} -s -C "${SRC_DIR}/etc/mtree" TOOL_AWK="${AWK}" \
1349 MAKEOBJDIR="${SCRATCHDIR}/obj" emit_dist_file > \
1350 "${SCRATCHDIR}/NetBSD.dist"
1351 MTREE_DIR="${SCRATCHDIR}"
1352 /bin/rm -rf "${SCRATCHDIR}/obj"
1353 fi
1354 compare_dir "$1" "${MTREE_DIR}" "${DEST_DIR}/etc/mtree" 444 NetBSD.dist
1355 failed=$(( ${failed} + $? ))
1356
1357 return ${failed}
1358 }
1359
1360 #
1361 # named
1362 #
1363 additem named "named configuration update"
1364 do_named()
1365 {
1366 [ -n "$1" ] || err 3 "USAGE: do_named fix|check"
1367 op="$1"
1368
1369 move_file "${op}" \
1370 "${DEST_DIR}/etc/namedb/named.conf" \
1371 "${DEST_DIR}/etc/named.conf"
1372
1373 compare_dir "${op}" "${SRC_DIR}/etc/namedb" "${DEST_DIR}/etc/namedb" \
1374 644 \
1375 root.cache
1376 }
1377
1378 #
1379 # pam
1380 #
1381 additem pam "/etc/pam.d is populated"
1382 do_pam()
1383 {
1384 [ -n "$1" ] || err 3 "USAGE: do_pam fix|check"
1385 op="$1"
1386 failed=0
1387
1388 populate_dir "${op}" true "${SRC_DIR}/etc/pam.d" \
1389 "${DEST_DIR}/etc/pam.d" 644 \
1390 README cron display_manager ftpd gdm imap kde login other \
1391 passwd pop3 ppp racoon rexecd rsh sshd su system telnetd \
1392 xdm xserver
1393
1394 failed=$(( ${failed} + $? ))
1395
1396 return ${failed}
1397 }
1398
1399 #
1400 # periodic
1401 #
1402 additem periodic "/etc/{daily,weekly,monthly,security} being up to date"
1403 do_periodic()
1404 {
1405 [ -n "$1" ] || err 3 "USAGE: do_periodic fix|check"
1406
1407 compare_dir "$1" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
1408 daily weekly monthly security
1409 }
1410
1411 #
1412 # pf
1413 #
1414 additem pf "pf configuration being up to date"
1415 do_pf()
1416 {
1417 [ -n "$1" ] || err 3 "USAGE: do_pf fix|check"
1418 op="$1"
1419 failed=0
1420
1421 find_file_in_dirlist pf.os "pf.os" \
1422 "${SRC_DIR}/dist/pf/etc" "${SRC_DIR}/etc" \
1423 || return 1
1424 # ${dir} is set by find_file_in_dirlist()
1425 populate_dir "${op}" true \
1426 "${dir}" "${DEST_DIR}/etc" 644 \
1427 pf.conf
1428 failed=$(( ${failed} + $? ))
1429
1430 compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 pf.os
1431 failed=$(( ${failed} + $? ))
1432
1433 return ${failed}
1434 }
1435
1436 #
1437 # pwd_mkdb
1438 #
1439 additem pwd_mkdb "passwd database version"
1440 do_pwd_mkdb()
1441 {
1442 [ -n "$1" ] || err 3 "USAGE: do_pwd_mkdb fix|check"
1443 op="$1"
1444 failed=0
1445
1446 # XXX Ideally, we should figure out the endianness of the
1447 # target machine, and add "-E B"/"-E L" to the db(1) flags,
1448 # and "-B"/"-L" to the pwd_mkdb(8) flags if the target is not
1449 # the same as the host machine. It probably doesn't matter,
1450 # because we don't expect "postinstall fix pwd_mkdb" to be
1451 # invoked during a cross build.
1452
1453 set -- $(${DB} -q -Sb -Ub -To -N hash "${DEST_DIR}/etc/pwd.db" \
1454 'VERSION\0')
1455 case "$2" in
1456 '\001\000\000\000') return 0 ;; # version 1, little-endian
1457 '\000\000\000\001') return 0 ;; # version 1, big-endian
1458 esac
1459
1460 if [ "${op}" = "check" ]; then
1461 msg "Update format of passwd database"
1462 failed=1
1463 elif ! ${PWD_MKDB} -V 1 -d "${DEST_DIR:-/}" \
1464 "${DEST_DIR}/etc/master.passwd";
1465 then
1466 msg "Can't update format of passwd database"
1467 failed=1
1468 else
1469 msg "Updated format of passwd database"
1470 fi
1471
1472 return ${failed}
1473 }
1474
1475 #
1476 # rc
1477 #
1478
1479 # There is no info in src/distrib or /etc/mtree which rc* files
1480 # can be overwritten unconditionally on upgrade. See PR/54741.
1481 rc_644_files="
1482 rc
1483 rc.subr
1484 rc.shutdown
1485 "
1486
1487 rc_obsolete_vars="
1488 amd amd_master
1489 btcontrol btcontrol_devices
1490 critical_filesystems critical_filesystems_beforenet
1491 mountcritlocal mountcritremote
1492 network ip6forwarding
1493 network nfsiod_flags
1494 sdpd sdpd_control
1495 sdpd sdpd_groupname
1496 sdpd sdpd_username
1497 sysctl defcorename
1498 "
1499
1500 update_rc()
1501 {
1502 local op=$1
1503 local dir=$2
1504 local name=$3
1505 local bindir=$4
1506 local rcdir=$5
1507
1508 if [ ! -x "${DEST_DIR}/${bindir}/${name}" ]; then
1509 return 0
1510 fi
1511
1512 if ! find_file_in_dirlist "${name}" "${name}" \
1513 "${rcdir}" "${SRC_DIR}/etc/rc.d"; then
1514 return 1
1515 fi
1516 populate_dir "${op}" false "${dir}" "${DEST_DIR}/etc/rc.d" 555 "${name}"
1517 return $?
1518 }
1519
1520 # select non-obsolete files in a sets file
1521 # $1: directory pattern
1522 # $2: file pattern
1523 # $3: filename
1524 select_set_files()
1525 {
1526 local qdir="$(echo $1 | ${SED} -e s@/@\\\\/@g -e s/\\./\\\\./g)"
1527 ${SED} -n -e /obsolete/d \
1528 -e "/^\.${qdir}/s@^.$2[[:space:]].*@\1@p" $3
1529 }
1530
1531 # select obsolete files in a sets file
1532 # $1: directory pattern
1533 # $2: file pattern
1534 # $3: setname
1535 select_obsolete_files()
1536 {
1537 if $SOURCEMODE; then
1538 ${SED} -n -e "/obsolete/s@\.$1$2[[:space:]].*@\1@p" \
1539 ${SRC_DIR}/distrib/sets/lists/$3/mi
1540 return
1541 fi
1542
1543 # On upgrade builds we don't extract the "etc" set so we
1544 # try to use the source set instead. See PR/54730 for
1545 # ways to better handle this.
1546
1547 local obsolete_dir
1548
1549 if [ $3 = "etc" ] ;then
1550 obsolete_dir=${SRC_DIR}/var/db/obsolete
1551 else
1552 obsolete_dir=${DEST_DIR}/var/db/obsolete
1553 fi
1554 ${SED} -n -e "s@\.$1$2\$@\1@p" "${obsolete_dir}/$3"
1555 }
1556
1557 getetcsets()
1558 {
1559 if $SOURCEMODE; then
1560 echo "${SRC_DIR}/distrib/sets/lists/etc/mi"
1561 else
1562 echo "${SRC_DIR}/etc/mtree/set.etc"
1563 fi
1564 }
1565
1566 additem rc "/etc/rc* and /etc/rc.d/ being up to date"
1567 do_rc()
1568 {
1569 [ -n "$1" ] || err 3 "USAGE: do_rc fix|check"
1570 local op="$1"
1571 local failed=0
1572 local generated_scripts=""
1573 local etcsets=$(getetcsets)
1574 if [ "${MKX11}" != "no" ]; then
1575 generated_scripts="${generated_scripts} xdm xfs"
1576 fi
1577
1578 # Directories of external programs that have rc files (in bsd)
1579 local rc_external_files="blacklist nsd unbound"
1580
1581 # rc* files in /etc/
1582 # XXX: at least rc.conf and rc.local shouldn't be updated. PR/54741
1583 #local rc_644_files="$(select_set_files /etc/rc \
1584 # "/etc/\(rc[^[:space:]/]*\)" ${etcsets})"
1585
1586 # no-obsolete rc files in /etc/rc.d
1587 local rc_555_files="$(select_set_files /etc/rc.d/ \
1588 "/etc/rc\.d/\([^[:space:]]*\)" ${etcsets} | \
1589 exclude ${rc_external_files})"
1590
1591 # obsolete rc file in /etc/rc.d
1592 local rc_obsolete_files="$(select_obsolete_files /etc/rc.d/ \
1593 "\([^[:space:]]*\)" etc)"
1594
1595 compare_dir "${op}" "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 \
1596 ${rc_644_files}
1597 failed=$(( ${failed} + $? ))
1598
1599 local extra_scripts
1600 if ! $SOURCEMODE; then
1601 extra_scripts="${generated_scripts}"
1602 else
1603 extra_scripts=""
1604 fi
1605
1606 compare_dir "${op}" "${SRC_DIR}/etc/rc.d" "${DEST_DIR}/etc/rc.d" 555 \
1607 ${rc_555_files} \
1608 ${extra_scripts}
1609 failed=$(( ${failed} + $? ))
1610
1611 for i in ${rc_external_files}; do
1612 local rc_file
1613 case $i in
1614 *d) rc_file=${i};;
1615 *) rc_file=${i}d;;
1616 esac
1617
1618 update_rc "${op}" "${dir}" ${rc_file} /sbin \
1619 "${SRC_DIR}/external/bsd/$i/etc/rc.d"
1620 failed=$(( ${failed} + $? ))
1621 done
1622
1623 if $SOURCEMODE && [ -n "${generated_scripts}" ]; then
1624 # generate scripts
1625 mkdir "${SCRATCHDIR}/rc"
1626 for f in ${generated_scripts}; do
1627 ${SED} -e "s,@X11ROOTDIR@,${X11ROOTDIR},g" \
1628 < "${SRC_DIR}/etc/rc.d/${f}.in" \
1629 > "${SCRATCHDIR}/rc/${f}"
1630 done
1631 compare_dir "${op}" "${SCRATCHDIR}/rc" \
1632 "${DEST_DIR}/etc/rc.d" 555 \
1633 ${generated_scripts}
1634 failed=$(( ${failed} + $? ))
1635 fi
1636
1637 # check for obsolete rc.d files
1638 for f in ${rc_obsolete_files}; do
1639 local fd="/etc/rc.d/${f}"
1640 [ -e "${DEST_DIR}${fd}" ] && echo "${fd}"
1641 done | obsolete_paths "${op}"
1642 failed=$(( ${failed} + $? ))
1643
1644 # check for obsolete rc.conf(5) variables
1645 set -- ${rc_obsolete_vars}
1646 while [ $# -gt 1 ]; do
1647 if rcconf_is_set "${op}" "$1" "$2" 1; then
1648 failed=1
1649 fi
1650 shift 2
1651 done
1652
1653 return ${failed}
1654 }
1655
1656 #
1657 # sendmail
1658 #
1659 adddisableditem sendmail "remove obsolete sendmail configuration files and scripts"
1660 do_sendmail()
1661 {
1662 [ -n "$1" ] || err 3 "USAGE: do_sendmail fix|check"
1663 op="$1"
1664 failed=0
1665
1666 # Don't complain if the "sendmail" package is installed because the
1667 # files might still be in use.
1668 if /usr/sbin/pkg_info -qe sendmail >/dev/null 2>&1; then
1669 return 0
1670 fi
1671
1672 for f in /etc/mail/helpfile /etc/mail/local-host-names \
1673 /etc/mail/sendmail.cf /etc/mail/submit.cf /etc/rc.d/sendmail \
1674 /etc/rc.d/smmsp /usr/share/misc/sendmail.hf \
1675 $( ( find "${DEST_DIR}/usr/share/sendmail" -type f ; \
1676 find "${DEST_DIR}/usr/share/sendmail" -type d \
1677 ) | unprefix "${DEST_DIR}" ) \
1678 /var/log/sendmail.st \
1679 /var/spool/clientmqueue \
1680 /var/spool/mqueue
1681 do
1682 [ -e "${DEST_DIR}${f}" ] && echo "${f}"
1683 done | obsolete_paths "${op}"
1684 failed=$(( ${failed} + $? ))
1685
1686 return ${failed}
1687 }
1688
1689 #
1690 # mailerconf
1691 #
1692 adddisableditem mailerconf "update /etc/mailer.conf after sendmail removal"
1693 do_mailerconf()
1694 {
1695 [ -n "$1" ] || err 3 "USAGE: do_mailterconf fix|check"
1696 op="$1"
1697
1698 failed=0
1699 mta_path="$(${AWK} '/^sendmail[ \t]/{print$2}' \
1700 "${DEST_DIR}/etc/mailer.conf")"
1701 old_sendmail_path="/usr/libexec/sendmail/sendmail"
1702 if [ "${mta_path}" = "${old_sendmail_path}" ]; then
1703 if [ "$op" = check ]; then
1704 msg "mailer.conf points to obsolete ${old_sendmail_path}"
1705 failed=1;
1706 else
1707 populate_dir "${op}" false \
1708 "${SRC_DIR}/etc" "${DEST_DIR}/etc" 644 mailer.conf
1709 failed=$?
1710 fi
1711 fi
1712
1713 return ${failed}
1714 }
1715
1716 #
1717 # ssh
1718 #
1719 additem ssh "ssh configuration update"
1720 do_ssh()
1721 {
1722 [ -n "$1" ] || err 3 "USAGE: do_ssh fix|check"
1723 op="$1"
1724
1725 failed=0
1726 _etcssh="${DEST_DIR}/etc/ssh"
1727 if ! check_dir "${op}" "${_etcssh}" 755; then
1728 failed=1
1729 fi
1730
1731 if [ ${failed} -eq 0 ]; then
1732 for f in \
1733 ssh_known_hosts ssh_known_hosts2 \
1734 ssh_host_dsa_key ssh_host_dsa_key.pub \
1735 ssh_host_rsa_key ssh_host_rsa_key.pub \
1736 ssh_host_key ssh_host_key.pub \
1737 ; do
1738 if ! move_file "${op}" \
1739 "${DEST_DIR}/etc/${f}" "${_etcssh}/${f}" ; then
1740 failed=1
1741 fi
1742 done
1743 for f in sshd.conf ssh.conf ; do
1744 # /etc/ssh/ssh{,d}.conf -> ssh{,d}_config
1745 #
1746 if ! move_file "${op}" \
1747 "${_etcssh}/${f}" "${_etcssh}/${f%.conf}_config" ;
1748 then
1749 failed=1
1750 fi
1751 # /etc/ssh{,d}.conf -> /etc/ssh/ssh{,d}_config
1752 #
1753 if ! move_file "${op}" \
1754 "${DEST_DIR}/etc/${f}" \
1755 "${_etcssh}/${f%.conf}_config" ;
1756 then
1757 failed=1
1758 fi
1759 done
1760 fi
1761
1762 sshdconf=""
1763 for f in \
1764 "${_etcssh}/sshd_config" \
1765 "${_etcssh}/sshd.conf" \
1766 "${DEST_DIR}/etc/sshd.conf" ; do
1767 if [ -f "${f}" ]; then
1768 sshdconf="${f}"
1769 break
1770 fi
1771 done
1772 if [ -n "${sshdconf}" ]; then
1773 modify_file "${op}" "${sshdconf}" "${SCRATCHDIR}/sshdconf" '
1774 /^[^#$]/ {
1775 kw = tolower($1)
1776 if (kw == "hostkey" &&
1777 $2 ~ /^\/etc\/+ssh_host(_[dr]sa)?_key$/ ) {
1778 sub(/\/etc\/+/, "/etc/ssh/")
1779 }
1780 if (kw == "rhostsauthentication" ||
1781 kw == "verifyreversemapping" ||
1782 kw == "reversemappingcheck") {
1783 sub(/^/, "# DEPRECATED:\t")
1784 }
1785 }
1786 { print }
1787 '
1788 failed=$(( ${failed} + $? ))
1789 fi
1790
1791 if ! find_file_in_dirlist moduli "moduli" \
1792 "${SRC_DIR}/crypto/external/bsd/openssh/dist" "${SRC_DIR}/etc" ; then
1793 failed=1
1794 # ${dir} is set by find_file_in_dirlist()
1795 elif ! compare_dir "${op}" "${dir}" "${DEST_DIR}/etc" 444 moduli; then
1796 failed=1
1797 fi
1798
1799 if ! check_dir "${op}" "${DEST_DIR}/var/chroot/sshd" 755 ; then
1800 failed=1
1801 fi
1802
1803 if rcconf_is_set "${op}" sshd sshd_conf_dir 1; then
1804 failed=1
1805 fi
1806
1807 return ${failed}
1808 }
1809
1810 #
1811 # wscons
1812 #
1813 additem wscons "wscons configuration file update"
1814 do_wscons()
1815 {
1816 [ -n "$1" ] || err 3 "USAGE: do_wscons fix|check"
1817 op="$1"
1818
1819 [ -f "${DEST_DIR}/etc/wscons.conf" ] || return 0
1820
1821 failed=0
1822 notfixed=""
1823 if [ "${op}" = "fix" ]; then
1824 notfixed="${NOT_FIXED}"
1825 fi
1826 while read _type _arg1 _rest; do
1827 if [ "${_type}" = "mux" -a "${_arg1}" = "1" ]; then
1828 msg \
1829 "Obsolete wscons.conf(5) entry \""${_type} ${_arg1}"\" found.${notfixed}"
1830 failed=1
1831 fi
1832 done < "${DEST_DIR}/etc/wscons.conf"
1833
1834 return ${failed}
1835 }
1836
1837 #
1838 # X11
1839 #
1840 additem x11 "x11 configuration update"
1841 do_x11()
1842 {
1843 [ -n "$1" ] || err 3 "USAGE: do_x11 fix|check"
1844 op="$1"
1845
1846 failed=0
1847 _etcx11="${DEST_DIR}/etc/X11"
1848 if [ ! -d "${_etcx11}" ]; then
1849 msg "${_etcx11} is not a directory; skipping check"
1850 return 0
1851 fi
1852 if [ -d "${DEST_DIR}/usr/X11R6/." ]
1853 then
1854 _libx11="${DEST_DIR}/usr/X11R6/lib/X11"
1855 if [ ! -d "${_libx11}" ]; then
1856 msg "${_libx11} is not a directory; skipping check"
1857 return 0
1858 fi
1859 fi
1860
1861 _notfixed=""
1862 if [ "${op}" = "fix" ]; then
1863 _notfixed="${NOT_FIXED}"
1864 fi
1865
1866 for d in \
1867 fs lbxproxy proxymngr rstart twm xdm xinit xserver xsm \
1868 ; do
1869 sd="${_libx11}/${d}"
1870 ld="/etc/X11/${d}"
1871 td="${DEST_DIR}${ld}"
1872 if [ -h "${sd}" ]; then
1873 continue
1874 elif [ -d "${sd}" ]; then
1875 tdfiles="$(find "${td}" \! -type d)"
1876 if [ -n "${tdfiles}" ]; then
1877 msg "${sd} exists yet ${td} already" \
1878 "contains files${_notfixed}"
1879 else
1880 msg "Migrate ${sd} to ${td}${_notfixed}"
1881 fi
1882 failed=1
1883 elif [ -e "${sd}" ]; then
1884 msg "Unexpected file ${sd}${_notfixed}"
1885 continue
1886 else
1887 continue
1888 fi
1889 done
1890
1891 # check if xdm resources have been updated
1892 if [ -r ${_etcx11}/xdm/Xresources ] && \
1893 ! ${GREP} 'inpColor:' ${_etcx11}/xdm/Xresources > /dev/null; then
1894 msg "Update ${_etcx11}/xdm/Xresources${_notfixed}"
1895 failed=1
1896 fi
1897
1898 return ${failed}
1899 }
1900
1901 #
1902 # xkb
1903 #
1904 # /usr/X11R7/lib/X11/xkb/symbols/pc used to be a directory, but changed
1905 # to a file on 2009-06-12. Fixing this requires removing the directory
1906 # (which we can do) and re-extracting the xbase set (which we can't do),
1907 # or at least adding that one file (which we may be able to do if X11SRCDIR
1908 # is available).
1909 #
1910 additem xkb "clean up for xkbdata to xkeyboard-config upgrade"
1911 do_xkb()
1912 {
1913 [ -n "$1" ] || err 3 "USAGE: do_xkb fix|check"
1914 op="$1"
1915 failed=0
1916
1917 pcpath="/usr/X11R7/lib/X11/xkb/symbols/pc"
1918 pcsrcdir="${X11SRCDIR}/external/mit/xkeyboard-config/dist/symbols"
1919
1920 filemsg="\
1921 ${pcpath} was a directory, should be a file.
1922 To fix, extract the xbase set again."
1923
1924 _notfixed=""
1925 if [ "${op}" = "fix" ]; then
1926 _notfixed="${NOT_FIXED}"
1927 fi
1928
1929 if [ ! -d "${DEST_DIR}${pcpath}" ]; then
1930 return 0
1931 fi
1932
1933 # Delete obsolete files in the directory, and the directory
1934 # itself. If the directory contains unexpected extra files
1935 # then it will not be deleted.
1936 ( [ -f "${DEST_DIR}"/var/db/obsolete/xbase ] \
1937 && ${SORT} -ru "${DEST_DIR}"/var/db/obsolete/xbase \
1938 | ${GREP} -E "^\\.?${pcpath}/" ;
1939 echo "${pcpath}" ) \
1940 | obsolete_paths "${op}"
1941 failed=$(( ${failed} + $? ))
1942
1943 # If the directory was removed above, then try to replace it with
1944 # a file.
1945 if [ -d "${DEST_DIR}${pcpath}" ]; then
1946 msg "${filemsg}${_notfixed}"
1947 failed=$(( ${failed} + 1 ))
1948 else
1949 if ! find_file_in_dirlist pc "${pcpath}" \
1950 "${pcsrcdir}" "${SRC_DIR}${pcpath%/*}"
1951 then
1952 msg "${filemsg}${_notfixed}"
1953 failed=$(( ${failed} + 1 ))
1954 else
1955 # ${dir} is set by find_file_in_dirlist()
1956 populate_dir "${op}" true \
1957 "${dir}" "${DEST_DIR}${pcpath%/*}" 444 \
1958 pc
1959 failed=$(( ${failed} + $? ))
1960 fi
1961 fi
1962
1963 return $failed
1964 }
1965
1966 #
1967 # uid
1968 #
1969 additem uid "required users in /etc/master.passwd"
1970 do_uid()
1971 {
1972 [ -n "$1" ] || err 3 "USAGE: do_uid fix|check"
1973
1974 check_ids "$1" users "${DEST_DIR}/etc/master.passwd" \
1975 "${SRC_DIR}/etc/master.passwd" 12 \
1976 postfix SKIP named ntpd sshd SKIP _pflogd _rwhod SKIP _proxy \
1977 _timedc _sdpd _httpd _mdnsd _tests _tcpdump _tss SKIP _rtadvd \
1978 SKIP _unbound _nsd SKIP _dhcpcd
1979 }
1980
1981
1982 #
1983 # varrwho
1984 #
1985 additem varrwho "required ownership of files in /var/rwho"
1986 do_varrwho()
1987 {
1988 [ -n "$1" ] || err 3 "USAGE: do_varrwho fix|check"
1989
1990 contents_owner "$1" "${DEST_DIR}/var/rwho" _rwhod _rwhod
1991 }
1992
1993
1994 #
1995 # tcpdumpchroot
1996 #
1997 additem tcpdumpchroot "remove /var/chroot/tcpdump/etc/protocols"
1998 do_tcpdumpchroot()
1999 {
2000 [ -n "$1" ] || err 3 "USAGE: do_tcpdumpchroot fix|check"
2001
2002 failed=0;
2003 if [ -r "${DEST_DIR}/var/chroot/tcpdump/etc/protocols" ]; then
2004 if [ "$1" = "fix" ]; then
2005 rm "${DEST_DIR}/var/chroot/tcpdump/etc/protocols"
2006 failed=$(( ${failed} + $? ))
2007 rmdir "${DEST_DIR}/var/chroot/tcpdump/etc"
2008 failed=$(( ${failed} + $? ))
2009 else
2010 failed=1
2011 fi
2012 fi
2013 return ${failed}
2014 }
2015
2016
2017 #
2018 # atf
2019 #
2020 additem atf "install missing atf configuration files and validate them"
2021 do_atf()
2022 {
2023 [ -n "$1" ] || err 3 "USAGE: do_atf fix|check"
2024 op="$1"
2025 failed=0
2026
2027 # Ensure atf configuration files are in place.
2028 if find_file_in_dirlist NetBSD.conf "NetBSD.conf" \
2029 "${SRC_DIR}/external/bsd/atf/etc/atf" \
2030 "${SRC_DIR}/etc/atf"; then
2031 # ${dir} is set by find_file_in_dirlist()
2032 populate_dir "${op}" true "${dir}" "${DEST_DIR}/etc/atf" 644 \
2033 NetBSD.conf common.conf || failed=1
2034 else
2035 failed=1
2036 fi
2037 if find_file_in_dirlist atf-run.hooks "atf-run.hooks" \
2038 "${SRC_DIR}/external/bsd/atf/dist/tools/sample" \
2039 "${SRC_DIR}/etc/atf"; then
2040 # ${dir} is set by find_file_in_dirlist()
2041 populate_dir "${op}" true "${dir}" "${DEST_DIR}/etc/atf" 644 \
2042 atf-run.hooks || failed=1
2043 else
2044 failed=1
2045 fi
2046
2047 # Validate the _atf to _tests user/group renaming.
2048 if [ -f "${DEST_DIR}/etc/atf/common.conf" ]; then
2049 handle_atf_user "${op}" || failed=1
2050 else
2051 failed=1
2052 fi
2053
2054 return ${failed}
2055 }
2056
2057 handle_atf_user()
2058 {
2059 local op="$1"
2060 local failed=0
2061
2062 local conf="${DEST_DIR}/etc/atf/common.conf"
2063 if grep '[^#]*unprivileged-user[ \t]*=.*_atf' "${conf}" >/dev/null
2064 then
2065 if [ "$1" = "fix" ]; then
2066 ${SED} -e \
2067 "/[^#]*unprivileged-user[\ t]*=/s/_atf/_tests/" \
2068 "${conf}" >"${conf}.new"
2069 failed=$(( ${failed} + $? ))
2070 mv "${conf}.new" "${conf}"
2071 failed=$(( ${failed} + $? ))
2072 msg "Set unprivileged-user=_tests in ${conf}"
2073 else
2074 msg "unprivileged-user=_atf in ${conf} should be" \
2075 "unprivileged-user=_tests"
2076 failed=1
2077 fi
2078 fi
2079
2080 return ${failed}
2081 }
2082
2083 #
2084 # catpages
2085 #
2086 obsolete_catpages()
2087 {
2088 basedir="$2"
2089 section="$3"
2090 mandir="${basedir}/man${section}"
2091 catdir="${basedir}/cat${section}"
2092 test -d "$mandir" || return 0
2093 test -d "$catdir" || return 0
2094 (cd "$mandir" && find . -type f) | {
2095 failed=0
2096 while read manpage; do
2097 manpage="${manpage#./}"
2098 case "$manpage" in
2099 *.Z)
2100 catname="$catdir/${manpage%.*.Z}.0"
2101 ;;
2102 *.gz)
2103 catname="$catdir/${manpage%.*.gz}.0"
2104 ;;
2105 *)
2106 catname="$catdir/${manpage%.*}.0"
2107 ;;
2108 esac
2109 test -e "$catname" -a "$catname" -ot "$mandir/$manpage" || continue
2110 if [ "$1" = "fix" ]; then
2111 rm "$catname"
2112 failed=$(( ${failed} + $? ))
2113 msg "Removed obsolete cat page $catname"
2114 else
2115 msg "Obsolete cat page $catname"
2116 failed=1
2117 fi
2118 done
2119 exit $failed
2120 }
2121 }
2122
2123 additem catpages "remove outdated cat pages"
2124 do_catpages()
2125 {
2126 failed=0
2127 for manbase in /usr/share/man /usr/X11R6/man /usr/X11R7/man; do
2128 for sec in 1 2 3 4 5 6 7 8 9; do
2129 obsolete_catpages "$1" "${DEST_DIR}${manbase}" "${sec}"
2130 failed=$(( ${failed} + $? ))
2131 if [ "$1" = "fix" ]; then
2132 rmdir "${DEST_DIR}${manbase}/cat${sec}"/* \
2133 2>/dev/null
2134 rmdir "${DEST_DIR}${manbase}/cat${sec}" \
2135 2>/dev/null
2136 fi
2137 done
2138 done
2139 return $failed
2140 }
2141
2142 #
2143 # man.conf
2144 #
2145 additem manconf "check for a mandoc usage in /etc/man.conf"
2146 do_manconf()
2147 {
2148 [ -n "$1" ] || err 3 "USAGE: do_manconf fix|check"
2149 op="$1"
2150 failed=0
2151
2152 [ -f "${DEST_DIR}/etc/man.conf" ] || return 0
2153 if ${GREP} -w "mandoc" "${DEST_DIR}/etc/man.conf" >/dev/null 2>&1;
2154 then
2155 failed=0;
2156 else
2157 failed=1
2158 notfixed=""
2159 if [ "${op}" = "fix" ]; then
2160 notfixed="${NOT_FIXED}"
2161 fi
2162 msg "The file /etc/man.conf has not been adapted to mandoc usage; you"
2163 msg "probably want to copy a new version over. ${notfixed}"
2164 fi
2165
2166 return ${failed}
2167 }
2168
2169
2170 #
2171 # ptyfsoldnodes
2172 #
2173 additem ptyfsoldnodes "remove legacy device nodes when using ptyfs"
2174 do_ptyfsoldnodes()
2175 {
2176 [ -n "$1" ] || err 3 "USAGE: do_ptyfsoldnodes fix|check"
2177 _ptyfs_op="$1"
2178
2179 # Check whether ptyfs is in use
2180 failed=0;
2181 if ! ${GREP} -E "^ptyfs" "${DEST_DIR}/etc/fstab" > /dev/null; then
2182 msg "ptyfs is not in use"
2183 return 0
2184 fi
2185
2186 if [ ! -e "${DEST_DIR}/dev/pts" ]; then
2187 msg "ptyfs is not properly configured: missing /dev/pts"
2188 return 1
2189 fi
2190
2191 # Find the device major numbers for the pty master and slave
2192 # devices, by parsing the output from "MAKEDEV -s pty0".
2193 #
2194 # Output from MAKEDEV looks like this:
2195 # ./ttyp0 type=char device=netbsd,5,0 mode=666 gid=0 uid=0
2196 # ./ptyp0 type=char device=netbsd,6,0 mode=666 gid=0 uid=0
2197 #
2198 # Output from awk, used in the eval statement, looks like this:
2199 # maj_ptym=6; maj_ptys=5;
2200 #
2201 find_makedev
2202 eval "$(
2203 ${HOST_SH} "${MAKEDEV_DIR}/MAKEDEV" -s pty0 2>/dev/null \
2204 | ${AWK} '\
2205 BEGIN { before_re = ".*device=[a-zA-Z]*,"; after_re = ",.*"; }
2206 /ptyp0/ { maj_ptym = gensub(before_re, "", 1, $0);
2207 maj_ptym = gensub(after_re, "", 1, maj_ptym); }
2208 /ttyp0/ { maj_ptys = gensub(before_re, "", 1, $0);
2209 maj_ptys = gensub(after_re, "", 1, maj_ptys); }
2210 END { print "maj_ptym=" maj_ptym "; maj_ptys=" maj_ptys ";"; }
2211 '
2212 )"
2213 #msg "Major numbers are maj_ptym=${maj_ptym} maj_ptys=${maj_ptys}"
2214 if [ -z "$maj_ptym" ] || [ -z "$maj_ptys" ]; then
2215 msg "Cannot find device major numbers for pty master and slave"
2216 return 1
2217 fi
2218
2219 # look for /dev/[pt]ty[p-zP-T][0-9a-zA-Z], and check that they
2220 # have the expected device major numbers. ttyv* is typically not a
2221 # pty device, but we check it anyway.
2222 #
2223 # The "for d1" loop is intended to avoid overflowing ARG_MAX;
2224 # otherwise we could have used a single glob pattern.
2225 #
2226 # If there are no files that match a particular pattern,
2227 # then stat prints something like:
2228 # stat: /dev/[pt]tyx?: lstat: No such file or directory
2229 # and we ignore it. XXX: We also ignore other error messages.
2230 #
2231 _ptyfs_tmp="$(mktemp /tmp/postinstall.ptyfs.XXXXXXXX)"
2232 for d1 in p q r s t u v w x y z P Q R S T; do
2233 ${STAT} -f "%Hr %N" "${DEST_DIR}/dev/"[pt]ty${d1}? 2>&1
2234 done \
2235 | while read -r major node ; do
2236 case "$major" in
2237 ${maj_ptym}|${maj_ptys}) echo "$node" ;;
2238 esac
2239 done >"${_ptyfs_tmp}"
2240
2241 _desc="legacy device node"
2242 while read node; do
2243 if [ "${_ptyfs_op}" = "check" ]; then
2244 msg "Remove ${_desc} ${node}"
2245 failed=1
2246 else # "fix"
2247 if rm "${node}"; then
2248 msg "Removed ${_desc} ${node}"
2249 else
2250 warn "Failed to remove ${_desc} ${node}"
2251 failed=1
2252 fi
2253 fi
2254 done < "${_ptyfs_tmp}"
2255 rm "${_ptyfs_tmp}"
2256
2257 return ${failed}
2258 }
2259
2260
2261 #
2262 # varshm
2263 #
2264 additem varshm "check for a tmpfs mounted on /var/shm"
2265 do_varshm()
2266 {
2267 [ -n "$1" ] || err 3 "USAGE: do_varshm fix|check"
2268 op="$1"
2269 failed=0
2270
2271 [ -f "${DEST_DIR}/etc/fstab" ] || return 0
2272 if ${GREP} -E "^var_shm_symlink" "${DEST_DIR}/etc/rc.conf" >/dev/null 2>&1;
2273 then
2274 failed=0;
2275 elif ${GREP} -w "/var/shm" "${DEST_DIR}/etc/fstab" >/dev/null 2>&1;
2276 then
2277 failed=0;
2278 else
2279 if [ "${op}" = "check" ]; then
2280 failed=1
2281 msg "No /var/shm mount found in ${DEST_DIR}/etc/fstab"
2282 elif [ "${op}" = "fix" ]; then
2283 printf '\ntmpfs\t/var/shm\ttmpfs\trw,-m1777,-sram%%25\n' \
2284 >> "${DEST_DIR}/etc/fstab"
2285 msg "Added tmpfs with 25% ram limit as /var/shm"
2286
2287 fi
2288 fi
2289
2290 return ${failed}
2291 }
2292
2293 #
2294 # obsolete_stand
2295 #
2296 adddisableditem obsolete_stand "remove obsolete files from /stand"
2297 do_obsolete_stand()
2298 {
2299 [ -n "$1" ] || err 3 "USAGE: do_obsolete_stnd fix|check"
2300 op="$1"
2301 failed=0
2302
2303 for dir in \
2304 /stand/${MACHINE} \
2305 /stand/${MACHINE}-4xx \
2306 /stand/${MACHINE}-booke \
2307 /stand/${MACHINE}-xen \
2308 /stand/${MACHINE}pae-xen
2309 do
2310 [ -d "${DESTDIR}${dir}" ] && obsolete_stand "${dir}"
2311 done | obsolete_paths "${op}"
2312 failed=$(( ${failed} + $? ))
2313
2314 return ${failed}
2315 }
2316
2317 listarchsubdirs() {
2318 if ! $SOURCEMODE; then
2319 echo "@ARCHSUBDIRS@"
2320 else
2321 ${SED} -n -e '/ARCHDIR_SUBDIR/s/[[:space:]]//gp' \
2322 ${SRC_DIR}/compat/archdirs.mk
2323 fi
2324 }
2325
2326
2327 getarchsubdirs() {
2328 local m
2329 case ${MACHINE_ARCH} in
2330 *arm*|*aarch64*) m=arm;;
2331 x86_64) m=amd64;;
2332 *) m=${MACHINE_ARCH};;
2333 esac
2334
2335 for i in $(listarchsubdirs); do
2336 echo $i
2337 done | ${SORT} -u | ${SED} -n -e "/=${m}/s@.*=${m}/\(.*\)@\1@p"
2338 }
2339
2340 getcompatlibdirs() {
2341 for i in $(getarchsubdirs); do
2342 if [ -d "${DEST_DIR}/usr/lib/$i" ]; then
2343 echo /usr/lib/$i
2344 fi
2345 done
2346 }
2347
2348 #
2349 # obsolete
2350 # (this item is last to allow other items to move obsolete files)
2351 #
2352 additem obsolete "remove obsolete file sets and minor libraries"
2353 do_obsolete()
2354 {
2355 [ -n "$1" ] || err 3 "USAGE: do_obsolete fix|check"
2356 op="$1"
2357 failed=0
2358
2359 ${SORT} -ru "${DEST_DIR}"/var/db/obsolete/* | obsolete_paths "${op}"
2360 failed=$(( ${failed} + $? ))
2361
2362 (
2363 obsolete_libs /lib
2364 obsolete_libs /usr/lib
2365 obsolete_libs /usr/lib/i18n
2366 obsolete_libs /usr/X11R6/lib
2367 obsolete_libs /usr/X11R7/lib
2368 for i in $(getcompatlibdirs); do
2369 obsolete_libs $i
2370 done
2371 ) | obsolete_paths "${op}"
2372 failed=$(( ${failed} + $? ))
2373
2374 return ${failed}
2375 }
2376
2377 #
2378 # end of items
2379 # ------------
2380 #
2381
2382
2383 usage()
2384 {
2385 cat 1>&2 << _USAGE_
2386 Usage: ${PROGNAME} [-s srcdir] [-x xsrcdir] [-d destdir] [-m mach] [-a arch] op [item [...]]
2387 Perform post-installation checks and/or fixes on a system's
2388 configuration files.
2389 If no items are provided, a default set of checks or fixes is applied.
2390
2391 Options:
2392 -s {srcdir|tgzfile|tempdir}
2393 Location of the source files. This may be any
2394 of the following:
2395 * A directory that contains a NetBSD source tree;
2396 * A distribution set file such as "etc.tgz" or
2397 "xetc.tgz". Pass multiple -s options to specify
2398 multiple such files;
2399 * A temporary directory in which one or both of
2400 "etc.tgz" and "xetc.tgz" have been extracted.
2401 [${SRC_DIR:-/usr/src}]
2402 -x xsrcdir Location of the X11 source files. This must be
2403 a directory that contains a NetBSD xsrc tree.
2404 [${XSRC_DIR:-/usr/src/../xsrc}]
2405 -d destdir Destination directory to check. [${DEST_DIR:-/}]
2406 -m mach MACHINE. [${MACHINE}]
2407 -a arch MACHINE_ARCH. [${MACHINE_ARCH}]
2408
2409 Operation may be one of:
2410 help Display this help.
2411 list List available items.
2412 check Perform post-installation checks on items.
2413 diff [diff(1) options ...]
2414 Similar to 'check' but also output difference of files.
2415 fix Apply fixes that 'check' determines need to be applied.
2416 usage Display this usage.
2417 _USAGE_
2418 exit 2
2419 }
2420
2421
2422 list()
2423 {
2424 echo "Default set of items (to apply if no items are provided by user):"
2425 echo " Item Description"
2426 echo " ---- -----------"
2427 for i in ${defaultitems}; do
2428 eval desc=\"\${desc_${i}}\"
2429 printf " %-12s %s\n" "${i}" "${desc}"
2430 done
2431 echo "Items disabled by default (must be requested explicitly):"
2432 echo " Item Description"
2433 echo " ---- -----------"
2434 for i in ${otheritems}; do
2435 eval desc=\"\${desc_${i}}\"
2436 printf " %-12s %s\n" "${i}" "${desc}"
2437 done
2438
2439 }
2440
2441
2442 main()
2443 {
2444 TGZLIST= # quoted list list of tgz files
2445 SRC_ARGLIST= # quoted list of one or more "-s" args
2446 SRC_DIR="${SRC_ARG}" # set default value for early usage()
2447 XSRC_DIR="${SRC_ARG}/../xsrc"
2448 N_SRC_ARGS=0 # number of "-s" args
2449 TGZMODE=false # true if "-s" specifies a tgz file
2450 DIRMODE=false # true if "-s" specified a directory
2451 SOURCEMODE=false # true if "-s" specified a source directory
2452
2453 case "$(uname -s)" in
2454 Darwin)
2455 # case sensitive match for case insensitive fs
2456 file_exists_exact=file_exists_exact
2457 ;;
2458 *)
2459 file_exists_exact=:
2460 ;;
2461 esac
2462
2463 while getopts s:x:d:m:a: ch; do
2464 case "${ch}" in
2465 s)
2466 qarg="$(shell_quote "${OPTARG}")"
2467 N_SRC_ARGS=$(( $N_SRC_ARGS + 1 ))
2468 SRC_ARGLIST="${SRC_ARGLIST}${SRC_ARGLIST:+ }-s ${qarg}"
2469 if [ -f "${OPTARG}" ]; then
2470 # arg refers to a *.tgz file.
2471 # This may happen twice, for both
2472 # etc.tgz and xetc.tgz, so we build up a
2473 # quoted list in TGZLIST.
2474 TGZMODE=true
2475 TGZLIST="${TGZLIST}${TGZLIST:+ }${qarg}"
2476 # Note that, when TGZMODE is true,
2477 # SRC_ARG is used only for printing
2478 # human-readable messages.
2479 SRC_ARG="${TGZLIST}"
2480 elif [ -d "${OPTARG}" ]; then
2481 # arg refers to a directory.
2482 # It might be a source directory, or a
2483 # directory where the sets have already
2484 # been extracted.
2485 DIRMODE=true
2486 SRC_ARG="${OPTARG}"
2487 if [ -f "${OPTARG}/etc/Makefile" ]; then
2488 SOURCEMODE=true
2489 fi
2490 else
2491 err 2 "Invalid argument for -s option"
2492 fi
2493 ;;
2494 x)
2495 if [ -d "${OPTARG}" ]; then
2496 # arg refers to a directory.
2497 XSRC_DIR="${OPTARG}"
2498 XSRC_DIR_FIX="-x ${OPTARG} "
2499 else
2500 err 2 "Not a directory for -x option"
2501 fi
2502 ;;
2503 d)
2504 DEST_DIR="${OPTARG}"
2505 ;;
2506 m)
2507 MACHINE="${OPTARG}"
2508 ;;
2509 a)
2510 MACHINE_ARCH="${OPTARG}"
2511 ;;
2512 *)
2513 usage
2514 ;;
2515 esac
2516 done
2517 shift $((${OPTIND} - 1))
2518 [ $# -gt 0 ] || usage
2519
2520 if [ "$N_SRC_ARGS" -gt 1 ] && $DIRMODE; then
2521 err 2 "Multiple -s args are allowed only with tgz files"
2522 fi
2523 if [ "$N_SRC_ARGS" -eq 0 ]; then
2524 # The default SRC_ARG was set elsewhere
2525 DIRMODE=true
2526 SOURCEMODE=true
2527 SRC_ARGLIST="-s $(shell_quote "${SRC_ARG}")"
2528 fi
2529
2530 #
2531 # If '-s' arg or args specified tgz files, extract them
2532 # to a scratch directory.
2533 #
2534 if $TGZMODE; then
2535 ETCTGZDIR="${SCRATCHDIR}/etc.tgz"
2536 echo "Note: Creating temporary directory ${ETCTGZDIR}"
2537 if ! mkdir "${ETCTGZDIR}"; then
2538 err 2 "Can't create ${ETCTGZDIR}"
2539 fi
2540 ( # subshell to localise changes to "$@"
2541 eval "set -- ${TGZLIST}"
2542 for tgz in "$@"; do
2543 echo "Note: Extracting files from ${tgz}"
2544 cat "${tgz}" | (
2545 cd "${ETCTGZDIR}" &&
2546 tar -zxf -
2547 ) || err 2 "Can't extract ${tgz}"
2548 done
2549 )
2550 SRC_DIR="${ETCTGZDIR}"
2551 else
2552 SRC_DIR="${SRC_ARG}"
2553 fi
2554
2555 [ -d "${SRC_DIR}" ] || err 2 "${SRC_DIR} is not a directory"
2556 [ -d "${DEST_DIR}" ] || err 2 "${DEST_DIR} is not a directory"
2557 [ -n "${MACHINE}" ] || err 2 "\${MACHINE} is not defined"
2558 [ -n "${MACHINE_ARCH}" ] || err 2 "\${MACHINE_ARCH} is not defined"
2559 if ! $SOURCEMODE && ! [ -f "${SRC_DIR}/etc/mtree/set.etc" ]; then
2560 err 2 "Files from the etc.tgz set are missing"
2561 fi
2562
2563 # If directories are /, clear them, so various messages
2564 # don't have leading "//". However, this requires
2565 # the use of ${foo:-/} to display the variables.
2566 #
2567 [ "${SRC_DIR}" = "/" ] && SRC_DIR=""
2568 [ "${DEST_DIR}" = "/" ] && DEST_DIR=""
2569
2570 detect_x11
2571
2572 op="$1"
2573 shift
2574
2575 case "${op}" in
2576 diff)
2577 op=check
2578 DIFF_STYLE=n # default style is RCS
2579 OPTIND=1
2580 while getopts bcenpuw ch; do
2581 case "${ch}" in
2582 c|e|n|u)
2583 if [ "${DIFF_STYLE}" != "n" -a \
2584 "${DIFF_STYLE}" != "${ch}" ]; then
2585 err 2 "conflicting output style: ${ch}"
2586 fi
2587 DIFF_STYLE="${ch}"
2588 ;;
2589 b|p|w)
2590 DIFF_OPT="${DIFF_OPT} -${ch}"
2591 ;;
2592 *)
2593 err 2 "unknown diff option"
2594 ;;
2595 esac
2596 done
2597 shift $((${OPTIND} - 1))
2598 ;;
2599 esac
2600
2601 case "${op}" in
2602
2603 usage|help)
2604 usage
2605 ;;
2606
2607 list)
2608 echo "Source directory: ${SRC_DIR:-/}"
2609 echo "Target directory: ${DEST_DIR:-/}"
2610 if $TGZMODE; then
2611 echo " (extracted from: ${SRC_ARG})"
2612 fi
2613 list
2614 ;;
2615
2616 check|fix)
2617 todo="$*"
2618 : ${todo:="${defaultitems}"}
2619
2620 # ensure that all supplied items are valid
2621 #
2622 for i in ${todo}; do
2623 eval desc=\"\${desc_${i}}\"
2624 [ -n "${desc}" ] || err 2 "Unsupported ${op} '"${i}"'"
2625 done
2626
2627 # perform each check/fix
2628 #
2629 echo "Source directory: ${SRC_DIR:-/}"
2630 if $TGZMODE; then
2631 echo " (extracted from: ${SRC_ARG})"
2632 fi
2633 echo "Target directory: ${DEST_DIR:-/}"
2634 items_passed=
2635 items_failed=
2636 for i in ${todo}; do
2637 echo "${i} ${op}:"
2638 ( eval do_${i} ${op} )
2639 if [ $? -eq 0 ]; then
2640 items_passed="${items_passed} ${i}"
2641 else
2642 items_failed="${items_failed} ${i}"
2643 fi
2644 done
2645
2646 if [ "${op}" = "check" ]; then
2647 plural="checks"
2648 else
2649 plural="fixes"
2650 fi
2651
2652 echo "${PROGNAME} ${plural} passed:${items_passed}"
2653 echo "${PROGNAME} ${plural} failed:${items_failed}"
2654 if [ -n "${items_failed}" ]; then
2655 exitstatus=1;
2656 if [ "${op}" = "check" ]; then
2657 [ "$MACHINE" = "$(uname -m)" ] && m= || m=" -m $MACHINE"
2658 cat <<_Fix_me_
2659 To fix, run:
2660 ${HOST_SH} ${0} ${SRC_ARGLIST} ${XSRC_DIR_FIX}-d ${DEST_DIR:-/}$m fix${items_failed}
2661 Note that this may overwrite local changes.
2662 _Fix_me_
2663 fi
2664 fi
2665
2666 ;;
2667
2668 *)
2669 warn "Unknown operation '"${op}"'"
2670 usage
2671 ;;
2672
2673 esac
2674 }
2675
2676 if [ -n "$POSTINSTALL_FUNCTION" ]; then
2677 eval "$POSTINSTALL_FUNCTION"
2678 exit 0
2679 fi
2680
2681 # defaults
2682 #
2683 PROGNAME="${0##*/}"
2684 SRC_ARG="/usr/src"
2685 DEST_DIR="/"
2686 : ${MACHINE:="$( uname -m )"} # assume native build if $MACHINE is not set
2687 : ${MACHINE_ARCH:="$( uname -p )"}# assume native build if not set
2688
2689 DIFF_STYLE=
2690 NOT_FIXED=" (FIX MANUALLY)"
2691 SCRATCHDIR="$( mkdtemp )" || err 2 "Can't create scratch directory"
2692 trap "/bin/rm -rf \"\${SCRATCHDIR}\" ; exit 0" 1 2 3 15 # HUP INT QUIT TERM
2693
2694 umask 022
2695 exec 3>/dev/null
2696 exec 4>/dev/null
2697 exitstatus=0
2698
2699 main "$@"
2700 /bin/rm -rf "${SCRATCHDIR}"
2701 exit $exitstatus
2702