#!/bin/shset -o errexit# The first argument is the shell script that initializes the variables:# addBuildCompatibilityLibDir# mimeDB# outputDir# sourceDir# tmpDir# compressionLevel# updateOnly# cc## addattr# copyattr# mimeset# package# rc# rmAttrs# unzip#if [ $# -le 1 ]; thenecho "$0: Missing parameters!" >&2exit 1fipackagePath="$1"packageInfoPath="$2"shift 2if [ $# -gt 0 ]; then. $1shiftfi# this adds the build library dir to LD_LIBRARY_PATHeval "$addBuildCompatibilityLibDir"# make a clean contents dirpackageName=`basename "$packagePath"`echo "$packageName: Removing and re-creating package contents dir ..."contentsDir="$tmpDir/contents"$rmAttrs -rf "$contentsDir"mkdir -p "$contentsDir"# map the shell commandssPrefix=tPrefix="$contentsDir/"cd=cdscd=:cp="$copyattr -d"copyAttrs="$copyattr"ln=lnmkdir=mkdirrm=$rmAttrsmkindex=mkindexextractFile(){# extractFile <archive> <directory> <extractedSubDir>archiveFile=$1targetExtractedDir=$2extractedSubDir=$3extractDir=$tmpDir/extract$rmAttrs -rf "$extractDir"mkdir -p "$extractDir"case "$archiveFile" in*.zip)$unzip -q -d "$extractDir" "$archiveFile";;*.tgz|*.tar.gz)tar -C "$extractDir" -xf "$archiveFile";;*.hpkg)if [ -n "$extractedSubDir" ]; then$package extract -C "$extractDir" "$archiveFile" \"$extractedSubDir"else$package extract -C "$extractDir" "$archiveFile"fi;;*)echo "Unhandled archive extension in build_haiku_image" \"extractFile()"exit 1;;esac$cp -r "${sPrefix}$extractDir/$extractedSubDir/." \"${tPrefix}$targetExtractedDir"$rmAttrs -rf "$extractDir"}# execute the scripts preparing the package contentsecho "$packageName: Collecting package contents ..."while [ $# -gt 0 ]; do. $1shiftdone# mimeset the whole package contentecho "$packageName: mimeset'ing package contents ..."$mimeset --mimedb "$mimeDB" "$contentsDir"# create the packageif [ ! $updateOnly ]; thenecho "$packageName: Creating the package ..."$rmAttrs -f "$packagePath"$package create -q "-$compressionLevel" -i "$packageInfoPath" \-C "$contentsDir" "$packagePath"elseecho "$packageName: Updating the package ..."$package add -q -f "-$compressionLevel" -i "$packageInfoPath" \-C "$contentsDir" "$packagePath" .fi