xref: /haiku/3rdparty/os_probe/83haiku (revision 268f99dd7dc4bd7474a8bd2742d3f1ec1de6752a)
1*610f99c8SAlexander G. M. Smith#!/bin/sh
20b057a90SAlexander G. M. Smith# Detects bootable Haiku OS on BeFS partitions and FUSE mounted BeFS too.
30b057a90SAlexander G. M. Smith# If it doesn't find anything, try mounting the BeFS volumes in Linux.
40b057a90SAlexander G. M. Smith# Discussion of improvements and development history at
50b057a90SAlexander G. M. Smith# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=732696
60b057a90SAlexander G. M. Smith# Adapted from version 42 (dated 20150811) updated by Jeroen Oortwijn at
70b057a90SAlexander G. M. Smith# https://bazaar.launchpad.net/~idefix/ubuntu/trusty/os-prober/HaikuPM/files/head:/os-probes/mounted/x86
80b057a90SAlexander G. M. Smith# Latest version now at https://git.haiku-os.org/haiku/tree/3rdparty/os_probe
902354704SAlexander G. M. Smith
1002354704SAlexander G. M. Smith. /usr/share/os-prober/common.sh
1102354704SAlexander G. M. Smith
1202354704SAlexander G. M. Smithpartition="$1"
1302354704SAlexander G. M. Smithmpoint="$2"
1402354704SAlexander G. M. Smithtype="$3"
1502354704SAlexander G. M. Smith
160b057a90SAlexander G. M. Smith# Weed out stuff that doesn't apply to us, needs to be a Be file system.
1702354704SAlexander G. M. Smithcase "$type" in
180b057a90SAlexander G. M. Smith	bfs|befs) debug "$partition is a BeFS partition." ;;
190b057a90SAlexander G. M. Smith	fuse|fuseblk) debug "$partition is a FUSE partition, maybe with BeFS on it." ; mpoint="$mpoint/myfs" ;;
200b057a90SAlexander G. M. Smith	*) exit 1 ;; # Be quiet and just quit for irrelevant partitions.
2102354704SAlexander G. M. Smithesac
2202354704SAlexander G. M. Smith
23c09821c0SAlexander G. M. Smithif head -c 512 "$partition" | grep -qs "haiku_loader"; then
240b057a90SAlexander G. M. Smith	debug "Haiku stage 1 bootloader found."
2502354704SAlexander G. M. Smithelse
26c09821c0SAlexander G. M. Smith	debug "Haiku stage 1 bootloader not found: exiting"
2702354704SAlexander G. M. Smith	exit 1
2802354704SAlexander G. M. Smithfi
2902354704SAlexander G. M. Smith
30c09821c0SAlexander G. M. Smithif system="$(item_in_dir "system" "$mpoint")" &&
31c09821c0SAlexander G. M. Smith	packages="$(item_in_dir "packages" "$mpoint/$system")" &&
320b057a90SAlexander G. M. Smith		item_in_dir -q "haiku_loader-r[0-9].*\.hpkg" "$mpoint/$system/$packages" &&
330b057a90SAlexander G. M. Smith		rev="$(item_in_dir "haiku-r[0-9].*\.hpkg" "$mpoint/$system/$packages")"
34c09821c0SAlexander G. M. Smiththen
350b057a90SAlexander G. M. Smith	debug "Haiku Package Manager stage 2 bootloader and kernel ($rev) found."
36c09821c0SAlexander G. M. Smith	label="$(count_next_label Haiku)"
370b057a90SAlexander G. M. Smith	# Convert kernel file name like haiku-r1~beta3_hrev55181_56-1-x86_64.hpkg
380b057a90SAlexander G. M. Smith	# or haiku-r1~alpha4_pm_hrev49856-1-x86_gcc2.hpkg into a readable version,
390b057a90SAlexander G. M. Smith	# like "Haiku R1 beta3 (hrev55181_56) 64".  Seems to use a travelling space
400b057a90SAlexander G. M. Smith	# technique in the sed stream editor.
410b057a90SAlexander 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/) [^_]\+_\([a-z0-9]\+\)\.hpkg/) \1 /;s/[^ ]\+.hpkg//;s/ $//')"
42c09821c0SAlexander G. M. Smith	long="Haiku $rev"
43c09821c0SAlexander G. M. Smith	result "$partition:$long:$label:chain"
44c09821c0SAlexander G. M. Smith	exit 0
45c09821c0SAlexander G. M. Smithelif system="$(item_in_dir "system" "$mpoint")" &&
4602354704SAlexander G. M. Smith	item_in_dir -q "haiku_loader" "$mpoint/$system" &&
47c09821c0SAlexander G. M. Smith	item_in_dir -q "kernel_.*" "$mpoint/$system"
4802354704SAlexander G. M. Smiththen
490b057a90SAlexander G. M. Smith	debug "Older non-package manager Haiku stage 2 bootloader and kernel found."
5002354704SAlexander G. M. Smith	label="$(count_next_label Haiku)"
5102354704SAlexander G. M. Smith	result "$partition:Haiku:$label:chain"
5202354704SAlexander G. M. Smith	exit 0
5302354704SAlexander G. M. Smithelse
54c09821c0SAlexander G. M. Smith	debug "Haiku stage 2 bootloader and kernel not found: exiting"
5502354704SAlexander G. M. Smith	exit 1
5602354704SAlexander G. M. Smithfi
57