xref: /haiku/3rdparty/os_probe/83haiku (revision c09821c07d145fe16dc858b56bdefc0a466c651c)
1#!/bin/sh
2# Detects Haiku on BeFS partitions and FUSE mounted BeFS too.
3# Discussion at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=732696
4# From version 42 (dated 20150811) updated by Jeroen Oortwijn at https://bazaar.launchpad.net/~idefix/ubuntu/trusty/os-prober/HaikuPM/files/head:/os-probes/mounted/x86
5
6. /usr/share/os-prober/common.sh
7
8partition="$1"
9mpoint="$2"
10type="$3"
11
12# Weed out stuff that doesn't apply to us
13case "$type" in
14	bfs|befs) debug "$partition is a BeFS partition" ;;
15	fuse|fuseblk) debug "$partition is a FUSE partition" ; mpoint="$mpoint/myfs" ;; # might be befs-fuse
16	*) debug "$partition is not a BeFS partition: exiting"; exit 1 ;;
17esac
18
19if head -c 512 "$partition" | grep -qs "haiku_loader"; then
20	debug "Haiku stage 1 bootloader found"
21else
22	debug "Haiku stage 1 bootloader not found: exiting"
23	exit 1
24fi
25
26if system="$(item_in_dir "system" "$mpoint")" &&
27	packages="$(item_in_dir "packages" "$mpoint/$system")" &&
28		item_in_dir -q "haiku_loader-.*\.hpkg" "$mpoint/$system/$packages" &&
29		rev="$(item_in_dir "haiku-.*\.hpkg" "$mpoint/$system/$packages")"
30then
31	debug "Haiku PM stage 2 bootloader and kernel found"
32	label="$(count_next_label Haiku)"
33	rev="$(echo "$rev" | sed 's/haiku-//;s/^\(r[0-9]\+\)./\U\1\E /;s/ \([a-z]\+[0-9]\+\)[_-]/ \1 /;s/ [a-z]*_\?\(hrev[0-9]\+\)\+-/ (\1) /;s/[^ ]\+.hpkg//;s/ $//')"
34	long="Haiku $rev"
35	result "$partition:$long:$label:chain"
36	exit 0
37elif system="$(item_in_dir "system" "$mpoint")" &&
38	item_in_dir -q "haiku_loader" "$mpoint/$system" &&
39	item_in_dir -q "kernel_.*" "$mpoint/$system"
40then
41	debug "Haiku non-PM stage 2 bootloader and kernel found"
42	label="$(count_next_label Haiku)"
43	result "$partition:Haiku:$label:chain"
44	exit 0
45else
46	debug "Haiku stage 2 bootloader and kernel not found: exiting"
47	exit 1
48fi
49