12e5b6d6dSopenharmony_ci#!/usr/bin/qsh 22e5b6d6dSopenharmony_ci# Copyright (C) 2016 and later: Unicode, Inc. and others. 32e5b6d6dSopenharmony_ci# License & terms of use: http://www.unicode.org/copyright.html 42e5b6d6dSopenharmony_ci# Copyright (C) 2000-2011, International Business Machines 52e5b6d6dSopenharmony_ci# Corporation and others. All Rights Reserved. 62e5b6d6dSopenharmony_ci# 72e5b6d6dSopenharmony_ci# Authors: 82e5b6d6dSopenharmony_ci# Ami Fixler 92e5b6d6dSopenharmony_ci# Barry Novinger 102e5b6d6dSopenharmony_ci# Steven R. Loomis 112e5b6d6dSopenharmony_ci# George Rhoten 122e5b6d6dSopenharmony_ci# Jason Spieth 132e5b6d6dSopenharmony_ci# 142e5b6d6dSopenharmony_ci# Shell script to unpax ICU and convert the files to an EBCDIC codepage. 152e5b6d6dSopenharmony_ci# After extracting to EBCDIC, binary files are re-extracted without the 162e5b6d6dSopenharmony_ci# EBCDIC conversion, thus restoring them to original codepage. 172e5b6d6dSopenharmony_ci 182e5b6d6dSopenharmony_ciif [ -z "$QSH_VERSION" ]; 192e5b6d6dSopenharmony_cithen 202e5b6d6dSopenharmony_ci QSH=0 212e5b6d6dSopenharmony_ci echo "QSH not detected (QSH_VERSION not set) - just testing." 222e5b6d6dSopenharmony_cielse 232e5b6d6dSopenharmony_ci QSH=1 242e5b6d6dSopenharmony_ci #echo "QSH version $QSH_VERSION" 252e5b6d6dSopenharmony_cifi 262e5b6d6dSopenharmony_ciexport QSH 272e5b6d6dSopenharmony_ci 282e5b6d6dSopenharmony_ci# set this to "v" to list files as they are unpacked (default) 292e5b6d6dSopenharmony_ciVERBOSE_UNPACK="v" 302e5b6d6dSopenharmony_ci 312e5b6d6dSopenharmony_ci# Set the following variable to the list of binary file suffixes (extensions) 322e5b6d6dSopenharmony_ci 332e5b6d6dSopenharmony_ci 342e5b6d6dSopenharmony_ci#**************************************************************************** 352e5b6d6dSopenharmony_ci#binary_suffixes='ico ICO bmp BMP jpg JPG gif GIF brk BRK' 362e5b6d6dSopenharmony_ci#ICU specific binary files 372e5b6d6dSopenharmony_ci#**************************************************************************** 382e5b6d6dSopenharmony_cibinary_suffixes='brk BRK bin BIN res RES cnv CNV dat DAT icu ICU spp SPP xml XML nrm NRM utf16be UTF16BE' 392e5b6d6dSopenharmony_cidata_files='icu/source/data/brkitr/* icu/source/data/locales/* icu/source/data/coll/* icu/source/data/rbnf/* icu/source/data/mappings/* icu/source/data/misc/* icu/source/data/translit/* icu/source/data/unidata/* icu/source/test/testdata/*' 402e5b6d6dSopenharmony_ci 412e5b6d6dSopenharmony_ci#**************************************************************************** 422e5b6d6dSopenharmony_ci# Function: usage 432e5b6d6dSopenharmony_ci# Description: Prints out text that describes how to call this script 442e5b6d6dSopenharmony_ci# Input: None 452e5b6d6dSopenharmony_ci# Output: None 462e5b6d6dSopenharmony_ci#**************************************************************************** 472e5b6d6dSopenharmony_ciusage() 482e5b6d6dSopenharmony_ci{ 492e5b6d6dSopenharmony_ci echo "Enter archive filename as a parameter: $0 icu-archive.tar" 502e5b6d6dSopenharmony_ci} 512e5b6d6dSopenharmony_ci 522e5b6d6dSopenharmony_ci#**************************************************************************** 532e5b6d6dSopenharmony_ci# first make sure we at least one arg and it's a file we can read 542e5b6d6dSopenharmony_ci#**************************************************************************** 552e5b6d6dSopenharmony_ci 562e5b6d6dSopenharmony_ci# check for no arguments 572e5b6d6dSopenharmony_ciif [ $# -eq 0 ]; then 582e5b6d6dSopenharmony_ci usage 592e5b6d6dSopenharmony_ci exit 602e5b6d6dSopenharmony_cifi 612e5b6d6dSopenharmony_ci 622e5b6d6dSopenharmony_ci# tar file is argument 1 632e5b6d6dSopenharmony_citar_file=$1 642e5b6d6dSopenharmony_ci 652e5b6d6dSopenharmony_ci# check that the file is valid 662e5b6d6dSopenharmony_ciif [ ! -r $tar_file ]; then 672e5b6d6dSopenharmony_ci echo "$tar_file does not exist or cannot be read." 682e5b6d6dSopenharmony_ci usage 692e5b6d6dSopenharmony_ci exit 702e5b6d6dSopenharmony_cifi 712e5b6d6dSopenharmony_ci 722e5b6d6dSopenharmony_ci# treat all data files as ebcdic 732e5b6d6dSopenharmony_ciebcdic_data=$data_files 742e5b6d6dSopenharmony_ci 752e5b6d6dSopenharmony_ci#**************************************************************************** 762e5b6d6dSopenharmony_ci# Extract files. We do this in two passes. One pass for 819 files and a 772e5b6d6dSopenharmony_ci# second pass for 37 files 782e5b6d6dSopenharmony_ci#**************************************************************************** 792e5b6d6dSopenharmony_ciecho "" 802e5b6d6dSopenharmony_ciecho "Extracting from $tar_file ..." 812e5b6d6dSopenharmony_ciecho "" 822e5b6d6dSopenharmony_ci 832e5b6d6dSopenharmony_ci# extract everything as iso-8859-1 except these directories 842e5b6d6dSopenharmony_cipax -C 819 -rc${VERBOSE_UNPACK}f $tar_file $ebcdic_data 852e5b6d6dSopenharmony_ci 862e5b6d6dSopenharmony_ci# extract files while converting them to EBCDIC 872e5b6d6dSopenharmony_ciecho "" 882e5b6d6dSopenharmony_ciecho "Extracting files which must be in ibm-37 ..." 892e5b6d6dSopenharmony_ciecho "" 902e5b6d6dSopenharmony_cipax -C 37 -r${VERBOSE_UNPACK}f $tar_file $ebcdic_data 912e5b6d6dSopenharmony_ci 922e5b6d6dSopenharmony_ci#**************************************************************************** 932e5b6d6dSopenharmony_ci# For files we have restored as CCSID 37, check the BOM to see if they 942e5b6d6dSopenharmony_ci# should be processed as 819. Also handle files with special paths. Files 952e5b6d6dSopenharmony_ci# that match will be added to binary files lists. The lists will in turn 962e5b6d6dSopenharmony_ci# be processed to restore files as 819. 972e5b6d6dSopenharmony_ci#**************************************************************************** 982e5b6d6dSopenharmony_ciecho "" 992e5b6d6dSopenharmony_ciecho "Determining binary files by BOM ..." 1002e5b6d6dSopenharmony_ciecho "" 1012e5b6d6dSopenharmony_cibin_count=0 1022e5b6d6dSopenharmony_ci# Process BOMs 1032e5b6d6dSopenharmony_ciif [ -f icu/as_is/bomlist.txt ]; 1042e5b6d6dSopenharmony_cithen 1052e5b6d6dSopenharmony_ci echo "Using icu/as_is/bomlist.txt" 1062e5b6d6dSopenharmony_ci pax -C 819 -rvf $tar_file `cat icu/as_is/bomlist.txt` 1072e5b6d6dSopenharmony_cielse 1082e5b6d6dSopenharmony_ci for file in `find ./icu \( -name \*.txt -print \)`; do 1092e5b6d6dSopenharmony_ci bom8=`head -n 1 $file|\ 1102e5b6d6dSopenharmony_ci od -t x1|\ 1112e5b6d6dSopenharmony_ci head -n 1|\ 1122e5b6d6dSopenharmony_ci sed 's/ */ /g'|\ 1132e5b6d6dSopenharmony_ci cut -f2-4 -d ' '|\ 1142e5b6d6dSopenharmony_ci tr 'A-Z' 'a-z'`; 1152e5b6d6dSopenharmony_ci #Find a converted UTF-8 BOM 1162e5b6d6dSopenharmony_ci if [ "$bom8" = "057 08b 0ab" -o "$bom8" = "57 8b ab" ] 1172e5b6d6dSopenharmony_ci then 1182e5b6d6dSopenharmony_ci file="`echo $file | cut -d / -f2-`" 1192e5b6d6dSopenharmony_ci 1202e5b6d6dSopenharmony_ci if [ `echo $binary_files | wc -w` -lt 200 ] 1212e5b6d6dSopenharmony_ci then 1222e5b6d6dSopenharmony_ci bin_count=`expr $bin_count + 1` 1232e5b6d6dSopenharmony_ci binary_files="$binary_files $file"; 1242e5b6d6dSopenharmony_ci else 1252e5b6d6dSopenharmony_ci echo "Restoring binary files by BOM ($bin_count)..." 1262e5b6d6dSopenharmony_ci rm $binary_files; 1272e5b6d6dSopenharmony_ci pax -C 819 -rvf $tar_file $binary_files; 1282e5b6d6dSopenharmony_ci echo "Determining binary files by BOM ($bin_count)..." 1292e5b6d6dSopenharmony_ci binary_files="$file"; 1302e5b6d6dSopenharmony_ci bin_count=`expr $bin_count + 1` 1312e5b6d6dSopenharmony_ci fi 1322e5b6d6dSopenharmony_ci fi 1332e5b6d6dSopenharmony_ci done 1342e5b6d6dSopenharmony_ci # now see if a re-extract of binary files is necessary 1352e5b6d6dSopenharmony_ci if [ `echo $binary_files | wc -w` -gt 0 ] 1362e5b6d6dSopenharmony_ci then 1372e5b6d6dSopenharmony_ci echo "Restoring binary files ($bin_count) ..." 1382e5b6d6dSopenharmony_ci rm $binary_files 1392e5b6d6dSopenharmony_ci pax -C 819 -rvf $tar_file $binary_files 1402e5b6d6dSopenharmony_ci fi 1412e5b6d6dSopenharmony_cifi 1422e5b6d6dSopenharmony_ci 1432e5b6d6dSopenharmony_ciecho "# Processing special paths." 1442e5b6d6dSopenharmony_ci# Process special paths 1452e5b6d6dSopenharmony_cimore_bin_opts=$(echo $binary_suffixes | sed -e 's%[a-zA-Z0-9]*%-o -name \*.&%g') 1462e5b6d6dSopenharmony_ci# echo "Looking for additional files: find ... $more_bin_opts" 1472e5b6d6dSopenharmony_cimore_bin_files=$(find icu -type f \( -name '*.zzz' $more_bin_opts \) -print) 1482e5b6d6dSopenharmony_ciecho "Restoring binary files by special paths ($bin_count) ..." 1492e5b6d6dSopenharmony_cirm $more_bin_files 1502e5b6d6dSopenharmony_cipax -C 819 -rvf $tar_file $more_bin_files 1512e5b6d6dSopenharmony_ci 1522e5b6d6dSopenharmony_ci#**************************************************************************** 1532e5b6d6dSopenharmony_ci# Generate and run the configure script 1542e5b6d6dSopenharmony_ci#**************************************************************************** 1552e5b6d6dSopenharmony_ci 1562e5b6d6dSopenharmony_ciecho "" 1572e5b6d6dSopenharmony_ciecho "Generating qsh compatible configure ..." 1582e5b6d6dSopenharmony_ciecho "" 1592e5b6d6dSopenharmony_ci 1602e5b6d6dSopenharmony_cised -f icu/as_is/os400/convertConfigure.sed icu/source/configure > icu/source/configureTemp 1612e5b6d6dSopenharmony_cidel -f icu/source/configure 1622e5b6d6dSopenharmony_cimv icu/source/configureTemp icu/source/configure 1632e5b6d6dSopenharmony_cichmod 755 icu/source/configure 1642e5b6d6dSopenharmony_ci 1652e5b6d6dSopenharmony_ciecho "" 1662e5b6d6dSopenharmony_ciecho "$0 has completed extracting ICU from $tar_file - $bin_count binary files extracted." 1672e5b6d6dSopenharmony_ci 168