1#!/bin/sh 2set -o errexit 3 4if [ $# -lt 2 ]; then 5 echo "Usage: $0 <archive> <scripts> ..." 6fi 7 8# get the archive name 9archive=$1 10shift 11 12# The second argument is the shell script that initializes the variables: 13# tmpDir 14# addBuildCompatibilityLibDir 15# 16# copyattr 17# rmAttrs 18# zip 19# NOTE: rmAttrs and zip are only passed in when building zip 20# 21. $1 22shift 23 24outputDir=$tmpDir/archive 25 26# this adds the build library dir to LD_LIBRARY_PATH 27eval "$addBuildCompatibilityLibDir" 28 29# map the shell commands 30sPrefix= 31tPrefix="$outputDir/" 32cd=cd 33scd=: 34cp="$copyattr -d" 35ln=ln 36mkdir=mkdir 37rm=rm 38 39 40cleanDir() 41{ 42 # clearDir <directory> 43 if [ $rmAttrs ] ; then 44 $rmAttrs -rf $1 45 else 46 $rm -rf $1 47 fi 48} 49 50 51# clean output dir 52cleanDir $outputDir 53$mkdir -p $outputDir 54 55# populate output dir 56echo "Preparing contents of archive $archive ..." 57while [ $# -gt 0 ]; do 58 . $1 59 shift 60done 61 62# get an absolute path for the archive 63cwd=$(pwd) 64cd $(dirname $archive) 65archive=$(pwd)/$(basename $archive) 66cd $cwd 67 68# build the archive 69echo "Building archive $archive ..." 70$rm -f $archive 71cd $outputDir 72case "$archive" in 73 *.zip) 74 $zip -ryq $archive . 75 ;; 76 *.tgz) 77 contents=$(ls) 78 tar --format ustar -czf $archive $contents 79 ;; 80 *) 81 echo "Unhandled archive format in build_archive" 82 exit 1 83 ;; 84esac 85cd .. 86 87# clean up 88cleanDir $outputDir 89