1#!/bin/sh 2 3# The first argument is the shell script that initializes the variables: 4# sourceDir 5# outputDir 6# tmpDir 7# installDir 8# isImage 9# imagePath 10# imageSize 11# imageLabel 12# addBuildCompatibilityLibDir 13# updateOnly 14# dontClearImage 15# isVMwareImage 16# optionalPackageDescriptions 17# 18# addattr 19# bfsShell 20# copyattr 21# fsShellCommand 22# makebootable 23# resattr 24# rc 25# rmAttrs 26# unzip 27# vmdkimage 28# 29if [ $# -gt 0 ]; then 30 . $1 31 shift 32fi 33 34# If the haiku image path is a symlink resolve it now (makebootable needs the 35# path of the actual device path under Linux). 36if readlink -f "$imagePath" &> /dev/null; then 37 normalizedImagePath=$(readlink -f "$imagePath") 38 if [ $normalizedImagePath ]; then 39 imagePath="$normalizedImagePath" 40 fi 41fi 42 43# this adds the build library dir to LD_LIBRARY_PATH 44eval "$addBuildCompatibilityLibDir" 45 46# map the shell commands 47if [ $isImage ]; then 48 sPrefix=: 49 tPrefix=/myfs/ 50 cd="$fsShellCommand cd" 51 scd="$fsShellCommand cd" 52 cp="$fsShellCommand cp -f" 53 copyAttrs="$fsShellCommand cp -a" 54 ln="$fsShellCommand ln" 55 mkdir="$fsShellCommand mkdir" 56 rm="$fsShellCommand rm" 57 mkindex="$fsShellCommand mkindex" 58else 59 sPrefix= 60 # TODO: This should come from the environment. 61 tPrefix="$installDir/" 62 cd=cd 63 scd=: 64 cp="$copyattr -d" 65 copyAttrs="$copyattr" 66 ln=ln 67 mkdir=mkdir 68 rm=rm 69 mkindex=mkindex 70fi 71 72 73unzipFile() 74{ 75 # unzipFile <archive> <directory> 76 zipFile=$1 77 targetUnzipDir=$2 78 79 echo "Unzipping $zipFile ..." 80 81 unzipDir=$tmpDir/unzip 82 $rmAttrs -rf "$unzipDir" 83 mkdir -p "$unzipDir" 84 85 $unzip -q -d "$unzipDir" "$zipFile" 86 87 if [ -f $unzipDir/.OptionalPackageDescription ]; then 88 cat $unzipDir/.OptionalPackageDescription >> $copyrightsFile 89 echo >> $copyrightsFile 90 rm $unzipDir/.OptionalPackageDescription 91 fi 92 93 $cp -r "${sPrefix}$unzipDir/." "${tPrefix}$targetUnzipDir" 94 95 $rmAttrs -rf "$unzipDir" 96} 97 98 99mkdir -p $tmpDir 100copyrightsFile=$tmpDir/copyrights 101$rmAttrs -f $copyrightsFile 102if [ "$optionalPackageDescriptions" ]; then 103 cp "$optionalPackageDescriptions" $copyrightsFile 104fi 105 106 107# create the image and mount it 108if [ $isImage ]; then 109 echo 110 111 imageOffsetFlags= 112 if [ $isVMwareImage ]; then 113 imageOffsetFlags="--start-offset 65536" 114 fi 115 116 if [ ! $updateOnly ]; then 117 echo "Creating image ..." 118 119 ddFlags= 120 if [ $isVMwareImage ]; then 121 vmdkImageFlags= 122 if [ ! "$dontClearImage" ]; then 123 vmdkImageFlags="-c" 124 fi 125 $vmdkimage -h 64k -i${imageSize}M $vmdkImageFlags "$imagePath" \ 126 || exit 1 127 elif [ ! -e "$imagePath" -o ! "$dontClearImage" ]; then 128 dd if=/dev/zero of="$imagePath" bs=1048576 count=$imageSize \ 129 || exit 1 130 fi 131 132 $bfsShell --initialize $imageOffsetFlags "$imagePath" \ 133 "$imageLabel" "block_size 2048" || exit 1 134 $makebootable $imageOffsetFlags "$imagePath" 135 fi 136 $bfsShell -n $imageOffsetFlags "$imagePath" > /dev/null & 137 sleep 1 138 # bail out, if mounting fails 139 $cd . || exit 1 140fi 141 142# create BEOS:APP_SIG index -- needed to launch apps via signature 143if [ ! $updateOnly ]; then 144 $mkindex BEOS:APP_SIG 145fi 146 147echo "Populating image ..." 148while [ $# -gt 0 ]; do 149 . $1 150 shift 151done 152 153 154# install MIME database 155# TODO: It should be possible to do that in the build system too. 156 157if [ ! $updateOnly ]; then 158 mimeDBSource=$sourceDir/src/data/beos_mime 159 mimeDBDest=${tPrefix}home/config/settings/beos_mime 160 161 echo "Deleting old MIME database ..." 162 163 $rm -rf $mimeDBDest 164 $mkdir -p $mimeDBDest 165 mimeTmpDir=$tmpDir/mime 166 mimeDBTmpDir=$tmpDir/mime/db 167 mimeTmpIndex=0 168 mimeTmpFile=$mimeTmpDir/mimedb$$.rsrc 169 170 # create tmp dir for the MIME conversion stuff 171 mkdir -p $mimeDBTmpDir 172 173 echo "Installing MIME database ..." 174 175 for inSuperFile in $mimeDBSource/*.super; do 176 superType=$(basename $inSuperFile .super) 177 tmpSuperDir=$mimeDBTmpDir/$superType 178 179 # compile rdef to rsrc file and the rsrc file to attributes 180 $rc -o $mimeTmpFile $inSuperFile 181 mkdir -p $tmpSuperDir 182 $resattr -O -o $tmpSuperDir $mimeTmpFile 183 $rmAttrs $mimeTmpFile 184 185 # iterate through the sub types 186 for inSubFile in $mimeDBSource/$superType/*; do 187 # check, if the type exists 188 if test -f $inSubFile && grep META:TYPE $inSubFile > /dev/null 2>&1 ; then 189 subType=$(basename $inSubFile) 190 tmpSubFile=$mimeDBTmpDir/$superType/$subType 191 192 # compile rdef to rsrc file and the rsrc file to attributes 193 $rc -o $mimeTmpFile $inSubFile 194 $resattr -O -o $tmpSubFile $mimeTmpFile 195 $rmAttrs $mimeTmpFile 196 fi 197 done 198 done 199 200 $cp -r ${sPrefix}$mimeDBTmpDir/. $mimeDBDest 201 202 # cleanup tmp dir 203 $rmAttrs -rf $mimeTmpDir 204fi # ! updateOnly 205 206 207# add the concatenated copyrights as an attribute to AboutSystem 208 209if [ ! $updateOnly ]; then 210 if [ -f $copyrightsFile ]; then 211 copyrightAttrs=$tmpDir/copyrightAttrs 212 $rmAttrs -f $copyrightAttrs 213 touch $copyrightAttrs 214 $addattr -f $copyrightsFile COPYRIGHTS $copyrightAttrs 215 $copyAttrs ${sPrefix}$copyrightAttrs ${tPrefix}beos/apps/AboutSystem 216 fi 217fi 218 219 220# unmount 221if [ $isImage ]; then 222 echo "Unmounting ..." 223 $fsShellCommand sync 224 $fsShellCommand quit 225fi 226