Module Name:    src
Committed By:   tls
Date:           Sun Aug 10 07:00:05 UTC 2014

Modified Files:
        src/usr.sbin/postinstall [tls-earlyentropy]: postinstall

Log Message:
Rebase.


To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.165.2.1 src/usr.sbin/postinstall/postinstall

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/postinstall/postinstall
diff -u src/usr.sbin/postinstall/postinstall:1.165 src/usr.sbin/postinstall/postinstall:1.165.2.1
--- src/usr.sbin/postinstall/postinstall:1.165	Sat Mar  8 16:36:24 2014
+++ src/usr.sbin/postinstall/postinstall	Sun Aug 10 07:00:04 2014
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: postinstall,v 1.165 2014/03/08 16:36:24 martin Exp $
+# $NetBSD: postinstall,v 1.165.2.1 2014/08/10 07:00:04 tls Exp $
 #
 # Copyright (c) 2002-2008 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -58,6 +58,8 @@
 : ${HOST_SH:=sh}
 : ${MAKE:=make}
 : ${PWD_MKDB:=/usr/sbin/pwd_mkdb}
+: ${SED:=sed}
+: ${SORT:=sort}
 : ${STAT:=stat}
 
 #
@@ -110,22 +112,71 @@ mkdtemp()
 #    eval "set -- $quotedlist"
 # or like this:
 #    eval "\$command $quotedlist \$filename"
+#
 shell_quote()
-{
+{(
 	local result=''
-	local arg
+	local arg qarg
+	LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
 	for arg in "$@" ; do
-		# Append a space if necessary
-		result="${result}${result:+ }"
-		# Convert each embedded ' to '\'',
-		# then insert ' at the beginning of the first line,
-		# and append ' at the end of the last line.
-		result="${result}$(printf "%s\n" "$arg" | \
-			sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
+		case "${arg}" in
+		'')
+			qarg="''"
+			;;
+		*[!-./a-zA-Z0-9]*)
+			# Convert each embedded ' to '\'',
+			# then insert ' at the beginning of the first line,
+			# and append ' at the end of the last line.
+			# Finally, elide unnecessary '' pairs at the
+			# beginning and end of the result and as part of
+			# '\'''\'' sequences that result from multiple
+			# adjacent quotes in he input.
+			qarg="$(printf "%s\n" "$arg" | \
+			    ${SED:-sed} -e "s/'/'\\\\''/g" \
+				-e "1s/^/'/" -e "\$s/\$/'/" \
+				-e "1s/^''//" -e "\$s/''\$//" \
+				-e "s/'''/'/g"
+				)"
+			;;
+		*)
+			# Arg is not the empty string, and does not contain
+			# any unsafe characters.  Leave it unchanged for
+			# readability.
+			qarg="${arg}"
+			;;
+		esac
+		result="${result}${result:+ }${qarg}"
 	done
 	printf "%s\n" "$result"
-}
+)}
 
+# Convert arg $1 to a basic regular expression (as in sed)
+# that will match the arg.  This works by inserting backslashes
+# before characters that are special in basic regular expressions.
+# It also inserts backslashes before the extra characters specified
+# in $2 (which defaults to "/,").
+# XXX: Does not handle embedded newlines.
+# Usage: regex="$(bre_quote "${string}")"
+bre_quote()
+{
+	local arg="$1"
+	local extra="${2-/,}"
+	printf "%s\n" "${arg}" | ${SED} -e 's/[][^$.*\\'"${extra}"']/\\&/g'
+}
+
+# unprefix dir
+#	Remove any dir prefix from a list of paths on stdin,
+#	and write the result to stdout.  Useful for converting
+#	from ${DEST_DIR}/path to /path.
+#
+unprefix()
+{
+	[ $# -eq 1 ] || err 3 "USAGE: unprefix dir"
+	local prefix="${1%/}"
+	prefix="$(bre_quote "${prefix}")"
+
+	${SED} -e "s,^${prefix}/,/,"
+}
 
 # additem item description
 #	Add item to list of supported items to check/fix,
@@ -448,8 +499,8 @@ file_exists_exact()
 
 # obsolete_paths op
 #	Obsolete the list of paths provided on stdin.
-#	Each path is relative to ${DEST_DIR}, and should
-#	be an absolute path or start with `./'.
+#	Each path should start with '/' or './', and
+#	will be interpreted relative to ${DEST_DIR}.
 #
 obsolete_paths()
 {
@@ -561,6 +612,37 @@ function checklib(results, line, regex) 
 	)
 }
 
