1*0e209d39SAndroid Build Coastguard Worker#!/usr/bin/qsh 2*0e209d39SAndroid Build Coastguard Worker# Copyright (C) 2016 and later: Unicode, Inc. and others. 3*0e209d39SAndroid Build Coastguard Worker# License & terms of use: http://www.unicode.org/copyright.html 4*0e209d39SAndroid Build Coastguard Worker# Copyright (C) 2000-2011, International Business Machines 5*0e209d39SAndroid Build Coastguard Worker# Corporation and others. All Rights Reserved. 6*0e209d39SAndroid Build Coastguard Worker# 7*0e209d39SAndroid Build Coastguard Worker# Authors: 8*0e209d39SAndroid Build Coastguard Worker# Ami Fixler 9*0e209d39SAndroid Build Coastguard Worker# Barry Novinger 10*0e209d39SAndroid Build Coastguard Worker# Steven R. Loomis 11*0e209d39SAndroid Build Coastguard Worker# George Rhoten 12*0e209d39SAndroid Build Coastguard Worker# Jason Spieth 13*0e209d39SAndroid Build Coastguard Worker# 14*0e209d39SAndroid Build Coastguard Worker# Shell script to unpax ICU and convert the files to an EBCDIC codepage. 15*0e209d39SAndroid Build Coastguard Worker# After extracting to EBCDIC, binary files are re-extracted without the 16*0e209d39SAndroid Build Coastguard Worker# EBCDIC conversion, thus restoring them to original codepage. 17*0e209d39SAndroid Build Coastguard Worker 18*0e209d39SAndroid Build Coastguard Workerif [ -z "$QSH_VERSION" ]; 19*0e209d39SAndroid Build Coastguard Workerthen 20*0e209d39SAndroid Build Coastguard Worker QSH=0 21*0e209d39SAndroid Build Coastguard Worker echo "QSH not detected (QSH_VERSION not set) - just testing." 22*0e209d39SAndroid Build Coastguard Workerelse 23*0e209d39SAndroid Build Coastguard Worker QSH=1 24*0e209d39SAndroid Build Coastguard Worker #echo "QSH version $QSH_VERSION" 25*0e209d39SAndroid Build Coastguard Workerfi 26*0e209d39SAndroid Build Coastguard Workerexport QSH 27*0e209d39SAndroid Build Coastguard Worker 28*0e209d39SAndroid Build Coastguard Worker# set this to "v" to list files as they are unpacked (default) 29*0e209d39SAndroid Build Coastguard WorkerVERBOSE_UNPACK="v" 30*0e209d39SAndroid Build Coastguard Worker 31*0e209d39SAndroid Build Coastguard Worker# Set the following variable to the list of binary file suffixes (extensions) 32*0e209d39SAndroid Build Coastguard Worker 33*0e209d39SAndroid Build Coastguard Worker 34*0e209d39SAndroid Build Coastguard Worker#**************************************************************************** 35*0e209d39SAndroid Build Coastguard Worker#binary_suffixes='ico ICO bmp BMP jpg JPG gif GIF brk BRK' 36*0e209d39SAndroid Build Coastguard Worker#ICU specific binary files 37*0e209d39SAndroid Build Coastguard Worker#**************************************************************************** 38*0e209d39SAndroid Build Coastguard Workerbinary_suffixes='brk BRK bin BIN res RES cnv CNV dat DAT icu ICU spp SPP xml XML nrm NRM utf16be UTF16BE' 39*0e209d39SAndroid Build Coastguard Workerdata_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/*' 40*0e209d39SAndroid Build Coastguard Worker 41*0e209d39SAndroid Build Coastguard Worker#**************************************************************************** 42*0e209d39SAndroid Build Coastguard Worker# Function: usage 43*0e209d39SAndroid Build Coastguard Worker# Description: Prints out text that describes how to call this script 44*0e209d39SAndroid Build Coastguard Worker# Input: None 45*0e209d39SAndroid Build Coastguard Worker# Output: None 46*0e209d39SAndroid Build Coastguard Worker#**************************************************************************** 47*0e209d39SAndroid Build Coastguard Workerusage() 48*0e209d39SAndroid Build Coastguard Worker{ 49*0e209d39SAndroid Build Coastguard Worker echo "Enter archive filename as a parameter: $0 icu-archive.tar" 50*0e209d39SAndroid Build Coastguard Worker} 51*0e209d39SAndroid Build Coastguard Worker 52*0e209d39SAndroid Build Coastguard Worker#**************************************************************************** 53*0e209d39SAndroid Build Coastguard Worker# first make sure we at least one arg and it's a file we can read 54*0e209d39SAndroid Build Coastguard Worker#**************************************************************************** 55*0e209d39SAndroid Build Coastguard Worker 56*0e209d39SAndroid Build Coastguard Worker# check for no arguments 57*0e209d39SAndroid Build Coastguard Workerif [ $# -eq 0 ]; then 58*0e209d39SAndroid Build Coastguard Worker usage 59*0e209d39SAndroid Build Coastguard Worker exit 60*0e209d39SAndroid Build Coastguard Workerfi 61*0e209d39SAndroid Build Coastguard Worker 62*0e209d39SAndroid Build Coastguard Worker# tar file is argument 1 63*0e209d39SAndroid Build Coastguard Workertar_file=$1 64*0e209d39SAndroid Build Coastguard Worker 65*0e209d39SAndroid Build Coastguard Worker# check that the file is valid 66*0e209d39SAndroid Build Coastguard Workerif [ ! -r $tar_file ]; then 67*0e209d39SAndroid Build Coastguard Worker echo "$tar_file does not exist or cannot be read." 68*0e209d39SAndroid Build Coastguard Worker usage 69*0e209d39SAndroid Build Coastguard Worker exit 70*0e209d39SAndroid Build Coastguard Workerfi 71*0e209d39SAndroid Build Coastguard Worker 72*0e209d39SAndroid Build Coastguard Worker# treat all data files as ebcdic 73*0e209d39SAndroid Build Coastguard Workerebcdic_data=$data_files 74*0e209d39SAndroid Build Coastguard Worker 75*0e209d39SAndroid Build Coastguard Worker#**************************************************************************** 76*0e209d39SAndroid Build Coastguard Worker# Extract files. We do this in two passes. One pass for 819 files and a 77*0e209d39SAndroid Build Coastguard Worker# second pass for 37 files 78*0e209d39SAndroid Build Coastguard Worker#**************************************************************************** 79*0e209d39SAndroid Build Coastguard Workerecho "" 80*0e209d39SAndroid Build Coastguard Workerecho "Extracting from $tar_file ..." 81*0e209d39SAndroid Build Coastguard Workerecho "" 82*0e209d39SAndroid Build Coastguard Worker 83*0e209d39SAndroid Build Coastguard Worker# extract everything as iso-8859-1 except these directories 84*0e209d39SAndroid Build Coastguard Workerpax -C 819 -rc${VERBOSE_UNPACK}f $tar_file $ebcdic_data 85*0e209d39SAndroid Build Coastguard Worker 86*0e209d39SAndroid Build Coastguard Worker# extract files while converting them to EBCDIC 87*0e209d39SAndroid Build Coastguard Workerecho "" 88*0e209d39SAndroid Build Coastguard Workerecho "Extracting files which must be in ibm-37 ..." 89*0e209d39SAndroid Build Coastguard Workerecho "" 90*0e209d39SAndroid Build Coastguard Workerpax -C 37 -r${VERBOSE_UNPACK}f $tar_file $ebcdic_data 91*0e209d39SAndroid Build Coastguard Worker 92*0e209d39SAndroid Build Coastguard Worker#**************************************************************************** 93*0e209d39SAndroid Build Coastguard Worker# For files we have restored as CCSID 37, check the BOM to see if they 94*0e209d39SAndroid Build Coastguard Worker# should be processed as 819. Also handle files with special paths. Files 95*0e209d39SAndroid Build Coastguard Worker# that match will be added to binary files lists. The lists will in turn 96*0e209d39SAndroid Build Coastguard Worker# be processed to restore files as 819. 97*0e209d39SAndroid Build Coastguard Worker#**************************************************************************** 98*0e209d39SAndroid Build Coastguard Workerecho "" 99*0e209d39SAndroid Build Coastguard Workerecho "Determining binary files by BOM ..." 100*0e209d39SAndroid Build Coastguard Workerecho "" 101*0e209d39SAndroid Build Coastguard Workerbin_count=0 102*0e209d39SAndroid Build Coastguard Worker# Process BOMs 103*0e209d39SAndroid Build Coastguard Workerif [ -f icu/as_is/bomlist.txt ]; 104*0e209d39SAndroid Build Coastguard Workerthen 105*0e209d39SAndroid Build Coastguard Worker echo "Using icu/as_is/bomlist.txt" 106*0e209d39SAndroid Build Coastguard Worker pax -C 819 -rvf $tar_file `cat icu/as_is/bomlist.txt` 107*0e209d39SAndroid Build Coastguard Workerelse 108*0e209d39SAndroid Build Coastguard Worker for file in `find ./icu \( -name \*.txt -print \)`; do 109*0e209d39SAndroid Build Coastguard Worker bom8=`head -n 1 $file|\ 110*0e209d39SAndroid Build Coastguard Worker od -t x1|\ 111*0e209d39SAndroid Build Coastguard Worker head -n 1|\ 112*0e209d39SAndroid Build Coastguard Worker sed 's/ */ /g'|\ 113*0e209d39SAndroid Build Coastguard Worker cut -f2-4 -d ' '|\ 114*0e209d39SAndroid Build Coastguard Worker tr 'A-Z' 'a-z'`; 115*0e209d39SAndroid Build Coastguard Worker #Find a converted UTF-8 BOM 116*0e209d39SAndroid Build Coastguard Worker if [ "$bom8" = "057 08b 0ab" -o "$bom8" = "57 8b ab" ] 117*0e209d39SAndroid Build Coastguard Worker then 118*0e209d39SAndroid Build Coastguard Worker file="`echo $file | cut -d / -f2-`" 119*0e209d39SAndroid Build Coastguard Worker 120*0e209d39SAndroid Build Coastguard Worker if [ `echo $binary_files | wc -w` -lt 200 ] 121*0e209d39SAndroid Build Coastguard Worker then 122*0e209d39SAndroid Build Coastguard Worker bin_count=`expr $bin_count + 1` 123*0e209d39SAndroid Build Coastguard Worker binary_files="$binary_files $file"; 124*0e209d39SAndroid Build Coastguard Worker else 125*0e209d39SAndroid Build Coastguard Worker echo "Restoring binary files by BOM ($bin_count)..." 126*0e209d39SAndroid Build Coastguard Worker rm $binary_files; 127*0e209d39SAndroid Build Coastguard Worker pax -C 819 -rvf $tar_file $binary_files; 128*0e209d39SAndroid Build Coastguard Worker echo "Determining binary files by BOM ($bin_count)..." 129*0e209d39SAndroid Build Coastguard Worker binary_files="$file"; 130*0e209d39SAndroid Build Coastguard Worker bin_count=`expr $bin_count + 1` 131*0e209d39SAndroid Build Coastguard Worker fi 132*0e209d39SAndroid Build Coastguard Worker fi 133*0e209d39SAndroid Build Coastguard Worker done 134*0e209d39SAndroid Build Coastguard Worker # now see if a re-extract of binary files is necessary 135*0e209d39SAndroid Build Coastguard Worker if [ `echo $binary_files | wc -w` -gt 0 ] 136*0e209d39SAndroid Build Coastguard Worker then 137*0e209d39SAndroid Build Coastguard Worker echo "Restoring binary files ($bin_count) ..." 138*0e209d39SAndroid Build Coastguard Worker rm $binary_files 139*0e209d39SAndroid Build Coastguard Worker pax -C 819 -rvf $tar_file $binary_files 140*0e209d39SAndroid Build Coastguard Worker fi 141*0e209d39SAndroid Build Coastguard Workerfi 142*0e209d39SAndroid Build Coastguard Worker 143*0e209d39SAndroid Build Coastguard Workerecho "# Processing special paths." 144*0e209d39SAndroid Build Coastguard Worker# Process special paths 145*0e209d39SAndroid Build Coastguard Workermore_bin_opts=$(echo $binary_suffixes | sed -e 's%[a-zA-Z0-9]*%-o -name \*.&%g') 146*0e209d39SAndroid Build Coastguard Worker# echo "Looking for additional files: find ... $more_bin_opts" 147*0e209d39SAndroid Build Coastguard Workermore_bin_files=$(find icu -type f \( -name '*.zzz' $more_bin_opts \) -print) 148*0e209d39SAndroid Build Coastguard Workerecho "Restoring binary files by special paths ($bin_count) ..." 149*0e209d39SAndroid Build Coastguard Workerrm $more_bin_files 150*0e209d39SAndroid Build Coastguard Workerpax -C 819 -rvf $tar_file $more_bin_files 151*0e209d39SAndroid Build Coastguard Worker 152*0e209d39SAndroid Build Coastguard Worker#**************************************************************************** 153*0e209d39SAndroid Build Coastguard Worker# Generate and run the configure script 154*0e209d39SAndroid Build Coastguard Worker#**************************************************************************** 155*0e209d39SAndroid Build Coastguard Worker 156*0e209d39SAndroid Build Coastguard Workerecho "" 157*0e209d39SAndroid Build Coastguard Workerecho "Generating qsh compatible configure ..." 158*0e209d39SAndroid Build Coastguard Workerecho "" 159*0e209d39SAndroid Build Coastguard Worker 160*0e209d39SAndroid Build Coastguard Workersed -f icu/as_is/os400/convertConfigure.sed icu/source/configure > icu/source/configureTemp 161*0e209d39SAndroid Build Coastguard Workerdel -f icu/source/configure 162*0e209d39SAndroid Build Coastguard Workermv icu/source/configureTemp icu/source/configure 163*0e209d39SAndroid Build Coastguard Workerchmod 755 icu/source/configure 164*0e209d39SAndroid Build Coastguard Worker 165*0e209d39SAndroid Build Coastguard Workerecho "" 166*0e209d39SAndroid Build Coastguard Workerecho "$0 has completed extracting ICU from $tar_file - $bin_count binary files extracted." 167*0e209d39SAndroid Build Coastguard Worker 168