Module Name:    src
Committed By:   apb
Date:           Sun May 18 16:53:56 UTC 2014

Modified Files:
        src/share/zoneinfo: tzdata2netbsd

Log Message:
Many changes to tzdata2netbsd.
This has been tested in a private repository.

* Use set -e
* Pass -d ${CVSROOT} to all cvs invocations.  cvs import needs it.
* cvs import needs to be done in the directory where the tarball
  was extracted.
* cvs import does not take a "-F messagefile" option (as cvs commit does);
  it needs "-m messagestring".
* The DOIT function now prompts for a yes/no/quit response, and quotes
  complex arguments when printing the command.
* When checking the PGP signature, require the correct key to have been used.
* Usability improvements when editing the cvs log message.
* More error checking.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/zoneinfo/tzdata2netbsd

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

Modified files:

Index: src/share/zoneinfo/tzdata2netbsd
diff -u src/share/zoneinfo/tzdata2netbsd:1.1 src/share/zoneinfo/tzdata2netbsd:1.2
--- src/share/zoneinfo/tzdata2netbsd:1.1	Sat May 17 19:53:22 2014
+++ src/share/zoneinfo/tzdata2netbsd	Sun May 18 16:53:56 2014
@@ -1,4 +1,4 @@
-# $NetBSD: tzdata2netbsd,v 1.1 2014/05/17 19:53:22 apb Exp $
+# $NetBSD: tzdata2netbsd,v 1.2 2014/05/18 16:53:56 apb Exp $
 #
 # For use by NetBSD developers when updating to new versions of tzdata.
 #
@@ -33,18 +33,72 @@ NEWSFILE="${WORKDIR}/NEWS"
 NEWSTRIMFILE="${WORKDIR}/NEWS.trimmed"
 IMPORTMSGFILE="${WORKDIR}/import.msg"
 MERGSMSGFILE="${WORKDIR}/merge.msg"
+PGPVERIFYLOG="${WORKDIR}/pgpverify.log"
 
 DOIT()
 {
-	really_do_it=false
+	local really_do_it=false
+	local reply
 
+	echo "ABOUT TO DO:" "$(shell_quote "$@")"
+	read -p "Really do it? [yes/no/quit] " reply
+	case "${reply}" in
+	[yY]*)	really_do_it=true ;;
+	[nN]*)	really_do_it=false ;;
+	[qQ]*)
+		echo "Aborting"
+		return 1
+		;;
+	esac
 	if $really_do_it; then
+		echo "REALLY DOING IT NOW..."
 		"$@"
 	else
 		echo "NOT REALLY DOING:" "$@"
 	fi
 }
 
+# Quote args to make them safe in the shell.
+# Usage: quotedlist="$(shell_quote args...)"
+#
+# After building up a quoted list, use it by evaling it inside
+# double quotes, like this:
+#    eval "set -- $quotedlist"
+# or like this:
+#    eval "\$command $quotedlist \$filename"
+shell_quote()
+{
+	local result=''
+	local arg qarg
+	for arg in "$@" ; do
+		case "${arg}" in
+		''|*[!-./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.
+			qarg="$(printf "%s\n" "$arg" | \
+			    sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
+			;;
+		*)
+			# Arg is not the empty string, and does not contain
+			# any unsafe characters.
+			qarg="${arg}"
+			;;
+		esac
+		result="${result}${result:+ }${qarg}"
+	done
+	printf "%s\n" "$result"
+}
+
+findcvsroot()
+{
+	[ -n "${CVSROOT}" ] && return 0
+	CVSROOT="$( cat ./CVS/Root )"
+	[ -n "${CVSROOT}" ] && return 0
+	echo >&2 "Failed to set CVSROOT value"
+	return 1
+}
+
 mkworkdir()
 {
 	mkdir -p "${WORKDIR}"
@@ -59,7 +113,23 @@ fetch()
 
 checksig()
 {
-	gpg --verify "${SIGFILE}" "${DISTFILE}"
+	{ gpg --verify "${SIGFILE}" "${DISTFILE}"
+	  echo gpg exit status $?
+	} 2>&1 | tee "${PGPVERIFYLOG}"
+
+	# The output should contain lines that match all the following regexps
+	#
+	while read line; do
+		if ! grep -q -e "^${line}\$" "${PGPVERIFYLOG}"; then
+			echo >&2 "Failed to verify signature: ${line}"
+			return 1
+		fi
+	done <<'EOF'
+gpg: Signature made .* using RSA key ID 62AA7E34
+gpg: Good signature from "Paul Eggert <egg...@cs.ucla.edu>"
+Primary key fingerprint: 7E37 92A9 D8AC F7D6 33BC  1588 ED97 E90E 62AA 7E34
+gpg exit status 0
+EOF
 }
 
 extract()
@@ -68,10 +138,8 @@ extract()
 	tar -z -xf "${DISTFILE}" -C "${EXTRACTDIR}"
 }
 
