Source-Changes-HG archive

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

[src/trunk]: src/external/public-domain/tz Make this more automated - no long...



details:   https://anonhg.NetBSD.org/src/rev/ce37dca0494b
branches:  trunk
changeset: 831352:ce37dca0494b
user:      kre <kre%NetBSD.org@localhost>
date:      Sat Mar 24 01:54:48 2018 +0000

description:
Make this more automated - no longer requires editing the
script before use.   Also update to reflect a few changes
to procedures that have occurred here and there in the past.

diffstat:

 external/public-domain/tz/tzdata2netbsd |  354 ++++++++++++++++++++++++++-----
 1 files changed, 298 insertions(+), 56 deletions(-)

diffs (truncated from 453 to 300 lines):

diff -r b7757e1e7f71 -r ce37dca0494b external/public-domain/tz/tzdata2netbsd
--- a/external/public-domain/tz/tzdata2netbsd   Sat Mar 24 01:52:26 2018 +0000
+++ b/external/public-domain/tz/tzdata2netbsd   Sat Mar 24 01:54:48 2018 +0000
@@ -1,57 +1,239 @@
-# $NetBSD: tzdata2netbsd,v 1.11 2016/11/03 10:11:05 kre Exp $
+# $NetBSD: tzdata2netbsd,v 1.12 2018/03/24 01:54:48 kre Exp $
 
 # For use by NetBSD developers when updating to new versions of tzdata.
 #
 # 0. Be in an up-to-date checkout of src/external/public-domain/tz
 #    from NetBSD-current.
-# 1. Edit OLDVER and NEWVER below.
-# 2. Make sure that you have Paul Eggert's 4K RSA public key in your
-#    keyring (62AA7E34, eggert%cs.ucla.edu@localhost)
-# 3. Run this script.  You will be prompted for confirmation before
-#    anything major (such as a cvs operation).
-# 4. If something fails, abort the script and fix it.
-# 5. Re-run this script until you are happy.  It's designed to
+# 1. Make sure that you have Paul Eggert's 4K RSA public key in your
+#    keyring (62AA7E34, eggert%cs.ucla.edu@localhost)  It is not required that it be trusted.
+# 2. Run this script.  You will be prompted for confirmation before
+#    anything major (such as a cvs operation).  The tz versions can be
+#    specified as args (new version first, and the previous second) if
+#    needed to override the calculated values
+# 3. If something fails, abort the script and fix it.
+# 4. Re-run this script until you are happy.  It's designed to
 #    be re-run over and over, and later runs will try not to
 #    redo non-trivial work done by earlier runs.
 #
 
-OLDVER=2016h
-NEWVER=2016i
-
-# Uppercase variants of OLDVER and NEWVER
-OLDVER_UC="$( echo "${OLDVER}" | tr '[a-z]' '[A-Z]' )"
-NEWVER_UC="$( echo "${NEWVER}" | tr '[a-z]' '[A-Z]' )"
-
-# Tags for use with version control systems
-CVSOLDTAG="TZDATA${OLDVER_UC}"
-CVSNEWTAG="TZDATA${NEWVER_UC}"
-CVSBRANCHTAG="TZDATA"
-GITHUBTAG="${NEWVER}"
-
-# URLs for fetching distribution files, etc.
-DISTURL="ftp://ftp.iana.org/tz/releases/tzdata${NEWVER}.tar.gz";
-SIGURL="${DISTURL}.asc"
-NEWSURL="https://github.com/eggert/tz/raw/${GITHUBTAG}/NEWS";
+VERS_PATTERN='2[0-9][0-9][0-9][a-z]'
+# This needs to be updated twice every millennium to allow for the
+# new millenium's years.
+# First in the late xx90's sometime, allow the new one by changing the leading
+# digit from a specific value to the class containing the current and
+# following values (eg: in 2098 or so, change '2' to be '[23]').
+# Tnen in the following early xx00's sometime, delete the class, and insert
+# leave only the current value as valid (eg: in 3001 or 3002,
+# change '[23]' to be just '3'
+# Doing it this way helps guard against invalid specifications.
+# We could automate this, but it is (IMO) not worth the cost, to avoid a
+# twice a millenium edit requirement.
+# A more significant (and harder) change will be needed in the late 9990's
+# If this script lasts until then, send me a postcard, I'll be waiting for it!
+# Things get easier again after that until the late 99990's (etc.)
 
