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