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