+# obsolete_stand dir
+#	Prints the names of all obsolete files and subdirs below the
+#	provided dir.  dir should be something like /stand/${MACHINE}.
+#	The input dir and all output paths are interpreted
+#	relative to ${DEST_DIR}.
+#
+#	Assumes that the numerically largest subdir is current, and all
+#	others are obsolete.
+#
+obsolete_stand()
+{
+	[ $# -eq 1 ] || err 3 "USAGE: obsolete_stand dir"
+	local dir="$1"
+	local subdir
+
+	if ! [ -d "${DEST_DIR}/${dir}" ]; then
+		msg "${DEST_DIR}${dir} doesn't exist; can't check for obsolete files"
+		return 1
+	fi
+
+	( cd "${DEST_DIR}${dir}" && ls -1d [0-9]*[0-9]/. ) \
+	| ${GREP} -v '[^0-9./]' \
+	| sort -t. -r -k1n -k2n -k3n \
+	| tail -n +2 \
+	| while read subdir ; do
+		subdir="${subdir%/.}"
+		find "${DEST_DIR}/${dir#/}/${subdir}" -depth -print
+	done \
+	| unprefix "${DEST_DIR}"
+}
+
 # modify_file op srcfile scratchfile awkprog
 #	Apply awkprog to srcfile sending output to scratchfile, and
 #	if appropriate replace srcfile with scratchfile.
@@ -718,9 +800,9 @@ do_ddbonpanic()
 			result=1
 		else
 			echo >> "${DEST_DIR}/etc/sysctl.conf"
-			sed < "${SRC_DIR}/etc/sysctl.conf" \
+			${SED} < "${SRC_DIR}/etc/sysctl.conf" \
 			   -e '/^ddb\.onpanic/q' | \
-			       sed -e '1,/^$/d' >> \
+			       ${SED} -e '1,/^$/d' >> \
 			    "${DEST_DIR}/etc/sysctl.conf"
 			result=$?
 		fi
@@ -1036,8 +1118,8 @@ do_motd()
 	then
 		tmp1="$(mktemp /tmp/postinstall.motd.XXXXXXXX)"
 		tmp2="$(mktemp /tmp/postinstall.motd.XXXXXXXX)"
-		sed '1,2d' <"${SRC_DIR}/etc/motd" >"${tmp1}"
-		sed '1,2d' <"${DEST_DIR}/etc/motd" >"${tmp2}"
+		${SED} '1,2d' <"${SRC_DIR}/etc/motd" >"${tmp1}"
+		${SED} '1,2d' <"${DEST_DIR}/etc/motd" >"${tmp2}"
 
 		if [ "$1" = check ]; then
 			cmp -s "${tmp1}" "${tmp2}"
@@ -1048,7 +1130,7 @@ do_motd()
 			fi
 		else
 			head -n 2 "${DEST_DIR}/etc/motd" >"${tmp1}"
-			sed '1,2d' <"${SRC_DIR}/etc/motd" >>"${tmp1}"
+			${SED} '1,2d' <"${SRC_DIR}/etc/motd" >>"${tmp1}"
 			cp "${tmp1}" "${DEST_DIR}/etc/motd"
 			result=0
 		fi
@@ -1258,7 +1340,7 @@ do_rc()
 		# generate scripts
 		mkdir "${SCRATCHDIR}/rc"
 		for f in ${generated_scripts}; do
-			sed -e "s,@X11ROOTDIR@,${X11ROOTDIR},g" \
+			${SED} -e "s,@X11ROOTDIR@,${X11ROOTDIR},g" \
 			    < "${SRC_DIR}/etc/rc.d/${f}.in" \
 			    > "${SCRATCHDIR}/rc/${f}"
 		done
@@ -1317,11 +1399,13 @@ do_sendmail()
 	for f in /etc/mail/helpfile /etc/mail/local-host-names \
 	    /etc/mail/sendmail.cf /etc/mail/submit.cf /etc/rc.d/sendmail \
 	    /etc/rc.d/smmsp /usr/share/misc/sendmail.hf \
-	    $(find "${DEST_DIR}/usr/share/sendmail" -type f) \
-	    $(find "${DEST_DIR}/usr/share/sendmail" -type d) \
-	    "${DEST_DIR}/var/log/sendmail.st" \
-	    "${DEST_DIR}/var/spool/clientmqueue" \
-	    "${DEST_DIR}/var/spool/mqueue"; do
+	    $( ( find "${DEST_DIR}/usr/share/sendmail" -type f ; \
+	         find "${DEST_DIR}/usr/share/sendmail" -type d \
+	       ) | unprefix "${DEST_DIR}" ) \
+	    /var/log/sendmail.st \
+	    /var/spool/clientmqueue \
+	    /var/spool/mqueue
+	do
 		[ -e "${DEST_DIR}${f}" ] && echo "${f}"
 	done | obsolete_paths "${op}"
 	failed=$(( ${failed} + $? ))
@@ -1570,7 +1654,7 @@ ${pcpath} was a directory, should be a f
 	# itself.  If the directory contains unexpected extra files
 	# then it will not be deleted.
 	( [ -f "${DEST_DIR}"/var/db/obsolete/xbase ] \
-	    &&  sort -ru "${DEST_DIR}"/var/db/obsolete/xbase \
+	    &&  ${SORT} -ru "${DEST_DIR}"/var/db/obsolete/xbase \
 	    | ${GREP} -E "^\\.?${pcpath}/" ;
 	    echo "${pcpath}" ) \
 	| obsolete_paths "${op}"
@@ -1697,7 +1781,7 @@ handle_atf_user()
 	if grep '[^#]*unprivileged-user[ \t]*=.*_atf' "${conf}" >/dev/null
 	then
 		if [ "$1" = "fix" ]; then
-			sed -e \
+			${SED} -e \
 			    "/[^#]*unprivileged-user[\ t]*=/s/_atf/_tests/" \
 			    "${conf}" >"${conf}.new"
 			failed=$(( ${failed} + $? ))
@@ -1790,6 +1874,11 @@ do_ptyfsoldnodes()
 		return 0
 	fi
 
+	if [ ! -e "${DEST_DIR}/dev/pts" ]; then
+		msg "ptyfs is not properly configured: missing /dev/pts"
+		return 1
+	fi
+
 	# Find the device major numbers for the pty master and slave
 	# devices, by parsing the output from "MAKEDEV -s pty0".
 	#
@@ -1888,6 +1977,21 @@ do_varshm()
 	return ${failed}
 }
 
+#
+#	obsolete_stand
+#
+adddisableditem obsolete_stand "remove obsolete files from /stand"
+do_obsolete_stand()
+{
+	[ -n "$1" ] || err 3 "USAGE: do_obsolete_stnd  fix|check"
+	op="$1"
+	failed=0
+
+	obsolete_stand "/stand/${MACHINE}" | obsolete_paths "${op}"
+	failed=$(( ${failed} + $? ))
+
+	return ${failed}
+}
 
 #
 #	obsolete
@@ -1900,7 +2004,7 @@ do_obsolete()
 	op="$1"
 	failed=0
 
-	sort -ru "${DEST_DIR}"/var/db/obsolete/* | obsolete_paths "${op}"
+	${SORT} -ru "${DEST_DIR}"/var/db/obsolete/* | obsolete_paths "${op}"
 	failed=$(( ${failed} + $? ))
 
 	(

Reply via email to