-# Each release has a heading in the NEWS file, like
-# "Release <version> - <date>".
-# Find the relevant part of the NEWS file for all release between
-# OLDVAR and NEWVER, and save them to NEWSTRIMFILE.
+# Find the relevant part of the NEWS file for all releases between
+# OLDVER and NEWVER, and save them to NEWSTRIMFILE.
 #
 trimnews()
 {
@@ -79,6 +147,7 @@ trimnews()
 	    '
 		BEGIN {inrange = 0}
 		/^Release [0-9]+[a-z]+ - .*/ {
+			# "Release <version> - <date>"
 			inrange = ($2 > oldver && $2 <= newver)
 		}
 		// { if (inrange) print; }
@@ -88,12 +157,21 @@ trimnews()
 
 # Create IMPORTMSGFILE from NEWSTRIMFILE, by ignoring some sections,
 # keeping only the first sentence from paragraphs in other sections,
-# and changing the format.  The result should be edited by hand before
-# performing a cvs commit.
+# and changing the format.
+#
+# The result should be edited by hand before performing a cvs commit.
+# A message to that effect is inserted at the beginning of the file.
 #
 mkimportmsg()
 {
 	[ -s "${IMPORTMSGFILE}" ] && return
+	{ cat <<EOF
+EDIT ME: Edit this file and then delete the lines marked "EDIT ME".
+EDIT ME: This file will be used as a log message for the "cvs commit" that
+EDIT ME: imports tzdata${NEWVER}.  The initial contents of this file were
+EDIT ME: generated from ${NEWSFILE}.
+EDIT ME: 
+EOF
 	awk -v oldver="${OLDVER}" -v newver="${NEWVER}" \
 	    -v disturl="${DISTURL}" \
 	    '
@@ -106,6 +184,7 @@ mkimportmsg()
 			print "Import tzdata"newver" from "disturl;
 		}
 		/^Release/ {
+			# "Release <version> - <date>"
 			ver = $2;
 			date = gensub(".* - ", "", 1, $0);
 			print "";
@@ -135,27 +214,43 @@ mkimportmsg()
 		}
 		/./ { blankline = 0; }
 		' \
-		<"${NEWSTRIMFILE}" >"${IMPORTMSGFILE}"
+		<"${NEWSTRIMFILE}"
+	} >"${IMPORTMSGFILE}"
 }
 
 editimportmsg()
 {
-	cat <<EOF
-Edit ${IMPORTMSGFILE##%/}, which will be used as a log message
-for "cvs import".  A template has been prepared from the NEWS file.
-EOF
+	if [ -s "${IMPORTMSGFILE}" ] \
+	&& ! grep -q '^EDIT' "${IMPORTMSGFILE}"
+	then
+		return 0 # file has already been edited
+	fi
+	# Pass both IMPORTMSGFILE and NEWSFILE to the editor, so that the
+	# user can easily consult NEWSFILE while editing IMPORTMSGFILE.
 	vi "${IMPORTMSGFILE}" "${NEWSFILE}"
 }
 
 cvsimport()
 {
-	DOIT cvs import -F "${IMPORTMSGFILE}" \
+	if ! [ -s "${IMPORTMSGFILE}" ] \
+	|| grep -q '^EDIT' "${IMPORTMSGFILE}"
+	then
+		cat >&2 <<EOF
+The message file ${IMPORTMSGFILE}
+has not been properly edited.
+Not performing cvs import.
+EOF
+		return 1
+	fi
+	( cd "${EXTRACTDIR}" &&
+	  DOIT cvs -d "${CVSROOT}" import -m "$(cat "${IMPORTMSGFILE}")" \
 		"${REPODIR}" "${CVSBRANCHTAG}" "${CVSNEWTAG}"
+	)
 }
 
 cvsmerge()
 {
-	DOIT cvs update -j"${CVSOLDTAG}" -j"${CVSNEWTAG}"
+	DOIT cvs -d "${CVSROOT}" update -j"${CVSOLDTAG}" -j"${CVSNEWTAG}"
 }
 
 resolveconflicts()
@@ -171,7 +266,15 @@ EOF
 
 cvscommitmerge()
 {
-	DOIT cvs commit -m "Merge tzdata${NEWVER}"
+	if grep -l '^[<=>][<=>][<=>]' *
+	then
+		cat >&2 <<EOF
+There still appear to be conflicts in the files listed above.
+Not performing cvs commit.
+EOF
+		return 1
+	fi
+	DOIT cvs -d "${CVSROOT}" commit -m "Merge tzdata${NEWVER}"
 }
 
 extra()
@@ -180,6 +283,7 @@ extra()
 Also do the following:
  * Edit src/doc/3RDPARTY
  * Edit src/doc/CHANGES
+ * Edit src/distrib/sets/base/mi if the set of installed files has changed.
  * Submit pullup requests for all active release branches.
  * rm -rf ${WORKDIR}
 EOF
@@ -187,18 +291,20 @@ EOF
 
 main()
 {
-	mkworkdir || exit $?
-	fetch || exit $?
-	checksig || exit $?
-	extract || exit $?
-	trimnews || exit $?
-	mkimportmsg || exit $?
-	editimportmsg || exit $?
-	cvsimport || exit $?
-	cvsmerge || exit $?
-	resolveconflicts || exit $?
-	cvscommitmerge || exit $?
-	extra || exit $?
+	set -e
+	findcvsroot
+	mkworkdir
+	fetch
+	checksig
+	extract
+	trimnews
+	mkimportmsg
+	editimportmsg
+	cvsimport
+	cvsmerge
+	resolveconflicts
+	cvscommitmerge
+	extra
 }
 
 main "$@"

Reply via email to