Home | History | Annotate | Line # | Download | only in tz
tzdata2netbsd revision 1.2.6.2
      1  1.2.6.2  tls # $NetBSD: tzdata2netbsd,v 1.2.6.2 2014/08/20 00:00:20 tls Exp $
      2  1.2.6.2  tls 
      3  1.2.6.2  tls # For use by NetBSD developers when updating to new versions of tzdata.
      4  1.2.6.2  tls #
      5  1.2.6.2  tls # 0. Be in an up-to-date checkout of src/external/public-domain/tz
      6  1.2.6.2  tls #    from NetBSD-current.
      7  1.2.6.2  tls # 1. Edit OLDVER and NEWVER below.
      8  1.2.6.2  tls # 3. Run this script.  You will be prompted for confirmation before
      9  1.2.6.2  tls #    anything major (such as a cvs operation).
     10  1.2.6.2  tls # 4. If something fails, abort the script and fix it.
     11  1.2.6.2  tls # 5. Re-run this script until you are happy.  It's designed to
     12  1.2.6.2  tls #    be re-run over and over, and later runs will try not to
     13  1.2.6.2  tls #    redo non-trivial work done by earlier runs.
     14  1.2.6.2  tls #
     15  1.2.6.2  tls 
     16  1.2.6.2  tls OLDVER=2014e
     17  1.2.6.2  tls NEWVER=2014f
     18  1.2.6.2  tls 
     19  1.2.6.2  tls # Uppercase variants of OLDVER and NEWVER
     20  1.2.6.2  tls OLDVER_UC="$( echo "${OLDVER}" | tr '[a-z]' '[A-Z]' )"
     21  1.2.6.2  tls NEWVER_UC="$( echo "${NEWVER}" | tr '[a-z]' '[A-Z]' )"
     22  1.2.6.2  tls 
     23  1.2.6.2  tls # Tags for use with version control systems
     24  1.2.6.2  tls CVSOLDTAG="TZDATA${OLDVER_UC}"
     25  1.2.6.2  tls CVSNEWTAG="TZDATA${NEWVER_UC}"
     26  1.2.6.2  tls CVSBRANCHTAG="TZDATA"
     27  1.2.6.2  tls GITHUBTAG="${NEWVER}"
     28  1.2.6.2  tls 
     29  1.2.6.2  tls # URLs for fetching distribution files, etc.
     30  1.2.6.2  tls DISTURL="ftp://ftp.iana.org/tz/releases/tzdata${NEWVER}.tar.gz"
     31  1.2.6.2  tls SIGURL="${DISTURL}.asc"
     32  1.2.6.2  tls NEWSURL="https://github.com/eggert/tz/raw/${GITHUBTAG}/NEWS"
     33  1.2.6.2  tls 
     34  1.2.6.2  tls # Directories
     35  1.2.6.2  tls REPODIR="src/external/public-domain/tz/dist" # relative to the NetBSD CVS repo
     36  1.2.6.2  tls WORKDIR="$(pwd)/update-work/${NEWVER}"
     37  1.2.6.2  tls EXTRACTDIR="${WORKDIR}/extract"
     38  1.2.6.2  tls 
     39  1.2.6.2  tls # Files in the work directory
     40  1.2.6.2  tls DISTFILE="${WORKDIR}/${DISTURL##*/}"
     41  1.2.6.2  tls SIGFILE="${DISTFILE}.sig"
     42  1.2.6.2  tls NEWSFILE="${WORKDIR}/NEWS"
     43  1.2.6.2  tls NEWSTRIMFILE="${WORKDIR}/NEWS.trimmed"
     44  1.2.6.2  tls IMPORTMSGFILE="${WORKDIR}/import.msg"
     45  1.2.6.2  tls MERGSMSGFILE="${WORKDIR}/merge.msg"
     46  1.2.6.2  tls PGPVERIFYLOG="${WORKDIR}/pgpverify.log"
     47  1.2.6.2  tls 
     48  1.2.6.2  tls DOIT()
     49  1.2.6.2  tls {
     50  1.2.6.2  tls 	local really_do_it=false
     51  1.2.6.2  tls 	local reply
     52  1.2.6.2  tls 
     53  1.2.6.2  tls 	echo "ABOUT TO DO:" "$(shell_quote "$@")"
     54  1.2.6.2  tls 	read -p "Really do it? [yes/no/quit] " reply
     55  1.2.6.2  tls 	case "${reply}" in
     56  1.2.6.2  tls 	[yY]*)	really_do_it=true ;;
     57  1.2.6.2  tls 	[nN]*)	really_do_it=false ;;
     58  1.2.6.2  tls 	[qQ]*)
     59  1.2.6.2  tls 		echo "Aborting"
     60  1.2.6.2  tls 		return 1
     61  1.2.6.2  tls 		;;
     62  1.2.6.2  tls 	esac
     63  1.2.6.2  tls 	if $really_do_it; then
     64  1.2.6.2  tls 		echo "REALLY DOING IT NOW..."
     65  1.2.6.2  tls 		"$@"
     66  1.2.6.2  tls 	else
     67  1.2.6.2  tls 		echo "NOT REALLY DOING THE ABOVE COMMAND"
     68  1.2.6.2  tls 	fi
     69  1.2.6.2  tls }
     70  1.2.6.2  tls 
     71  1.2.6.2  tls # Quote args to make them safe in the shell.
     72  1.2.6.2  tls # Usage: quotedlist="$(shell_quote args...)"
     73  1.2.6.2  tls #
     74  1.2.6.2  tls # After building up a quoted list, use it by evaling it inside
     75  1.2.6.2  tls # double quotes, like this:
     76  1.2.6.2  tls #    eval "set -- $quotedlist"
     77  1.2.6.2  tls # or like this:
     78  1.2.6.2  tls #    eval "\$command $quotedlist \$filename"
     79  1.2.6.2  tls #
     80  1.2.6.2  tls shell_quote()
     81  1.2.6.2  tls {(
     82  1.2.6.2  tls 	local result=''
     83  1.2.6.2  tls 	local arg qarg
     84  1.2.6.2  tls 	LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
     85  1.2.6.2  tls 	for arg in "$@" ; do
     86  1.2.6.2  tls 		case "${arg}" in
     87  1.2.6.2  tls 		'')
     88  1.2.6.2  tls 			qarg="''"
     89  1.2.6.2  tls 			;;
     90  1.2.6.2  tls 		*[!-./a-zA-Z0-9]*)
     91  1.2.6.2  tls 			# Convert each embedded ' to '\'',
     92  1.2.6.2  tls 			# then insert ' at the beginning of the first line,
     93  1.2.6.2  tls 			# and append ' at the end of the last line.
     94  1.2.6.2  tls 			# Finally, elide unnecessary '' pairs at the
     95  1.2.6.2  tls 			# beginning and end of the result and as part of
     96  1.2.6.2  tls 			# '\'''\'' sequences that result from multiple
     97  1.2.6.2  tls 			# adjacent quotes in he input.
     98  1.2.6.2  tls 			qarg="$(printf "%s\n" "$arg" | \
     99  1.2.6.2  tls 			    ${SED:-sed} -e "s/'/'\\\\''/g" \
    100  1.2.6.2  tls 				-e "1s/^/'/" -e "\$s/\$/'/" \
    101  1.2.6.2  tls 				-e "1s/^''//" -e "\$s/''\$//" \
    102  1.2.6.2  tls 				-e "s/'''/'/g"
    103  1.2.6.2  tls 				)"
    104  1.2.6.2  tls 			;;
    105  1.2.6.2  tls 		*)
    106  1.2.6.2  tls 			# Arg is not the empty string, and does not contain
    107  1.2.6.2  tls 			# any unsafe characters.  Leave it unchanged for
    108  1.2.6.2  tls 			# readability.
    109  1.2.6.2  tls 			qarg="${arg}"
    110  1.2.6.2  tls 			;;
    111  1.2.6.2  tls 		esac
    112  1.2.6.2  tls 		result="${result}${result:+ }${qarg}"
    113  1.2.6.2  tls 	done
    114  1.2.6.2  tls 	printf "%s\n" "$result"
    115  1.2.6.2  tls )}
    116  1.2.6.2  tls 
    117  1.2.6.2  tls findcvsroot()
    118  1.2.6.2  tls {
    119  1.2.6.2  tls 	[ -n "${CVSROOT}" ] && return 0
    120  1.2.6.2  tls 	CVSROOT="$( cat ./CVS/Root )"
    121  1.2.6.2  tls 	[ -n "${CVSROOT}" ] && return 0
    122  1.2.6.2  tls 	echo >&2 "Failed to set CVSROOT value"
    123  1.2.6.2  tls 	return 1
    124  1.2.6.2  tls }
    125  1.2.6.2  tls 
    126  1.2.6.2  tls mkworkdir()
    127  1.2.6.2  tls {
    128  1.2.6.2  tls 	mkdir -p "${WORKDIR}"
    129  1.2.6.2  tls }
    130  1.2.6.2  tls 
    131  1.2.6.2  tls fetch()
    132  1.2.6.2  tls {
    133  1.2.6.2  tls 	[ -f "${DISTFILE}" ] || ftp -o "${DISTFILE}" "${DISTURL}"
    134  1.2.6.2  tls 	[ -f "${SIGFILE}" ] || ftp -o "${SIGFILE}" "${SIGURL}"
    135  1.2.6.2  tls 	[ -f "${NEWSFILE}" ] || ftp -o "${NEWSFILE}" "${NEWSURL}"
    136  1.2.6.2  tls }
    137  1.2.6.2  tls 
    138  1.2.6.2  tls checksig()
    139  1.2.6.2  tls {
    140  1.2.6.2  tls 	{ gpg --verify "${SIGFILE}" "${DISTFILE}"
    141  1.2.6.2  tls 	  echo gpg exit status $?
    142  1.2.6.2  tls 	} 2>&1 | tee "${PGPVERIFYLOG}"
    143  1.2.6.2  tls 
    144  1.2.6.2  tls 	# The output should contain lines that match all the following regexps
    145  1.2.6.2  tls 	#
    146  1.2.6.2  tls 	while read line; do
    147  1.2.6.2  tls 		if ! grep -q -e "^${line}\$" "${PGPVERIFYLOG}"; then
    148  1.2.6.2  tls 			echo >&2 "Failed to verify signature: ${line}"
    149  1.2.6.2  tls 			return 1
    150  1.2.6.2  tls 		fi
    151  1.2.6.2  tls 	done <<'EOF'
    152  1.2.6.2  tls gpg: Signature made .* using RSA key ID 62AA7E34
    153  1.2.6.2  tls gpg: Good signature from "Paul Eggert <eggert (a] cs.ucla.edu>"
    154  1.2.6.2  tls Primary key fingerprint: 7E37 92A9 D8AC F7D6 33BC  1588 ED97 E90E 62AA 7E34
    155  1.2.6.2  tls gpg exit status 0
    156  1.2.6.2  tls EOF
    157  1.2.6.2  tls }
    158  1.2.6.2  tls 
    159  1.2.6.2  tls extract()
    160  1.2.6.2  tls {
    161  1.2.6.2  tls 	[ -f "${EXTRACTDIR}/zone.tab" ] && return
    162  1.2.6.2  tls 	mkdir -p "${EXTRACTDIR}"
    163  1.2.6.2  tls 	tar -z -xf "${DISTFILE}" -C "${EXTRACTDIR}"
    164  1.2.6.2  tls }
    165  1.2.6.2  tls 
    166  1.2.6.2  tls addnews()
    167  1.2.6.2  tls {
    168  1.2.6.2  tls 	[ -f "${EXTRACTDIR}/NEWS" ] && return
    169  1.2.6.2  tls 	cp -p "${NEWSFILE}" "${EXTRACTDIR}"/NEWS
    170  1.2.6.2  tls }
    171  1.2.6.2  tls 
    172  1.2.6.2  tls # Find the relevant part of the NEWS file for all releases between
    173  1.2.6.2  tls # OLDVER and NEWVER, and save them to NEWSTRIMFILE.
    174  1.2.6.2  tls #
    175  1.2.6.2  tls trimnews()
    176  1.2.6.2  tls {
    177  1.2.6.2  tls 	[ -s "${NEWSTRIMFILE}" ] && return
    178  1.2.6.2  tls 	awk -v oldver="${OLDVER}" -v newver="${NEWVER}" \
    179  1.2.6.2  tls 	    '
    180  1.2.6.2  tls 		BEGIN {inrange = 0}
    181  1.2.6.2  tls 		/^Release [0-9]+[a-z]+ - .*/ {
    182  1.2.6.2  tls 			# "Release <version> - <date>"
    183  1.2.6.2  tls 			inrange = ($2 > oldver && $2 <= newver)
    184  1.2.6.2  tls 		}
    185  1.2.6.2  tls 		// { if (inrange) print; }
    186  1.2.6.2  tls 		' \
    187  1.2.6.2  tls 		<"${NEWSFILE}" >"${NEWSTRIMFILE}"
    188  1.2.6.2  tls }
    189  1.2.6.2  tls 
    190  1.2.6.2  tls # Create IMPORTMSGFILE from NEWSTRIMFILE, by ignoring some sections,
    191  1.2.6.2  tls # keeping only the first sentence from paragraphs in other sections,
    192  1.2.6.2  tls # and changing the format.
    193  1.2.6.2  tls #
    194  1.2.6.2  tls # The result should be edited by hand before performing a cvs commit.
    195  1.2.6.2  tls # A message to that effect is inserted at the beginning of the file.
    196  1.2.6.2  tls #
    197  1.2.6.2  tls mkimportmsg()
    198  1.2.6.2  tls {
    199  1.2.6.2  tls 	[ -s "${IMPORTMSGFILE}" ] && return
    200  1.2.6.2  tls 	{ cat <<EOF
    201  1.2.6.2  tls EDIT ME: Edit this file and then delete the lines marked "EDIT ME".
    202  1.2.6.2  tls EDIT ME: This file will be used as a log message for the "cvs commit" that
    203  1.2.6.2  tls EDIT ME: imports tzdata${NEWVER}.  The initial contents of this file were
    204  1.2.6.2  tls EDIT ME: generated from ${NEWSFILE}.
    205  1.2.6.2  tls EDIT ME: 
    206  1.2.6.2  tls EOF
    207  1.2.6.2  tls 	awk -v oldver="${OLDVER}" -v newver="${NEWVER}" \
    208  1.2.6.2  tls 	    -v disturl="${DISTURL}" -v newsurl="${NEWSURL}" \
    209  1.2.6.2  tls 	    '
    210  1.2.6.2  tls 		BEGIN {
    211  1.2.6.2  tls 			bullet = "  * ";
    212  1.2.6.2  tls 			indent = "    ";
    213  1.2.6.2  tls 			blankline = 0;
    214  1.2.6.2  tls 			goodsection = 0;
    215  1.2.6.2  tls 			havesentence = 0;
    216  1.2.6.2  tls 			print "Import tzdata"newver" from "disturl;
    217  1.2.6.2  tls 			print "and NEWS file from "newsurl;
    218  1.2.6.2  tls 		}
    219  1.2.6.2  tls 		/^Release/ {
    220  1.2.6.2  tls 			# "Release <version> - <date>"
    221  1.2.6.2  tls 			ver = $2;
    222  1.2.6.2  tls 			date = gensub(".* - ", "", 1, $0);
    223  1.2.6.2  tls 			print "";
    224  1.2.6.2  tls 			print "Summary of changes in tzdata"ver \
    225  1.2.6.2  tls 				" ("date"):";
    226  1.2.6.2  tls 		}
    227  1.2.6.2  tls 		/^$/ { blankline = 1; havesentence = 0; }
    228  1.2.6.2  tls 		/^  Changes affecting/ { goodsection = 0; }
    229  1.2.6.2  tls 		/^  Changes affecting.*time/ { goodsection = 1; }
    230  1.2.6.2  tls 		/^  Changes affecting.*data format/ { goodsection = 1; }
    231  1.2.6.2  tls 		/^  Changes affecting.*documentation/ || \
    232  1.2.6.2  tls 		/^  Changes affecting.*commentary/ {
    233  1.2.6.2  tls 			t = gensub("^ *", "", 1, $0);
    234  1.2.6.2  tls 			t = gensub("\\.*$", ".", 1, t);
    235  1.2.6.2  tls 			print bullet t;
    236  1.2.6.2  tls 			goodsection = 0;
    237  1.2.6.2  tls 		}
    238  1.2.6.2  tls 		/^    .*/ && goodsection {
    239  1.2.6.2  tls 			# In a paragraph in a "good" section.
    240  1.2.6.2  tls 			# Ignore leading spaces, and ignore anything
    241  1.2.6.2  tls 			# after the first sentence.
    242  1.2.6.2  tls 			# First line of paragraph gets a bullet.
    243  1.2.6.2  tls 			t = gensub("^ *", "", 1, $0);
    244  1.2.6.2  tls 			t = gensub("\\. .*", ".", 1, t);
    245  1.2.6.2  tls 			if (blankline) print bullet t;
    246  1.2.6.2  tls 			else if (! havesentence) print indent t;
    247  1.2.6.2  tls 			havesentence = (havesentence || (t ~ "\\.$"));
    248  1.2.6.2  tls 		}
    249  1.2.6.2  tls 		/./ { blankline = 0; }
    250  1.2.6.2  tls 		' \
    251  1.2.6.2  tls 		<"${NEWSTRIMFILE}"
    252  1.2.6.2  tls 	} >"${IMPORTMSGFILE}"
    253  1.2.6.2  tls }
    254  1.2.6.2  tls 
    255  1.2.6.2  tls editimportmsg()
    256  1.2.6.2  tls {
    257  1.2.6.2  tls 	if [ -s "${IMPORTMSGFILE}" ] \
    258  1.2.6.2  tls 	&& ! grep -q '^EDIT' "${IMPORTMSGFILE}"
    259  1.2.6.2  tls 	then
    260  1.2.6.2  tls 		return 0 # file has already been edited
    261  1.2.6.2  tls 	fi
    262  1.2.6.2  tls 	# Pass both IMPORTMSGFILE and NEWSFILE to the editor, so that the
    263  1.2.6.2  tls 	# user can easily consult NEWSFILE while editing IMPORTMSGFILE.
    264  1.2.6.2  tls 	vi "${IMPORTMSGFILE}" "${NEWSFILE}"
    265  1.2.6.2  tls }
    266  1.2.6.2  tls 
    267  1.2.6.2  tls cvsimport()
    268  1.2.6.2  tls {
    269  1.2.6.2  tls 	if ! [ -s "${IMPORTMSGFILE}" ] \
    270  1.2.6.2  tls 	|| grep -q '^EDIT' "${IMPORTMSGFILE}"
    271  1.2.6.2  tls 	then
    272  1.2.6.2  tls 		cat >&2 <<EOF
    273  1.2.6.2  tls The message file ${IMPORTMSGFILE}
    274  1.2.6.2  tls has not been properly edited.
    275  1.2.6.2  tls Not performing cvs import.
    276  1.2.6.2  tls EOF
    277  1.2.6.2  tls 		return 1
    278  1.2.6.2  tls 	fi
    279  1.2.6.2  tls 	( cd "${EXTRACTDIR}" &&
    280  1.2.6.2  tls 	  DOIT cvs -d "${CVSROOT}" import -m "$(cat "${IMPORTMSGFILE}")" \
    281  1.2.6.2  tls 		"${REPODIR}" "${CVSBRANCHTAG}" "${CVSNEWTAG}"
    282  1.2.6.2  tls 	)
    283  1.2.6.2  tls }
    284  1.2.6.2  tls 
    285  1.2.6.2  tls cvsmerge()
    286  1.2.6.2  tls {
    287  1.2.6.2  tls 	DOIT cvs -d "${CVSROOT}" update -j"${CVSOLDTAG}" -j"${CVSNEWTAG}"
    288  1.2.6.2  tls }
    289  1.2.6.2  tls 
    290  1.2.6.2  tls resolveconflicts()
    291  1.2.6.2  tls {
    292  1.2.6.2  tls 	cat <<EOF
    293  1.2.6.2  tls Resolve conflicts resulting from the cvs merge.
    294  1.2.6.2  tls exit 0 when done.  exit 1 to abort.
    295  1.2.6.2  tls EOF
    296  1.2.6.2  tls 	nl='
    297  1.2.6.2  tls '
    298  1.2.6.2  tls 	PS1="[inside ${0##*/}]${nl}${PS1}" sh -i
    299  1.2.6.2  tls }
    300  1.2.6.2  tls 
    301  1.2.6.2  tls cvscommitmerge()
    302  1.2.6.2  tls {
    303  1.2.6.2  tls 	if grep -l '^[<=>][<=>][<=>]' *
    304  1.2.6.2  tls 	then
    305  1.2.6.2  tls 		cat >&2 <<EOF
    306  1.2.6.2  tls There still appear to be conflicts in the files listed above.
    307  1.2.6.2  tls Not performing cvs commit.
    308  1.2.6.2  tls EOF
    309  1.2.6.2  tls 		return 1
    310  1.2.6.2  tls 	fi
    311  1.2.6.2  tls 	DOIT cvs -d "${CVSROOT}" commit -m "Merge tzdata${NEWVER}"
    312  1.2.6.2  tls }
    313  1.2.6.2  tls 
    314  1.2.6.2  tls extra()
    315  1.2.6.2  tls {
    316  1.2.6.2  tls 	cat <<EOF
    317  1.2.6.2  tls Also do the following:
    318  1.2.6.2  tls  * Edit src/doc/3RDPARTY
    319  1.2.6.2  tls  * Edit src/doc/CHANGES
    320  1.2.6.2  tls  * Edit src/distrib/sets/base/mi if the set of installed files has changed.
    321  1.2.6.2  tls  * Submit pullup requests for all active release branches.
    322  1.2.6.2  tls  * rm -rf ${WORKDIR}
    323  1.2.6.2  tls EOF
    324  1.2.6.2  tls }
    325  1.2.6.2  tls 
    326  1.2.6.2  tls main()
    327  1.2.6.2  tls {
    328  1.2.6.2  tls 	set -e
    329  1.2.6.2  tls 	findcvsroot
    330  1.2.6.2  tls 	mkworkdir
    331  1.2.6.2  tls 	fetch
    332  1.2.6.2  tls 	checksig
    333  1.2.6.2  tls 	extract
    334  1.2.6.2  tls 	addnews
    335  1.2.6.2  tls 	trimnews
    336  1.2.6.2  tls 	mkimportmsg
    337  1.2.6.2  tls 	editimportmsg
    338  1.2.6.2  tls 	cvsimport
    339  1.2.6.2  tls 	cvsmerge
    340  1.2.6.2  tls 	resolveconflicts
    341  1.2.6.2  tls 	cvscommitmerge
    342  1.2.6.2  tls 	extra
    343  1.2.6.2  tls }
    344  1.2.6.2  tls 
    345  1.2.6.2  tls main "$@"
    346