Elliott Hughes | d40e63e | 2011-02-17 16:20:07 -0800 | [diff] [blame^] | 1 | #!/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. |
| 6 | set -e |
| 7 | set -u |
| 8 | |
| 9 | echo "Looking for bionic..." |
| 10 | bionic_dir=$(cd $(dirname $0)/../../.. && pwd) |
| 11 | bionic_zoneinfo_dir=$bionic_dir/libc/zoneinfo |
| 12 | bionic_zoneinfo_tools_dir=$bionic_dir/libc/tools/zoneinfo |
| 13 | if [[ ! -d "$bionic_zoneinfo_dir" || ! -d "$bionic_zoneinfo_tools_dir" ]]; then |
| 14 | echo "Can't find bionic's zoneinfo directories!" |
| 15 | exit 1 |
| 16 | fi |
| 17 | |
| 18 | echo "Switching to temporary directory..." |
| 19 | temp_dir=`mktemp -d` |
| 20 | cd $temp_dir |
| 21 | trap "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 |
| 25 | echo "Looking for new tzdata..." |
| 26 | wget -N --no-verbose 'ftp://elsie.nci.nih.gov/pub/tzdata*.tar.gz' |
| 27 | zoneinfo_version_file=$bionic_zoneinfo_dir/zoneinfo.version |
| 28 | if [ -f "$zoneinfo_version_file" ]; then |
| 29 | current_version=tzdata`sed s/\n// < $zoneinfo_version_file` |
| 30 | else |
| 31 | current_version=missing |
| 32 | fi |
| 33 | latest_archive=`ls -r -v tzdata*.tar.gz | head -n1` |
| 34 | latest_version=`basename $latest_archive .tar.gz` |
| 35 | if [ "$current_version" == "$latest_version" ]; then |
| 36 | echo "You already have the latest tzdata ($latest_version)!" |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | echo "Extracting $latest_version..." |
| 41 | mkdir $latest_version |
| 42 | tar -C $latest_version -zxf $latest_archive |
| 43 | |
| 44 | echo "Compiling $latest_version..." |
| 45 | mkdir data |
| 46 | for 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 |
| 59 | do |
| 60 | zic -d data $latest_version/$i |
| 61 | done |
| 62 | |
| 63 | echo "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 | |
| 72 | javac -d . \ |
| 73 | $bionic_zoneinfo_tools_dir/ZoneCompactor.java \ |
| 74 | $bionic_zoneinfo_tools_dir/ZoneInfo.java |
| 75 | java ZoneCompactor setup data |
| 76 | |
| 77 | echo "Updating bionic to $latest_version..." |
| 78 | mv zoneinfo.dat zoneinfo.idx $bionic_zoneinfo_dir |
| 79 | echo $latest_version | sed 's/tzdata//' > $bionic_zoneinfo_dir/zoneinfo.version |