17b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller#!/usr/bin/env bash
27b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller#
37b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# Copyright (C) 2017 The Android Open Source Project
47b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller#
57b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# Licensed under the Apache License, Version 2.0 (the "License");
67b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# you may not use this file except in compliance with the License.
77b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# You may obtain a copy of the License at
87b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller#
97b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller#      http://www.apache.org/licenses/LICENSE-2.0
107b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller#
117b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# Unless required by applicable law or agreed to in writing, software
127b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# distributed under the License is distributed on an "AS IS" BASIS,
137b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
147b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# See the License for the specific language governing permissions and
157b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# limitations under the License.
167b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller#
177b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# Creates fake distro data files by taking the files in $1 and turning them into ones
187b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# that appear to be ones from IANA release $2. The resulting files are placed beneath $3.
197b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller
207b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerREFERENCE_FILES_DIR=$1
217b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerOUTPUT_IANA_RULES_VERSION=$2
227b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerDISTRO_OUTPUT_DIR=$3
237b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller
247b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# Fail on error
257b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fullerset -e
267b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller
277b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerTZDATA_FILE=iana/tzdata
287b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerICU_FILE=icu_overlay/icu_tzdata.dat
297b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerTZLOOKUP_FILE=android/tzlookup.xml
307b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller
317b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerINPUT_TZDATA_FILE=${REFERENCE_FILES_DIR}/${TZDATA_FILE}
327b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerINPUT_ICU_FILE=${REFERENCE_FILES_DIR}/${ICU_FILE}
337b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerINPUT_TZLOOKUP_FILE=${REFERENCE_FILES_DIR}/${TZLOOKUP_FILE}
347b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller
357b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerTZHEADER=$(head -n1 ${INPUT_TZDATA_FILE} | cut -c1-11)
367b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerINPUT_IANA_RULES_VERSION=${TZHEADER:6}
377b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller
387b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerOUTPUT_TZDATA_FILE=${DISTRO_OUTPUT_DIR}/${TZDATA_FILE}
397b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerOUTPUT_ICU_FILE=${DISTRO_OUTPUT_DIR}/${ICU_FILE}
407b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerOUTPUT_TZLOOKUP_FILE=${DISTRO_OUTPUT_DIR}/${TZLOOKUP_FILE}
417b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller
427b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fullermkdir -p ${DISTRO_OUTPUT_DIR}
437b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fullermkdir -p ${DISTRO_OUTPUT_DIR}/iana
447b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fullermkdir -p ${DISTRO_OUTPUT_DIR}/icu_overlay
457b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fullermkdir -p ${DISTRO_OUTPUT_DIR}/android
467b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller
477b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# Create a new tzdata file.
487b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fullersed "1s/^tzdata${INPUT_IANA_RULES_VERSION}/tzdata${OUTPUT_IANA_RULES_VERSION}/" ${INPUT_TZDATA_FILE} > ${OUTPUT_TZDATA_FILE}
497b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller
507b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# Create new ICU file.
517b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerSEARCH=$(echo ${INPUT_IANA_RULES_VERSION} | sed "s/\(.\)/\1\\\x00/g")
527b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil FullerREPLACE=$(echo ${OUTPUT_IANA_RULES_VERSION} | sed "s/\(.\)/\1\\\x00/g")
537b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fullersed "s/$SEARCH/$REPLACE/" ${INPUT_ICU_FILE} > ${OUTPUT_ICU_FILE}
547b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller
557b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller# Copy the tzlookup.xml as is.
567b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fullercp ${INPUT_TZLOOKUP_FILE} ${OUTPUT_TZLOOKUP_FILE}
577b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller
587b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fullerecho Transformed input files with version ${INPUT_IANA_RULES_VERSION} to ${OUTPUT_IANA_RULES_VERSION} in ${DISTRO_OUTPUT_DIR}
597b4b9e592d6c9010be93d018b8a7b594bf2c1ccfNeil Fuller
60