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