xref: /haiku/3rdparty/os_probe/83haiku (revision 3958b5545b689b03177237aa49adfeae1bac8919)
1#!/usr/bin/sh
2# Detects Haiku on BeFS partitions.
3
4. /usr/share/os-prober/common.sh
5
6partition="$1"
7mpoint="$2"
8type="$3"
9
10# Weed out stuff that doesn't apply to us
11case "$type" in
12	befs|befs_be) debug "$partition is a BeFS partition" ;;
13	*) debug "$partition is not a BeFS partition: exiting"; exit 1 ;;
14esac
15
16if head -c 512 "$partition" | grep -qs 'system.*haiku_loader'; then
17	debug "Stage 1 bootloader found"
18else
19	debug "Stage 1 bootloader not found: exiting"
20	exit 1
21fi
22
23system="$(item_in_dir "system" "$mpoint")"
24packages="$(item_in_dir "packages" "$mpoint/$system")"
25found=
26if [ "$system" != "" ] &&
27	item_in_dir -q "haiku_loader" "$mpoint/$system" &&
28	(item_in_dir -q "kernel_x86" "$mpoint/$system" ||
29		item_in_dir -q "kernel_x86_64" "$mpoint/$system")
30then
31	found=1
32fi
33
34if [ "$found" = "" ] && [ "$packages" != "" ] &&
35	item_in_dir -q "haiku_loader\-.*" "$mpoint/$system/$packages" &&
36	(item_in_dir -q "haiku_x86\-.*" "$mpoint/$system/$packages" ||
37		item_in_dir -q "haiku_x86_64\-.*" "$mpoint/$system/$packages")
38then
39	found=1
40fi
41
42if [ "$found" != "" ]
43then
44	debug "Stage 2 bootloader and kernel found"
45	label="$(count_next_label Haiku)"
46	result "$partition:Haiku:$label:chain"
47	exit 0
48else
49	debug "Stage 2 bootloader and kernel not found: exiting"
50	exit 1
51fi
52