The NEED_xxx feature of etcupdate (that i.e. asks you to run passwd_mkdb in 
case a new version of master.passwd is installed) is broken.
The problem is that diff_and_merge_files() and thus install_file() (which 
sets the NEED_xxx variables to "true") is run after a pipe and thus in a 
subshell. So the "true" values never make it to the end of the script where 
their values are used.
The easiest way to fix it appears to create some special (.etcupdate._NEED_xxx) 
files in $TEMPROOT. Means that the removal of $TEMPROOT has to be moved after 
the NEED_xxx checks.
Better suggestions?
Shall I file a PR?
--- etcupdate   2016-02-18 18:18:49.000000000 +0100
+++ etcupdate-x 2016-02-19 16:03:49.000000000 +0100
@@ -76,13 +76,6 @@
 OVERWRITE_FILES=" "    # files to overwrite (Install)
 MERGE_FILES=" "                # files to merge
 
-# Settings for post-installation procedures
-NEED_MAKEDEV=false
-NEED_MTREE=false
-NEED_NEWALIASES=false
-NEED_PWD_MKDB=false
-NEED_SERVICES_MKDB=false
-
 
 usage() {
        cat << EOF >&2
@@ -168,7 +161,7 @@
        if ${AUTO_MISSING} || yesno "Create ${1}"; then
                verbose "Creating ${1}"
                mkdir -p "${1}" || exit 1
-               NEED_MTREE=true
+               touch "${TEMPROOT}"/.etcupdate.NEED_MTREE
        fi
 }
 
@@ -182,19 +175,19 @@
        # Check if this was a special file
        case "${1}" in
        /dev/MAKEDEV)
-               NEED_MAKEDEV=true
+               touch "${TEMPROOT}"/.etcupdate.NEED_MAKEDEV
                ;;
        /dev/MAKEDEV.local)
-               NEED_MAKEDEV=true
+               touch "${TEMPROOT}"/.etcupdate.NEED_MAKEDEV
                ;;
        /etc/mail/aliases)
-               NEED_NEWALIASES=true
+               touch "${TEMPROOT}"/.etcupdate.NEED_NEWALIASES
                ;;
        /etc/master.passwd)
-               NEED_PWD_MKDB=true
+               touch "${TEMPROOT}"/.etcupdate.NEED_PWD_MKDB
                ;;
        /etc/services)
-               NEED_SERVICES_MKDB=true
+               touch "${TEMPROOT}"/.etcupdate.NEED_SERVICES_MKDB
                ;;
        esac
 }
@@ -744,12 +737,6 @@
        echo "${REMAINING}" | sed -e 's/^/  /'
        echo ""
 fi
-if yesno "Remove ${TEMPROOT}"; then
-       echo "*** Removing ${TEMPROOT}"
-       rm -rf "${TEMPROOT}"
-else
-       echo "*** Keeping ${TEMPROOT}"
-fi
 
 # Clean up after "make distribution"
 if ${SOURCEMODE}; then
@@ -764,7 +751,8 @@
 fi
 
 # Do some post-installation tasks
-if ${NEED_PWD_MKDB}; then
+if test -f "${TEMPROOT}"/.etcupdate.NEED_PWD_MKDB; then
+       rm "${TEMPROOT}"/.etcupdate.NEED_PWD_MKDB
        if yesno "Do you want to rebuild the password databases from the" \
                 "new master.passwd"
        then
@@ -780,13 +768,14 @@
        fi
 fi
 
-if ! ${NEED_SERVICES_MKDB}; then
+if ! test -f "${TEMPROOT}"/.etcupdate.NEED_SERVICES_MKDB; then
        if test -e /var/db/services.db -a ! -e /var/db/services.cdb; then
-               NEED_SERVICES_MKDB=true
+               touch "${TEMPROOT}"/.etcupdate.NEED_SERVICES_MKDB
        fi
 fi
 
-if ${NEED_SERVICES_MKDB}; then
+if test -f "${TEMPROOT}"/.etcupdate.NEED_SERVICES_MKDB; then
+       rm "${TEMPROOT}"/.etcupdate.NEED_SERVICES_MKDB
        if yesno "Do you want to rebuild the services databases from the" \
                 "new /etc/services"
        then
@@ -800,14 +789,16 @@
                echo ""
        fi
 fi
-if ${NEED_MTREE}; then
+if test -f "${TEMPROOT}"/.etcupdate.NEED_MTREE; then
+       rm "${TEMPROOT}"/.etcupdate.NEED_MTREE
        if yesno "You have created new directories. Run mtree to set" \
                 "permissions"
        then
                (cd / && mtree -Udef /etc/mtree/NetBSD.dist)
        fi
 fi
-if ${NEED_MAKEDEV}; then
+if test -f "${TEMPROOT}"/.etcupdate.NEED_MAKEDEV; then
+       rm "${TEMPROOT}"/.etcupdate.NEED_MAKEDEV
        if yesno "Do you want to rebuild the device nodes in /dev"; then
                verbose "Running MAKEDEV in /dev"
                (cd "/dev" && ./MAKEDEV all)
@@ -819,7 +810,8 @@
                echo ""
        fi
 fi
-if ${NEED_NEWALIASES}; then
+if test -f "${TEMPROOT}"/.etcupdate.NEED_NEWALIASES; then
+       rm "${TEMPROOT}"/.etcupdate.NEED_NEWALIASES
        if yesno "Do you want to rebuild the mail alias database"; then
                verbose "Running newaliases"
                newaliases
@@ -831,6 +823,14 @@
                echo ""
        fi
 fi
+
+if yesno "Remove ${TEMPROOT}"; then
+       echo "*** Removing ${TEMPROOT}"
+       rm -rf "${TEMPROOT}"
+else
+       echo "*** Keeping ${TEMPROOT}"
+fi
+
 if [ -x /usr/sbin/postinstall ]; then
        echo "*** Running /usr/sbin/postinstall"
        eval "/usr/sbin/postinstall ${SRC_ARGLIST} check"

Reply via email to