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 142echo "Populating image ..." 143while [ $# -gt 0 ]; do 144 . $1 145 shift 146done 147 148 149# install MIME database 150# TODO: It should be possible to do that in the build system too. 151 152if [ ! $updateOnly ]; then 153 mimeDBSource=$sourceDir/src/data/beos_mime 154 mimeDBDest=${tPrefix}home/config/settings/beos_mime 155 156 echo "Deleting old MIME database ..." 157 158 $rm -rf $mimeDBDest 159 $mkdir -p $mimeDBDest 160 mimeTmpDir=$tmpDir/mime 161 mimeDBTmpDir=$tmpDir/mime/db 162 mimeTmpIndex=0 163 mimeTmpFile=$mimeTmpDir/mimedb$$.rsrc 164 165 # create tmp dir for the MIME conversion stuff 166 mkdir -p $mimeDBTmpDir 167 168 echo "Installing MIME database ..." 169 170 for inSuperFile in $mimeDBSource/*.super; do 171 superType=$(basename $inSuperFile .super) 172 tmpSuperDir=$mimeDBTmpDir/$superType 173 174 # compile rdef to rsrc file and the rsrc file to attributes 175 $rc -o $mimeTmpFile $inSuperFile 176 mkdir -p $tmpSuperDir 177 $resattr -O -o $tmpSuperDir $mimeTmpFile 178 $rmAttrs $mimeTmpFile 179 180 # iterate through the sub types 181 for inSubFile in $mimeDBSource/$superType/*; do 182 # check, if the type exists 183 if test -f $inSubFile && grep META:TYPE $inSubFile > /dev/null 2>&1 ; then 184 subType=$(basename $inSubFile) 185 tmpSubFile=$mimeDBTmpDir/$superType/$subType 186 187 # compile rdef to rsrc file and the rsrc file to attributes 188 $rc -o $mimeTmpFile $inSubFile 189 $resattr -O -o $tmpSubFile $mimeTmpFile 190 $rmAttrs $mimeTmpFile 191 fi 192 done 193 done 194 195 $cp -r ${sPrefix}$mimeDBTmpDir/. $mimeDBDest 196 197 # cleanup tmp dir 198 $rmAttrs -rf $mimeTmpDir 199fi # ! updateOnly 200 201 202# add the concatenated copyrights as an attribute to AboutSystem 203 204if [ ! $updateOnly ]; then 205 if [ -f $copyrightsFile ]; then 206 copyrightAttrs=$tmpDir/copyrightAttrs 207 $rmAttrs -f $copyrightAttrs 208 touch $copyrightAttrs 209 $addattr -f $copyrightsFile COPYRIGHTS $copyrightAttrs 210 $copyAttrs ${sPrefix}$copyrightAttrs ${tPrefix}beos/apps/AboutSystem 211 fi 212fi 213 214 215# unmount 216if [ $isImage ]; then 217 echo "Unmounting ..." 218 $fsShellCommand sync 219 $fsShellCommand quit 220fi 221