blob: 5755e265793016328795bfd2b3c6d2805b507664 [file] [log] [blame]
Elliott Hughesd40e63e2011-02-17 16:20:07 -08001#!/bin/bash
2# Run with no arguments from any directory, with no special setup required.
3
4# Abort if any command returns an error exit status, or if an undefined
5# variable is used.
6set -e
7set -u
8
9echo "Looking for bionic..."
10bionic_dir=$(cd $(dirname $0)/../../.. && pwd)
11bionic_zoneinfo_dir=$bionic_dir/libc/zoneinfo
12bionic_zoneinfo_tools_dir=$bionic_dir/libc/tools/zoneinfo
13if [[ ! -d "$bionic_zoneinfo_dir" || ! -d "$bionic_zoneinfo_tools_dir" ]]; then
14 echo "Can't find bionic's zoneinfo directories!"
15 exit 1
16fi
17
18echo "Switching to temporary directory..."
19temp_dir=`mktemp -d`
20cd $temp_dir
21trap "rm -rf $temp_dir; exit" INT TERM EXIT
22
23# URL from "Sources for Time Zone and Daylight Saving Time Data"
24# http://www.twinsun.com/tz/tz-link.htm
25echo "Looking for new tzdata..."
26wget -N --no-verbose 'ftp://elsie.nci.nih.gov/pub/tzdata*.tar.gz'
27zoneinfo_version_file=$bionic_zoneinfo_dir/zoneinfo.version
28if [ -f "$zoneinfo_version_file" ]; then
29 current_version=tzdata`sed s/\n// < $zoneinfo_version_file`
30else
31 current_version=missing
32fi
33latest_archive=`ls -r -v tzdata*.tar.gz | head -n1`
34latest_version=`basename $latest_archive .tar.gz`
35if [ "$current_version" == "$latest_version" ]; then
36 echo "You already have the latest tzdata ($latest_version)!"
37 exit 1
38fi
39
40echo "Extracting $latest_version..."
41mkdir $latest_version
42tar -C $latest_version -zxf $latest_archive
43
44echo "Compiling $latest_version..."
45mkdir data
46for i in \
47 africa \
48 antarctica \
49 asia \
50 australasia \
51 etcetera \
52 europe \
53 factory \
54 northamerica \
55 solar87 \
56 solar88 \
57 solar89 \
58 southamerica
59do
60 zic -d data $latest_version/$i
61done
62
63echo "Compacting $latest_version..."
64(
65 cat $latest_version/* | grep '^Link' | awk '{print $1, $2, $3}'
66 (
67 cat $latest_version/* | grep '^Zone' | awk '{print $2}'
68 cat $latest_version/* | grep '^Link' | awk '{print $3}'
69 ) | LC_ALL="C" sort
70) | grep -v Riyadh8 > setup
71
72javac -d . \
73 $bionic_zoneinfo_tools_dir/ZoneCompactor.java \
74 $bionic_zoneinfo_tools_dir/ZoneInfo.java
75java ZoneCompactor setup data
76
77echo "Updating bionic to $latest_version..."
78mv zoneinfo.dat zoneinfo.idx $bionic_zoneinfo_dir
79echo $latest_version | sed 's/tzdata//' > $bionic_zoneinfo_dir/zoneinfo.version