12e5b6d6dSopenharmony_ci#!/bin/bash -u 22e5b6d6dSopenharmony_ci# 32e5b6d6dSopenharmony_ci##################################################################### 42e5b6d6dSopenharmony_ci### © 2020 and later: Unicode, Inc. and others. ### 52e5b6d6dSopenharmony_ci### License & terms of use: http://www.unicode.org/copyright.html ### 62e5b6d6dSopenharmony_ci##################################################################### 72e5b6d6dSopenharmony_ci# 82e5b6d6dSopenharmony_ci# This script will attempt to build and install the necessary CLDR JAR files 92e5b6d6dSopenharmony_ci# from a given CLDR installation root directory. The JAR files are installed 102e5b6d6dSopenharmony_ci# according to the manual instructions given in README.txt and lib/README.txt. 112e5b6d6dSopenharmony_ci# 122e5b6d6dSopenharmony_ci# The user must have installed both 'ant' and 'maven' in accordance with the 132e5b6d6dSopenharmony_ci# instructions in README.txt before attempting to run this script. 142e5b6d6dSopenharmony_ci# 152e5b6d6dSopenharmony_ci# Usage (from the directory of this script): 162e5b6d6dSopenharmony_ci# 172e5b6d6dSopenharmony_ci# ./install-cldr-jars.sh <CLDR-root-directory> 182e5b6d6dSopenharmony_ci# 192e5b6d6dSopenharmony_ci# Note to maintainers: This script cannot be assumed to run on a Unix/Linux 202e5b6d6dSopenharmony_ci# based system, and while a Posix compliant bash shell is required, any 212e5b6d6dSopenharmony_ci# assumptions about auxiliary Unix tools should be minimized (e.g. things 222e5b6d6dSopenharmony_ci# like "dirname" or "tempfile" may not exist). Where bash-only alternatives 232e5b6d6dSopenharmony_ci# have to be used, they should be clearly documented. 242e5b6d6dSopenharmony_ci 252e5b6d6dSopenharmony_ci# Exit with a message for fatal errors. 262e5b6d6dSopenharmony_cifunction die() { 272e5b6d6dSopenharmony_ci echo "$1" 282e5b6d6dSopenharmony_ci echo "Exiting..." 292e5b6d6dSopenharmony_ci exit 1 302e5b6d6dSopenharmony_ci} >&2 312e5b6d6dSopenharmony_ci 322e5b6d6dSopenharmony_ci# Runs a given command and captures output to the global log file. 332e5b6d6dSopenharmony_ci# If a command errors, the user can then view the log file. 342e5b6d6dSopenharmony_cifunction run_with_logging() { 352e5b6d6dSopenharmony_ci echo >> "${LOG_FILE}" 362e5b6d6dSopenharmony_ci echo "Running: ${@}" >> "${LOG_FILE}" 372e5b6d6dSopenharmony_ci echo -- "----------------------------------------------------------------" >> "${LOG_FILE}" 382e5b6d6dSopenharmony_ci "${@}" >> "${LOG_FILE}" 2>&1 392e5b6d6dSopenharmony_ci if (( $? != 0 )) ; then 402e5b6d6dSopenharmony_ci echo -- "---- Previous command failed ----" >> "${LOG_FILE}" 412e5b6d6dSopenharmony_ci echo "Error running: ${@}" 422e5b6d6dSopenharmony_ci read -p "Show log file? " -n 1 -r 432e5b6d6dSopenharmony_ci echo 442e5b6d6dSopenharmony_ci if [[ "${REPLY}" =~ ^[Yy]$ ]] ; then 452e5b6d6dSopenharmony_ci less -X "${LOG_FILE}" 462e5b6d6dSopenharmony_ci fi 472e5b6d6dSopenharmony_ci echo "Log file: ${LOG_FILE}" 482e5b6d6dSopenharmony_ci exit 1 492e5b6d6dSopenharmony_ci fi 502e5b6d6dSopenharmony_ci echo -- "---- Previous command succeeded ----" >> "${LOG_FILE}" 512e5b6d6dSopenharmony_ci} 522e5b6d6dSopenharmony_ci 532e5b6d6dSopenharmony_ci# First require that we are run from the same directory as the script. 542e5b6d6dSopenharmony_ci# Can't assume users have "dirname" available so hack it a bit with shell 552e5b6d6dSopenharmony_ci# substitution (if no directory path was prepended, SCRIPT_DIR==$0). 562e5b6d6dSopenharmony_ciSCRIPT_DIR=${0%/*} 572e5b6d6dSopenharmony_ciif [[ "$SCRIPT_DIR" != "$0" ]] ; then 582e5b6d6dSopenharmony_ci cd $SCRIPT_DIR 592e5b6d6dSopenharmony_cifi 602e5b6d6dSopenharmony_ci 612e5b6d6dSopenharmony_ci# Check for some expected environmental things early. 622e5b6d6dSopenharmony_ciwhich ant > /dev/null || die "Cannot find Ant executable 'ant' in the current path." 632e5b6d6dSopenharmony_ciwhich mvn > /dev/null || die "Cannot find Maven executable 'mvn' in the current path." 642e5b6d6dSopenharmony_ci 652e5b6d6dSopenharmony_ci# Check there's one argument that points at a directory (or a symbolic link to a directory). 662e5b6d6dSopenharmony_ci(( $# == 1 )) && [[ -d "$1" ]] || die "Usage: ./install-cldr-jars.sh <CLDR-root-directory>" 672e5b6d6dSopenharmony_ci 682e5b6d6dSopenharmony_ci# Set up a log file (and be nice about tidying it up). 692e5b6d6dSopenharmony_ci# Cannot assume "tempfile" exists so use a timestamp (we expect "date" to exist though). 702e5b6d6dSopenharmony_ciLOG_FILE="${TMPDIR:-/tmp}/cldr2icu_log_$(date '+%m%d_%H%M%S').txt" 712e5b6d6dSopenharmony_citouch $LOG_FILE || die "Cannot create temporary file: ${LOG_FILE}" 722e5b6d6dSopenharmony_ciecho -- "---- LOG FILE ---- $(date '+%F %T') ----" >> "${LOG_FILE}" 732e5b6d6dSopenharmony_ci 742e5b6d6dSopenharmony_ci# Build the cldr-code.jar in the cldr-code/target subdirectory of the CLDR tools directory. 752e5b6d6dSopenharmony_ciCLDR_TOOLS_DIR="$1/tools" 762e5b6d6dSopenharmony_cipushd "${CLDR_TOOLS_DIR}" > /dev/null || die "Cannot change directory to: ${CLDR_TOOLS_DIR}" 772e5b6d6dSopenharmony_ci 782e5b6d6dSopenharmony_ciecho "Building CLDR JAR file..." 792e5b6d6dSopenharmony_cirun_with_logging mvn package -DskipTests=true 802e5b6d6dSopenharmony_ci[[ -f "cldr-code/target/cldr-code.jar" ]] || die "Error creating cldr-code.jar file" 812e5b6d6dSopenharmony_ci 822e5b6d6dSopenharmony_cipopd > /dev/null 832e5b6d6dSopenharmony_ci 842e5b6d6dSopenharmony_ci# The -B flag is "batch" mode and won't mess about with escape codes in the log file. 852e5b6d6dSopenharmony_ciecho "Installing CLDR JAR file..." 862e5b6d6dSopenharmony_cirun_with_logging mvn -B install:install-file \ 872e5b6d6dSopenharmony_ci -Dproject.parent.relativePath="" \ 882e5b6d6dSopenharmony_ci -DgroupId=org.unicode.cldr \ 892e5b6d6dSopenharmony_ci -DartifactId=cldr-api \ 902e5b6d6dSopenharmony_ci -Dversion=0.1-SNAPSHOT \ 912e5b6d6dSopenharmony_ci -Dpackaging=jar \ 922e5b6d6dSopenharmony_ci -DgeneratePom=true \ 932e5b6d6dSopenharmony_ci -DlocalRepositoryPath=. \ 942e5b6d6dSopenharmony_ci -Dfile="${CLDR_TOOLS_DIR}/cldr-code/target/cldr-code.jar" 952e5b6d6dSopenharmony_ci 962e5b6d6dSopenharmony_ciecho "Syncing local Maven repository..." 972e5b6d6dSopenharmony_cirun_with_logging mvn -B dependency:purge-local-repository \ 982e5b6d6dSopenharmony_ci -Dproject.parent.relativePath="" \ 992e5b6d6dSopenharmony_ci -DmanualIncludes=org.unicode.cldr:cldr-api:jar 1002e5b6d6dSopenharmony_ci 1012e5b6d6dSopenharmony_ciecho "All done!" 1022e5b6d6dSopenharmony_ciecho "Log file: ${LOG_FILE}" 103