-# Directories
-REPODIR="src/external/public-domain/tz/dist" # relative to the NetBSD CVS repo
-TZDISTDIR="$(pwd)/dist" # should be .../external/public-domain/tz/dist
-WORKDIR="$(pwd)/update-work/${NEWVER}"
-EXTRACTDIR="${WORKDIR}/extract"
+# Note the pattern is used on both the old and new version specifiers,
+# so it must be able to cope with the shift from one form (eg 2999g)
+# to the new one (eg: 3000a) without failing (or the code that uses it
+# below needs to be updated).
 
-# Files in the work directory
-DISTFILE="${WORKDIR}/${DISTURL##*/}"
-SIGFILE="${DISTFILE}.sig"
-PGPVERIFYLOG="${WORKDIR}/pgpverify.log"
-NEWSFILE="${WORKDIR}/NEWS"
-NEWSTRIMFILE="${WORKDIR}/NEWS.trimmed"
-IMPORTMSGFILE="${WORKDIR}/import.msg"
-IMPORTDONEFILE="${WORKDIR}/import.done"
-MERGSMSGFILE="${WORKDIR}/merge.msg"
-MERGEDONEFILE="${WORKDIR}/merge.done"
-COMMITMERGEDONEFILE="${WORKDIR}/commitmerge.done"
+# Also note that the option of having a second alpha (1997aa or something)
+# to handle years with much activity is handled below, the pattern does not
+# need to match those.
+# If that convention changes (as of date of writing, it has never been
+# exercised) then code changes below will be required.
+
+DIST_HOST=ftp.iana.org
+DIST_PATH=tz
+DIST_FILES=releases
 
 EDITOR=${EDITOR:-vi}
