xref: /haiku/3rdparty/os_probe/83haiku (revision c09821c07d145fe16dc858b56bdefc0a466c651c)
1*c09821c0SAlexander G. M. Smith#!/bin/sh
2*c09821c0SAlexander G. M. Smith# Detects Haiku on BeFS partitions and FUSE mounted BeFS too.
3*c09821c0SAlexander G. M. Smith# Discussion at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=732696
4*c09821c0SAlexander G. M. Smith# 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
502354704SAlexander G. M. Smith
602354704SAlexander G. M. Smith. /usr/share/os-prober/common.sh
702354704SAlexander G. M. Smith
802354704SAlexander G. M. Smithpartition="$1"
902354704SAlexander G. M. Smithmpoint="$2"
1002354704SAlexander G. M. Smithtype="$3"
1102354704SAlexander G. M. Smith
1202354704SAlexander G. M. Smith# Weed out stuff that doesn't apply to us
1302354704SAlexander G. M. Smithcase "$type" in
14*c09821c0SAlexander G. M. Smith	bfs|befs) debug "$partition is a BeFS partition" ;;
15*c09821c0SAlexander G. M. Smith	fuse|fuseblk) debug "$partition is a FUSE partition" ; mpoint="$mpoint/myfs" ;; # might be befs-fuse
1602354704SAlexander G. M. Smith	*) debug "$partition is not a BeFS partition: exiting"; exit 1 ;;
1702354704SAlexander G. M. Smithesac
1802354704SAlexander G. M. Smith
19*c09821c0SAlexander G. M. Smithif head -c 512 "$partition" | grep -qs "haiku_loader"; then
20*c09821c0SAlexander G. M. Smith	debug "Haiku stage 1 bootloader found"
2102354704SAlexander G. M. Smithelse
22*c09821c0SAlexander G. M. Smith	debug "Haiku stage 1 bootloader not found: exiting"
2302354704SAlexander G. M. Smith	exit 1
2402354704SAlexander G. M. Smithfi
2502354704SAlexander G. M. Smith
26*c09821c0SAlexander G. M. Smithif system="$(item_in_dir "system" "$mpoint")" &&
27*c09821c0SAlexander G. M. Smith	packages="$(item_in_dir "packages" "$mpoint/$system")" &&
28*c09821c0SAlexander G. M. Smith		item_in_dir -q "haiku_loader-.*\.hpkg" "$mpoint/$system/$packages" &&
29*c09821c0SAlexander G. M. Smith		rev="$(item_in_dir "haiku-.*\.hpkg" "$mpoint/$system/$packages")"
30*c09821c0SAlexander G. M. Smiththen
31*c09821c0SAlexander G. M. Smith	debug "Haiku PM stage 2 bootloader and kernel found"
32*c09821c0SAlexander G. M. Smith	label="$(count_next_label Haiku)"
33*c09821c0SAlexander G. M. Smith	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*c09821c0SAlexander G. M. Smith	long="Haiku $rev"
35*c09821c0SAlexander G. M. Smith	result "$partition:$long:$label:chain"
36*c09821c0SAlexander G. M. Smith	exit 0
37*c09821c0SAlexander G. M. Smithelif system="$(item_in_dir "system" "$mpoint")" &&
3802354704SAlexander G. M. Smith	item_in_dir -q "haiku_loader" "$mpoint/$system" &&
39*c09821c0SAlexander G. M. Smith	item_in_dir -q "kernel_.*" "$mpoint/$system"
4002354704SAlexander G. M. Smiththen
41*c09821c0SAlexander G. M. Smith	debug "Haiku non-PM stage 2 bootloader and kernel found"
4202354704SAlexander G. M. Smith	label="$(count_next_label Haiku)"
4302354704SAlexander G. M. Smith	result "$partition:Haiku:$label:chain"
4402354704SAlexander G. M. Smith	exit 0
4502354704SAlexander G. M. Smithelse
46*c09821c0SAlexander G. M. Smith	debug "Haiku stage 2 bootloader and kernel not found: exiting"
4702354704SAlexander G. M. Smith	exit 1
4802354704SAlexander G. M. Smithfi
49