xref: /haiku/build/scripts/build_haiku_image (revision cfc3fa87da824bdf593eb8b817a83b6376e77935)
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	mimeTmpIndex=0
145
146	# create tmp dir for the MIME conversion stuff
147	mkdir -p $mimeTmpDir
148
149	echo "Installing MIME database ..."
150
151	for inSuperFile in $mimeDBSource/*.super; do
152		superType=$(basename $inSuperFile .super)
153		outSuperDir=$mimeDBDest/$superType
154
155		# compile rdef to rsrc file and the rsrc file to attributes
156		mimeTmpIndex=$(($mimeTmpIndex + 1))
157		tmpFile=$mimeTmpDir/mimedb$$_${mimeTmpIndex}.rsrc
158		tmpFile2=$mimeTmpDir/mimedb$$_${mimeTmpIndex}.mime
159		$rc -o $tmpFile $inSuperFile
160		mkdir -p $tmpFile2
161		$resattr -O -o $tmpFile2 $tmpFile
162		$cp -r ${sPrefix}$tmpFile2 $outSuperDir
163
164		# iterate through the sub types
165		for inSubFile in $mimeDBSource/$superType/*; do
166			# check, if the type exists
167			if test -f $inSubFile && grep META:TYPE $inSubFile > /dev/null 2>&1 ; then
168				subType=$(basename $inSubFile)
169				outSubFile=$outSuperDir/$subType
170
171				# compile rdef to rsrc file and the rsrc file to attributes
172				mimeTmpIndex=$(($mimeTmpIndex + 1))
173				tmpFile=$mimeTmpDir/mimedb$$_${mimeTmpIndex}.rsrc
174				tmpFile2=$mimeTmpDir/mimedb$$_${mimeTmpIndex}.mime
175				$rc -o $tmpFile $inSubFile
176				$resattr -O -o $tmpFile2 $tmpFile
177				$cp ${sPrefix}$tmpFile2 $outSubFile
178			fi
179		done
180	done
181
182	# cleanup tmp dir
183	$rmAttrs -rf $mimeTmpDir
184fi	# ! updateOnly
185
186
187# unmount
188if [ $isImage ]; then
189	echo "Unmounting ..."
190	$fsShellCommand sync
191	$fsShellCommand quit
192fi
193