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