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