+WORK_PFX=$(pwd)/update-work || fail "Cannot obtain PWD"
+UPDATE_FROM=${WORK_PFX}/updating.from.version
+
+usage()
+{
+       printf >&2 '%s\n'                                               \
+               "Usage: $0 [new-version-id [old-version-id]]"           \
+               "     where a version-id is of the form YYYYx (eg: 2018c)" \
+               "     or '' for new-version-id (to specify only the old)"
+       exit 2
+}
+
+fail()
+{
+       local IFS=' '
+
+       printf >&2 '%s\n'       "Error detected:" "   $*" "Aborting."
+       exit 1
+}
+
+valid_vers()
+{
+       case "$2" in
+       ${VERS_PATTERN} | ${VERS_PATTERN}[a-z] )
+               ;;
+       *)      printf >&2 '%s: %s\n' \
+                   "Bad form for $1 version specifier '$2'" \
+                   "should (usually) be 'YYYYx'"
+               return 1
+               ;;
+       esac
+       return 0
+}
+
+get_curvers()
+{
+       local LF=''
+       local LIST=iana-listing
+       local SED_SCRIPT='
+               /tzdata-latest.*-> /{
+                       s/^.*-> //
+                       s/\..*$//
+                       s;^releases/tzdata;;p
+                       q
+               }
+               d'
+
+       test -d "${WORK_PFX}" &&
+               test -s "${WORK_PFX}/${LIST}" &&
+               test "${WORK_PFX}/${LIST}" -nt dist/CVS &&
+               LF=$(find "${WORK_PFX}" -name "${LIST}" -mtime -1 -print) &&
+               test -n "${LF}" &&
+               NEWVER=$(sed -n < "${LF}" "${SED_SCRIPT}") &&
+               valid_vers new "${NEWVER}"                              ||
+
+       ftp >/dev/null 2>&1 -ia "${DIST_HOST}" <<- EOF &&
+                                       dir ${DIST_PATH} ${WORK_PFX}/${LIST}
+                                       quit
+                                       EOF
+               test -s "${WORK_PFX}/${LIST}" &&
+               NEWVER=$(sed -n < "${WORK_PFX}/${LIST}" "${SED_SCRIPT}") &&
+               valid_vers new "${NEWVER}"                              ||
+
+       {
+               rm -f "${WORK_PFX}/${LIST}"
+               fail "Cannot fetch current tzdata version from ${DIST_HOST}"
+       }
+
+       printf '%s\n' "Updating from ${OLDVER} to ${NEWVER}"
+}
+
+argparse()
+{
+       local OVF
+
+       if OVF=$(find "${WORK_PFX}" -name "${UPDATE_FROM##*/}" -mtime +2 -print)
+       then
+               # delete anything old
+               test -n "${OVF}" && rm -f "${OVF}"
+       fi
+
+       case "$#" in
+       0|1)
+               # once we have obtained OLDVER once, never guess it again.
+               test -f "${UPDATE_FROM}" && OLDVER=$(cat "${UPDATE_FROM}") ||
+
+               OLDVER=$(cat dist/version) || {
+                       printf >&2 '%s\n'  \
+                           "Cannot determine current installed version"  \
+                           "Specify it on the command line."  \
+                           ""
+                       usage
+               }
+
+               valid_vers old "${OLDVER}" ||
+                       fail "Calculated bad OLDVER, give as 2nd arg"
+               ;;
+
+       2)      valid_vers old "$2" && OLDVER="$2" || usage
+               ;;
+
+       *)      usage
+               ;;
+       esac
+
+       case "$#:$1" in
+       0: | 1: | 2: )
+               ;;
+       1:?*|2:?*)      
+               valid_vers new "$1" && NEWVER="$1" || usage
+               ;;
+       *)      usage
+               ;;
+       esac
+
+       test -z "${NEWVER}" && get_curvers
+
+       test "${NEWVER}" = "${OLDVER}" && {
+               printf '%s\n' \
+                    "New and old versions both ${NEWVER}: nothing to do"
+               exit 0
+
+       }
+
+       printf '%s\n' "${OLDVER}" > "${UPDATE_FROM}" ||
+           fail "Unable to preserve old version ${OLDVER} in ${UPDATE_FROM}"
+
+       test "${#NEWVER}" -gt "${#OLDVER}" ||
+               test "${NEWVER}" '>' "${OLDVER}" ||
+               {
+                       local reply
+
+                       printf '%s\n' \
+                           "Update would revert ${OLDVER} to ${NEWVER}"
+                       read -p "Is reversion intended? " reply
+                       case "${reply}" in
+                       [Yy]*)  ;;
+                       *)      printf '%s\n' OK. Aborted.
+                               rm -f "${UPDATE_FROM}"
+                               exit 1
+                               ;;
+                       esac
+               }
+
+       return 0
+}
+
+setup_versions()
+{
+       # Uppercase variants of OLDVER and NEWVER
+       OLDVER_UC="$( echo "${OLDVER}" | tr '[a-z]' '[A-Z]' )"
+       NEWVER_UC="$( echo "${NEWVER}" | tr '[a-z]' '[A-Z]' )"
+
+       # Tags for use with version control systems
+       CVSOLDTAG="TZDATA${OLDVER_UC}"
+       CVSNEWTAG="TZDATA${NEWVER_UC}"
+       CVSBRANCHTAG="TZDATA"
+       GITHUBTAG="${NEWVER}"
+
+       # URLs for fetching distribution files, etc.
+       DISTURL="ftp://${DIST_HOST}/${DIST_PATH}/${DIST_FILES}";
+       DISTURL="${DISTURL}/tzdata${NEWVER}.tar.gz"
+       SIGURL="${DISTURL}.asc"
+       NEWSURL="https://github.com/eggert/tz/raw/${GITHUBTAG}/NEWS";
+
+       # Directories
+       REPODIR="src/external/public-domain/tz/dist"
+                               # relative to the NetBSD CVS repo
+       TZDISTDIR="$(pwd)/dist" # should be .../external/public-domain/tz/dist
+       WORKDIR="${WORK_PFX}/${NEWVER}"
+       EXTRACTDIR="${WORKDIR}/extract"
+
+       # Files in the work directory
+       DISTFILE="${WORKDIR}/${DISTURL##*/}"
+       SIGFILE="${DISTFILE}.asc"
+       PGPVERIFYLOG="${WORKDIR}/pgpverify.log"
+       NEWSFILE="${WORKDIR}/NEWS"
+       NEWSTRIMFILE="${WORKDIR}/NEWS.trimmed"
+       IMPORTMSGFILE="${WORKDIR}/import.msg"
+       IMPORTDONEFILE="${WORKDIR}/import.done"
+       MERGSMSGFILE="${WORKDIR}/merge.msg"
+       MERGEDONEFILE="${WORKDIR}/merge.done"
+       COMMITMERGEDONEFILE="${WORKDIR}/commitmerge.done"
+
+       printf '%s\n' "${CVSOLDTAG}"  > "${WORK_PFX}/updating_from"
+}
 
 DOIT()
 {
@@ -68,6 +250,9 @@
                echo "Aborting"
                return 1
                ;;
+       *)      echo "Huh?"
+               return 1
+               ;;
        esac
        if $really_do_it; then
                echo "REALLY DOING IT NOW..."
@@ -87,7 +272,7 @@
 #    eval "\$command $quotedlist \$filename"
 #
 shell_quote()
-{(
+(



Home | Main Index | Thread Index | Old Index