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