xref: /haiku/build/scripts/build_haiku_image (revision 1b80286772b529a3d6de3bbeb0720c62e6a32fed)
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		imageFlags="-i${imageSize}M"
120		if [ ! "$dontClearImage" ]; then
121			imageFlags="$imageFlags -c"
122		fi
123
124		if [ $isVMwareImage ]; then
125			$vmdkimage -h 64k $imageFlags "$imagePath" || exit 1
126		else
127			$createImage $imageFlags "$imagePath" || exit 1
128		fi
129
130		$bfsShell --initialize $imageOffsetFlags "$imagePath" \
131			"$imageLabel" "block_size 2048" || exit 1
132		$makebootable $imageOffsetFlags "$imagePath"
133	fi
134	$bfsShell -n $imageOffsetFlags "$imagePath" > /dev/null &
135	sleep 1
136	# bail out, if mounting fails
137	$cd . || exit 1
138fi
139
140echo "Populating image ..."
141while [ $# -gt 0 ]; do
142	. $1
143	shift
144done
145
146
147# install MIME database
148# TODO: It should be possible to do that in the build system too.
149
150if [ ! $updateOnly ]; then
151	mimeDBSource=$sourceDir/src/data/beos_mime
152	mimeDBDest=${tPrefix}home/config/settings/beos_mime
153
154	echo "Deleting old MIME database ..."
155
156	$rm -rf $mimeDBDest
157	$mkdir -p $mimeDBDest
158	mimeTmpDir=$tmpDir/mime
159	mimeDBTmpDir=$tmpDir/mime/db
160	mimeTmpIndex=0
161	mimeTmpFile=$mimeTmpDir/mimedb$$.rsrc
162
163	# create tmp dir for the MIME conversion stuff
164	mkdir -p $mimeDBTmpDir
165
166	echo "Installing MIME database ..."
167
168	for inSuperFile in $mimeDBSource/*.super; do
169		superType=$(basename $inSuperFile .super)
170		tmpSuperDir=$mimeDBTmpDir/$superType
171
172		# compile rdef to rsrc file and the rsrc file to attributes
173		$rc -o $mimeTmpFile $inSuperFile
174		mkdir -p $tmpSuperDir
175		$resattr -O -o $tmpSuperDir $mimeTmpFile
176		$rmAttrs $mimeTmpFile
177
178		# iterate through the sub types
179		for inSubFile in $mimeDBSource/$superType/*; do
180			# check, if the type exists
181			if test -f $inSubFile && grep META:TYPE $inSubFile > /dev/null 2>&1 ; then
182				subType=$(basename $inSubFile)
183				tmpSubFile=$mimeDBTmpDir/$superType/$subType
184
185				# compile rdef to rsrc file and the rsrc file to attributes
186				$rc -o $mimeTmpFile $inSubFile
187				$resattr -O -o $tmpSubFile $mimeTmpFile
188				$rmAttrs $mimeTmpFile
189			fi
190		done
191	done
192
193	$cp -r ${sPrefix}$mimeDBTmpDir/. $mimeDBDest
194
195	# cleanup tmp dir
196	$rmAttrs -rf $mimeTmpDir
197fi	# ! updateOnly
198
199
200# add the concatenated copyrights as an attribute to AboutSystem
201
202if [ ! $updateOnly ]; then
203	if [ -f $copyrightsFile ]; then
204		copyrightAttrs=$tmpDir/copyrightAttrs
205		$rmAttrs -f $copyrightAttrs
206		touch $copyrightAttrs
207		$addattr -f $copyrightsFile COPYRIGHTS $copyrightAttrs
208		$copyAttrs ${sPrefix}$copyrightAttrs ${tPrefix}system/apps/AboutSystem
209	fi
210fi
211
212
213# unmount
214if [ $isImage ]; then
215	echo "Unmounting ..."
216	$fsShellCommand sync
217	$fsShellCommand quit
218fi
219