Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/postinstall postinstall: sort the items. keep obsol...



details:   https://anonhg.NetBSD.org/src/rev/de6c82ac1500
branches:  trunk
changeset: 961900:de6c82ac1500
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sun Apr 25 01:44:55 2021 +0000

description:
postinstall: sort the items. keep obsolete* last

Consistency and quality of life improvements to postinstall:

Order all of the items (including disabled) alphabetically.
Consistent comment style before each item block.
Move other functions used by do_*() before rather than after do_*().

diffstat:

 usr.sbin/postinstall/postinstall.in |  961 +++++++++++++++++++----------------
 1 files changed, 518 insertions(+), 443 deletions(-)

diffs (truncated from 1282 to 300 lines):

diff -r 586029e7e2e5 -r de6c82ac1500 usr.sbin/postinstall/postinstall.in
--- a/usr.sbin/postinstall/postinstall.in       Sun Apr 25 01:15:39 2021 +0000
+++ b/usr.sbin/postinstall/postinstall.in       Sun Apr 25 01:44:55 2021 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: postinstall.in,v 1.36 2021/04/25 01:15:39 lukem Exp $
+# $NetBSD: postinstall.in,v 1.37 2021/04/25 01:44:55 lukem Exp $
 #
 # Copyright (c) 2002-2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -590,7 +590,8 @@
 # find all the target symlinks of shared libaries and exclude them
 # from consideration for removal
 #
