1#!/bin/bash 2 3# Copyright 2020 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# Fail fast on any error. 18set -e 19 20if [ -z ${ANDROID_BUILD_TOP} ]; then 21 echo \$ANDROID_BUILD_TOP must be set. 22 exit 1 23fi 24 25RELEASE_ID=${1} 26if [ -z ${RELEASE_ID} ]; then 27 echo "Usage:" 28 echo " ${0} <release ID>" 29 echo 30 echo "e.g. ${0} 2020a" 31 exit 1 32fi 33 34SCRIPT_PATH=$(realpath $0) 35 36# -f = report failures 37# -L = follow redirects 38CURL_CMD="curl -f -L" 39 40TZBB_PROJECT_URL=https://github.com/evansiroky/timezone-boundary-builder/ 41SERVER_RELEASE_BASE_URL=${TZBB_PROJECT_URL}releases/download 42SERVER_SOURCE_BASE_URL=https://raw.githubusercontent.com/evansiroky/timezone-boundary-builder/master 43 44SOURCE_FILES=(\ 45 DATA_LICENSE \ 46) 47RELEASE_FILES=(\ 48 input-data.zip \ 49 timezones.geojson.zip \ 50) 51 52function download() { 53 set -e 54 SERVER_BASE_URL=${1} 55 FILE_NAME=${2} 56 LOCAL_DIR=${3} 57 58 URL=${SERVER_BASE_URL}/${FILE_NAME} 59 LOCAL_FILE_NAME=${LOCAL_DIR}/${FILE_NAME} 60 echo Downloading ${FILE_NAME} from ${URL}... 61 ${CURL_CMD} ${URL} --output ${LOCAL_FILE_NAME} 62 63 DOWNLOAD_DATE=$(date) 64 SHA=$(sha1sum ${LOCAL_FILE_NAME} | awk '{ print $1}') 65 66 # Add a METADATA file URL entry for every file we download. 67 cat << EOF >> ${METADATA_FILE} 68 url { 69 type: OTHER 70 value: "${FILE_NAME} downloaded from ${URL} on ${DOWNLOAD_DATE}, SHA1=${SHA}" 71 } 72EOF 73} 74 75LOCAL_DATA_DIR=${ANDROID_BUILD_TOP}/packages/modules/GeoTZ/tzbb_data 76 77mkdir -p ${LOCAL_DATA_DIR} 78echo Removing existing data files... 79rm -f ${LOCAL_DATA_DIR}/* 80 81METADATA_FILE=${LOCAL_DATA_DIR}/METADATA 82# Start the METADATA file 83cat << EOF > ${METADATA_FILE} 84// Generated file DO NOT EDIT 85// Run download-tzbb-files.sh 86name: "tzbb_data" 87description: 88 "Assorted files downloaded from ${TZBB_PROJECT_URL}" 89 90third_party { 91 url { 92 type: HOMEPAGE 93 value: "${TZBB_PROJECT_URL}" 94 } 95EOF 96 97for FILE in ${SOURCE_FILES[@]}; do 98 download ${SERVER_SOURCE_BASE_URL} ${FILE} ${LOCAL_DATA_DIR} 99done 100 101for FILE in ${RELEASE_FILES[@]}; do 102 download ${SERVER_RELEASE_BASE_URL}/${RELEASE_ID} ${FILE} ${LOCAL_DATA_DIR} 103done 104 105PROTO_UPGRADE_DATE=$(date +'{ year: '%Y' month: '%-m' day: '%-d' }') 106 107# Finish the METADATA file 108cat << EOF >> ${METADATA_FILE} 109 version: "${RELEASE_ID}" 110 last_upgrade_date ${PROTO_UPGRADE_DATE} 111 license_type: RESTRICTED 112} 113EOF 114 115ln -sr ${LOCAL_DATA_DIR}/DATA_LICENSE ${LOCAL_DATA_DIR}/LICENSE 116 117echo Look in ${LOCAL_DATA_DIR} for updated files.... 118