#!/bin/shset -o errexitif [ $# -lt 2 ]; thenecho "Usage: $0 <archive> <scripts> ..."fi# get the archive namearchive=$1shift# The second argument is the shell script that initializes the variables:# tmpDir# addBuildCompatibilityLibDir## copyattr# rmAttrs# zip# NOTE: rmAttrs and zip are only passed in when building zip#. $1shiftoutputDir=$tmpDir/archive# this adds the build library dir to LD_LIBRARY_PATHeval "$addBuildCompatibilityLibDir"# map the shell commandssPrefix=tPrefix="$outputDir/"cd=cdscd=:cp="$copyattr -d"ln=lnmkdir=mkdirrm=rmcleanDir(){# clearDir <directory>if [ $rmAttrs ] ; then$rmAttrs -rf $1else$rm -rf $1fi}# clean output dircleanDir $outputDir$mkdir -p $outputDir# populate output direcho "Preparing contents of archive $archive ..."while [ $# -gt 0 ]; do. $1shiftdone# get an absolute path for the archivecwd=$(pwd)cd $(dirname $archive)archive=$(pwd)/$(basename $archive)cd $cwd# build the archiveecho "Building archive $archive ..."$rm -f $archivecd $outputDircase "$archive" in*.zip)$zip -ryq $archive .;;*.tgz)contents=$(ls)tar --format ustar -czf $archive $contents;;*)echo "Unhandled archive format in build_archive"exit 1;;esaccd ..# clean upcleanDir $outputDir