-exclude_libs() {
+exclude_libs()
+{
        local target="$(ls -l -d lib*.so.* 2> /dev/null \
            | ${AWK} '{ print $11; }' \
            | ${SED} -e 's@.*/@@' | ${SORT} -u)"
@@ -808,9 +809,170 @@
 #      items
 #      -----
 #
+# NOTE: Keep these items sorted, except for obsolete* which are listed last.
+#
+
+#
+#      atf
+#
+
+handle_atf_user()
+{
+       local op="$1"
+       local failed=0
+
+       local conf="${DEST_DIR}/etc/atf/common.conf"
+       if grep '[^#]*unprivileged-user[ \t]*=.*_atf' "${conf}" >/dev/null
+       then
+               if [ "$1" = "fix" ]; then
+                       ${SED} -e \
+                           "/[^#]*unprivileged-user[\ t]*=/s/_atf/_tests/" \
+                           "${conf}" >"${conf}.new"
+                       failed=$(( ${failed} + $? ))
+                       mv "${conf}.new" "${conf}"
+                       failed=$(( ${failed} + $? ))
+                       msg "Set unprivileged-user=_tests in ${conf}"
+               else
+                       msg "unprivileged-user=_atf in ${conf} should be" \
+                           "unprivileged-user=_tests"
+                       failed=1
+               fi
+       fi
+
+       return ${failed}
+}
+
+additem atf "install missing atf configuration files and validate them"
+do_atf()
+{
+       [ -n "$1" ] || err 3 "USAGE: do_atf fix|check"
+       op="$1"
+       failed=0
+
+       # Ensure atf configuration files are in place.
+       if find_file_in_dirlist NetBSD.conf "NetBSD.conf" \
+           "${SRC_DIR}/external/bsd/atf/etc/atf" \
+           "${SRC_DIR}/etc/atf"; then
+                       # ${dir} is set by find_file_in_dirlist()
+               populate_dir "${op}" true "${dir}" "${DEST_DIR}/etc/atf" 644 \
+                   NetBSD.conf common.conf || failed=1
+       else
+               failed=1
+       fi
+       if find_file_in_dirlist atf-run.hooks "atf-run.hooks" \
+           "${SRC_DIR}/external/bsd/atf/dist/tools/sample" \
+           "${SRC_DIR}/etc/atf"; then
+                       # ${dir} is set by find_file_in_dirlist()
+               populate_dir "${op}" true "${dir}" "${DEST_DIR}/etc/atf" 644 \
+                   atf-run.hooks || failed=1
+       else
+               failed=1
+       fi
+
+       # Validate the _atf to _tests user/group renaming.
+       if [ -f "${DEST_DIR}/etc/atf/common.conf" ]; then
+               handle_atf_user "${op}" || failed=1
+       else
+               failed=1
+       fi
+
+       return ${failed}
+}
+
 
 #
-#      Bluetooth
+#      autofsconfig
+#
+
+additem autofsconfig "automounter configuration files"
+do_autofsconfig()
+{
+       [ -n "$1" ] || err 3 "USAGE: do_autofsconfig fix|check"
+       local autofs_files="
+include_ldap
+include_nis
+special_hosts
+special_media
+special_noauto
+special_null
+"
+       op="$1"
+       failed=0
+       if [ "$op" = "fix" ]; then
+               mkdir -p "${DEST_DIR}/etc/autofs"
+       fi
+       failed=$(( ${failed} + $? ))
+       populate_dir "$op" false "${SRC_DIR}/etc" \
+           "${DEST_DIR}/etc" \
+           644 \
+           auto_master
+       failed=$(( ${failed} + $? ))
+       populate_dir "$op" false "${SRC_DIR}/etc/autofs" \
+           "${DEST_DIR}/etc/autofs" \
+           644 \
+           ${autofs_files}
+       return ${failed}
+}
+
+
+#
+#      blocklist
+#
+
+fixblock()
+{
+       local op="$1"
+       local target="${DEST_DIR}$2"
+
+       if [ ! -f "${target}" ]; then
+               continue
+       fi
+
+       if ${GREP} '[bB]lack' "${target}" > /dev/null; then
+               if [ "$1" = "check" ]; then
+                       msg "Fix old configuration file(s)."
+                       return 1
+               else
+                       local p=$(${STAT} -f %Lp "${target}")
+                       chmod u+w "${target}" || return 1
+                       if [ "$2" = "/etc/npf.conf" ]; then
+                               ${SED} -i -e 's/"blacklistd"/"blocklistd"/g' "${target}"
+                       else
+                               ${SED} -i -e 's/\([bB]\)lacklist/\1locklist/g' "${target}"
+                       fi
+                       chmod "${p}" "${target}"
+               fi
+       fi
+}
+
+additem blocklist "rename old files to blocklist"
+do_blocklist()
+{
+       [ -n "$1" ] || err 3 "USAGE: do_blocklist fix|check"
+       local op="$1"
+
+       # if we are actually using blocklistd
+       for i in /var/db/blacklist.db /etc/blacklistd.conf; do
+               local old="${DEST_DIR}${i}"
+               if [ ! -f "${old}" ]; then
+                       continue
+               elif [ "$1" = "check" ]; then
+                       msg "Rename old file(s)."
+                       return 1
+               fi
+               local new=$(echo "${old}" | ${SED} s/black/block/)
+               mv "${old}" "${new}" || return 1
+       done
+
+       for i in /etc/rc.conf /etc/npf.conf /etc/blocklistd.conf \
+           /etc/defaults/rc.conf; do
+               fixblock "${op}" "${i}" || return 1
+       done
+}
+
+
+#
+#      bluetooth
 #
 
 additem bluetooth "Bluetooth configuration is up to date"
@@ -844,62 +1006,72 @@
        return ${failed}
 }
 
-fixblock() {
-       local op="$1"
-       local target="${DEST_DIR}$2"
-
-       if [ ! -f "${target}" ]; then
-               continue
-       fi
-
-       if ${GREP} '[bB]lack' "${target}" > /dev/null; then
-               if [ "$1" = "check" ]; then
-                       msg "Fix old configuration file(s)."
-                       return 1
-               else
-                       local p=$(${STAT} -f %Lp "${target}")
-                       chmod u+w "${target}" || return 1
-                       if [ "$2" = "/etc/npf.conf" ]; then
-                               ${SED} -i -e 's/"blacklistd"/"blocklistd"/g' "${target}"
-                       else
-                               ${SED} -i -e 's/\([bB]\)lacklist/\1locklist/g' "${target}"
-                       fi
-                       chmod "${p}" "${target}"
-               fi
-       fi
-}
 
 #
-#      blocklist update
+#      catpages
 #
-additem blocklist "rename old files to blocklist"
-do_blocklist()
+
+obsolete_catpages()
 {
-       [ -n "$1" ] || err 3 "USAGE: do_blocklist fix|check"
-       local op="$1"
-
-       # if we are actually using blocklistd
-       for i in /var/db/blacklist.db /etc/blacklistd.conf; do
-               local old="${DEST_DIR}${i}"
-               if [ ! -f "${old}" ]; then
-                       continue
-               elif [ "$1" = "check" ]; then
-                       msg "Rename old file(s)."
-                       return 1
+       basedir="$2"
+       section="$3"
+       mandir="${basedir}/man${section}"
+       catdir="${basedir}/cat${section}"
+       test -d "$mandir" || return 0
+       test -d "$catdir" || return 0
+       (cd "$mandir" && find . -type f) | {
+       failed=0
+       while read manpage; do
+               manpage="${manpage#./}"
+               case "$manpage" in
+               *.Z)
+                       catname="$catdir/${manpage%.*.Z}.0"
+                       ;;
+               *.gz)
+                       catname="$catdir/${manpage%.*.gz}.0"
+                       ;;
+               *)
+                       catname="$catdir/${manpage%.*}.0"
+                       ;;
+               esac
+               test -e "$catname" -a "$catname" -ot "$mandir/$manpage" || continue
+               if [ "$1" = "fix" ]; then
+                       rm "$catname"
+                       failed=$(( ${failed} + $? ))
+                       msg "Removed obsolete cat page $catname"
+               else
+                       msg "Obsolete cat page $catname"
+                       failed=1
                fi
-               local new=$(echo "${old}" | ${SED} s/black/block/)
-               mv "${old}" "${new}" || return 1
        done
-
-       for i in /etc/rc.conf /etc/npf.conf /etc/blocklistd.conf \
-           /etc/defaults/rc.conf; do
-               fixblock "${op}" "${i}" || return 1
+       exit $failed
+       }
+}
+
+additem catpages "remove outdated cat pages"
+do_catpages()
+{
+       failed=0
+       for manbase in /usr/share/man /usr/X11R6/man /usr/X11R7/man; do
+               for sec in 1 2 3 4 5 6 7 8 9; do
+                       obsolete_catpages "$1" "${DEST_DIR}${manbase}" "${sec}"
+                       failed=$(( ${failed} + $? ))
+                       if [ "$1" = "fix" ]; then
+                               rmdir "${DEST_DIR}${manbase}/cat${sec}"/* \
+                                       2>/dev/null
+                               rmdir "${DEST_DIR}${manbase}/cat${sec}" \
+                                       2>/dev/null
+                       fi
+               done
        done
+       return $failed



Home | Main Index | Thread Index | Old Index