xref: /haiku/build/scripts/build_haiku_image (revision 1b8f7f13a3dc70e0e903cb94248220b40b732204)
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
59unzipFile()
60{
61	# unzipFile <archive> <directory>
62	zipFile=$1
63	targetUnzipDir=$2
64
65	echo "Unzipping $zipFile ..."
66
67	if [ $isImage ]; then
68		unzipDir=$tmpDir/unzip
69		rm -rf $unzipDir
70		mkdir -p $unzipDir
71
72		$unzip -q -d $unzipDir $zipFile
73		$cp -r ${sPrefix}$unzipDir/. ${tPrefix}$targetUnzipDir
74
75		rm -rf $unzipDir
76	else
77		$unzip -q -d ${tPrefix}$targetUnzipDir ${sPrefix}$zipFile
78	fi
79}
80
81
82# create the image and mount it
83if [ $isImage ]; then
84	echo
85	if [ ! $updateOnly ]; then
86		echo "Creating image ..."
87		if [ ! -e $imagePath -o ! "$dontClearImage" ]; then
88			dd if=/dev/zero of=$imagePath bs=1048576 count=$imageSize
89		fi
90		$bfsShell --initialize $imagePath Haiku
91		$makebootable $imagePath
92	fi
93	$bfsShell -n $imagePath > /dev/null &
94	sleep 1
95fi
96
97# create BEOS:APP_SIG index -- needed to launch apps via signature
98if [ ! $updateOnly ]; then
99	$mkindex BEOS:APP_SIG
100fi
101
102echo "Populating image ..."
103while [ $# -gt 0 ]; do
104	. $1
105	shift
106done
107
108
109# install MIME database
110# TODO: It should be possible to do that in the build system too.
111
112if [ ! $updateOnly ]; then
113	mimeDBSource=$sourceDir/src/data/beos_mime
114	mimeDBDest=${tPrefix}home/config/settings/beos_mime
115
116	echo "Deleting old MIME database ..."
117
118	$rm -rf $mimeDBDest
119	$mkdir -p $mimeDBDest
120	mkdir -p $tmpDir
121	mimeTmpDir=$tmpDir/mime
122	mimeTmpIndex=0
123
124	# create tmp dir for the MIME conversion stuff
125	mkdir -p $mimeTmpDir
126
127	echo "Installing MIME database ..."
128
129	for inSuperFile in $mimeDBSource/*.super; do
130		superType=$(basename $inSuperFile .super)
131		outSuperDir=$mimeDBDest/$superType
132
133		# compile rdef to rsrc file and the rsrc file to attributes
134		mimeTmpIndex=$(($mimeTmpIndex + 1))
135		tmpFile=$mimeTmpDir/mimedb$$_${mimeTmpIndex}.rsrc
136		tmpFile2=$mimeTmpDir/mimedb$$_${mimeTmpIndex}.mime
137		$rc -o $tmpFile $inSuperFile
138		mkdir -p $tmpFile2
139		$resattr -O -o $tmpFile2 $tmpFile
140		$cp -r ${sPrefix}$tmpFile2 $outSuperDir
141
142		# iterate through the sub types
143		for inSubFile in $mimeDBSource/$superType/*; do
144			# check, if the type exists
145			if test -f $inSubFile && grep META:TYPE $inSubFile > /dev/null 2>&1 ; then
146				subType=$(basename $inSubFile)
147				outSubFile=$outSuperDir/$subType
148
149				# compile rdef to rsrc file and the rsrc file to attributes
150				mimeTmpIndex=$(($mimeTmpIndex + 1))
151				tmpFile=$mimeTmpDir/mimedb$$_${mimeTmpIndex}.rsrc
152				tmpFile2=$mimeTmpDir/mimedb$$_${mimeTmpIndex}.mime
153				$rc -o $tmpFile $inSubFile
154				$resattr -O -o $tmpFile2 $tmpFile
155				$cp ${sPrefix}$tmpFile2 $outSubFile
156			fi
157		done
158	done
159
160	# cleanup tmp dir
161	rm -rf $mimeTmpDir
162fi	# ! updateOnly
163
164
165# install sources
166
167sourcesDest=${tPrefix}home/HaikuSources
168
169# create sources directory
170if [ -n "${sourceDirsToCopy}" ]; then
171	echo "Installing Haiku Sources ..."
172
173	$mkdir -p ${sourcesDest}
174fi
175
176for sourcesDir in ${sourceDirsToCopy}; do
177	echo "  sources dir:  ${sourcesDir}"
178
179	# create all subdirectories
180	subDirs=$(find ${sourcesDir} -type d | grep -v '.svn' |
181		sed -e "s@^${sourceDir}@${sourcesDest}@")
182	$mkdir -p ${subDirs}
183
184	# get all files and copy each one individually
185	sourceFiles=$(find $sourcesDir -type f | grep -v '.svn')
186	for sourceFile in $sourceFiles; do
187		destSourceFile=$(echo $sourceFile |
188			sed -e "s@^${sourceDir}@${sourcesDest}@")
189		$cp ${sPrefix}$sourceFile $destSourceFile
190	done
191done
192
193
194# unmount
195if [ $isImage ]; then
196	echo "Unmounting ..."
197	$fsShellCommand sync
198	$fsShellCommand quit
199fi
200