xref: /haiku/build/scripts/build_haiku_image (revision 5412911f7f8ca41340b0f5cb928ed9726322ab44)
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#
13# bfsShell
14# copyattr
15# fsShellCommand
16# makebootable
17# resattr
18# rc
19#
20if [ $# -gt 0 ]; then
21	. $1
22	shift
23fi
24
25# this adds the build library dir to LD_LIBRARY_PATH
26eval "$addBuildCompatibilityLibDir"
27
28# map the shell commands
29if [ $isImage ]; then
30	sPrefix=:
31	tPrefix=/myfs/
32	cd="$fsShellCommand cd"
33	scd="$fsShellCommand cd"
34	cp="$fsShellCommand cp"
35	ln="$fsShellCommand ln"
36	mkdir="$fsShellCommand mkdir"
37	rm="$fsShellCommand rm"
38	mkindex="$fsShellCommand mkindex"
39else
40	sPrefix=
41	# TODO: This should come from the environment.
42	tPrefix="$installDir/"
43	cd=cd
44	scd=:
45	cp="$copyattr -d"
46	ln=ln
47	mkdir=mkdir
48	rm=rm
49	mkindex=mkindex
50fi
51
52# create the image and mount it
53if [ $isImage ]; then
54	echo
55	echo "Creating image ..."
56	dd if=/dev/zero of=$imagePath bs=1M count=$imageSize
57	$bfsShell --initialize $imagePath Haiku
58	$makebootable $imagePath
59	$bfsShell -n $imagePath > /dev/null &
60	sleep 1
61fi
62
63$mkindex BEOS:APP_SIG
64	# needed to launch apps via signature
65
66echo "Populating image ..."
67while [ $# -gt 0 ]; do
68	. $1
69	shift
70done
71
72
73# install MIME database
74# TODO: It should be possible to do that in the build system too.
75mimeDBSource=$sourceDir/src/data/beos_mime
76mimeDBDest=${tPrefix}home/config/settings/beos_mime
77
78echo "Deleting old MIME database ..."
79
80$rm -rf $mimeDBDest
81$mkdir -p $mimeDBDest
82mkdir -p $tmpDir
83
84echo "Installing MIME database ..."
85
86for inSuperFile in $mimeDBSource/*.super; do
87	superType=$(basename $inSuperFile .super)
88	outSuperDir=$mimeDBDest/$superType
89
90	# compile rdef to rsrc file and the rsrc file to attributes
91	tmpFile=$tmpDir/mimedb$$.rsrc
92	tmpFile2=$tmpDir/mimedb$$.mime
93	$rc -o $tmpFile $inSuperFile
94	mkdir -p $tmpFile2
95	$resattr -O -o $tmpFile2 $tmpFile
96	$cp -r ${sPrefix}$tmpFile2 $outSuperDir
97	rm -rf $tmpFile $tmpFile2
98
99	# iterate through the sub types
100	for inSubFile in $mimeDBSource/$superType/*; do
101		# check, if the type exists
102		if test -f $inSubFile && grep META:TYPE $inSubFile &> /dev/null; then
103			subType=$(basename $inSubFile)
104			outSubFile=$outSuperDir/$subType
105
106			# compile rdef to rsrc file and the rsrc file to attributes
107			tmpFile=$tmpDir/mimedb$$.rsrc
108			tmpFile2=$tmpDir/mimedb$$.mime
109			$rc -o $tmpFile $inSubFile
110			$resattr -O -o $tmpFile2 $tmpFile
111			$cp ${sPrefix}$tmpFile2 $outSubFile
112			rm -f $tmpFile $tmpFile2
113		fi
114	done
115done
116
117
118# unmount
119if [ $isImage ]; then
120	echo "Unmounting ..."
121	$fsShellCommand sync
122	$fsShellCommand quit
123fi
124