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