1#!/bin/sh 2set -o errexit 3 4# The first argument is the shell script that initializes the variables: 5# addBuildCompatibilityLibDir 6# mimeDB 7# outputDir 8# sourceDir 9# tmpDir 10# compressionLevel 11# updateOnly 12# cc 13# 14# addattr 15# copyattr 16# mimeset 17# package 18# rc 19# rmAttrs 20# unzip 21# 22 23if [ $# -le 1 ]; then 24 echo "$0: Missing parameters!" >&2 25 exit 1 26fi 27 28packagePath="$1" 29packageInfoPath="$2" 30shift 2 31 32if [ $# -gt 0 ]; then 33 . $1 34 shift 35fi 36 37# this adds the build library dir to LD_LIBRARY_PATH 38eval "$addBuildCompatibilityLibDir" 39 40 41# make a clean contents dir 42packageName=`basename "$packagePath"` 43echo "$packageName: Removing and re-creating package contents dir ..." 44contentsDir="$tmpDir/contents" 45$rmAttrs -rf "$contentsDir" 46mkdir -p "$contentsDir" 47 48 49# map the shell commands 50sPrefix= 51tPrefix="$contentsDir/" 52cd=cd 53scd=: 54cp="$copyattr -d" 55copyAttrs="$copyattr" 56ln=ln 57mkdir=mkdir 58rm=$rmAttrs 59mkindex=mkindex 60 61 62extractFile() 63{ 64 # extractFile <archive> <directory> <extractedSubDir> 65 archiveFile=$1 66 targetExtractedDir=$2 67 extractedSubDir=$3 68 69 extractDir=$tmpDir/extract 70 $rmAttrs -rf "$extractDir" 71 mkdir -p "$extractDir" 72 73 case "$archiveFile" in 74 *.zip) 75 $unzip -q -d "$extractDir" "$archiveFile" 76 ;; 77 *.tgz|*.tar.gz) 78 tar -C "$extractDir" -xf "$archiveFile" 79 ;; 80 *.hpkg) 81 if [ -n "$extractedSubDir" ]; then 82 $package extract -C "$extractDir" "$archiveFile" \ 83 "$extractedSubDir" 84 else 85 $package extract -C "$extractDir" "$archiveFile" 86 fi 87 ;; 88 *) 89 echo "Unhandled archive extension in build_haiku_image" \ 90 "extractFile()" 91 exit 1 92 ;; 93 esac 94 95 $cp -r "${sPrefix}$extractDir/$extractedSubDir/." \ 96 "${tPrefix}$targetExtractedDir" 97 98 $rmAttrs -rf "$extractDir" 99} 100 101 102# execute the scripts preparing the package contents 103echo "$packageName: Collecting package contents ..." 104while [ $# -gt 0 ]; do 105 . $1 106 shift 107done 108 109 110# mimeset the whole package content 111echo "$packageName: mimeset'ing package contents ..." 112$mimeset --mimedb "$mimeDB" "$contentsDir" 113 114 115# create the package 116if [ ! $updateOnly ]; then 117 echo "$packageName: Creating the package ..." 118 rm -f "$packagePath" 119 $package create -q "-$compressionLevel" -i "$packageInfoPath" \ 120 -C "$contentsDir" "$packagePath" 121else 122 echo "$packageName: Updating the package ..." 123 $package add -q -f "-$compressionLevel" -i "$packageInfoPath" \ 124 -C "$contentsDir" "$packagePath" . 125fi 126