haiku/3rdparty/os_probe/83haiku
Alexander G. M. Smith 0b057a903f 3rdparty/os_probe: Better wording, fix Beta+ version parsing.
Add lots of comments explaining things in the code.  Also fix parsing
of Beta updates which have hrev version numbers with an extra bit at
the end, like hrev12345_67.  Include architecture in the GRUB menu
title, so you can tell 32 bit and 64 bit installs apart.  Switch
back to #!/usr/bin/sh, like all the other probes do.

Change-Id: Id47afe5029369c739d5177b1dd917c7d1d631ad6
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4498
Reviewed-by: Alexander G. M. Smith <agmsmith@ncf.ca>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
2021-10-05 16:07:01 +00:00

57 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/sh
# Detects bootable Haiku OS on BeFS partitions and FUSE mounted BeFS too.
# If it doesn't find anything, try mounting the BeFS volumes in Linux.
# Discussion of improvements and development history at
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=732696
# Adapted 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
# Latest version now at https://git.haiku-os.org/haiku/tree/3rdparty/os_probe
. /usr/share/os-prober/common.sh
partition="$1"
mpoint="$2"
type="$3"
# Weed out stuff that doesn't apply to us, needs to be a Be file system.
case "$type" in
bfs|befs) debug "$partition is a BeFS partition." ;;
fuse|fuseblk) debug "$partition is a FUSE partition, maybe with BeFS on it." ; mpoint="$mpoint/myfs" ;;
*) exit 1 ;; # Be quiet and just quit for irrelevant partitions.
esac
if head -c 512 "$partition" | grep -qs "haiku_loader"; then
debug "Haiku stage 1 bootloader found."
else
debug "Haiku stage 1 bootloader not found: exiting"
exit 1
fi
if system="$(item_in_dir "system" "$mpoint")" &&
packages="$(item_in_dir "packages" "$mpoint/$system")" &&
item_in_dir -q "haiku_loader-r[0-9].*\.hpkg" "$mpoint/$system/$packages" &&
rev="$(item_in_dir "haiku-r[0-9].*\.hpkg" "$mpoint/$system/$packages")"
then
debug "Haiku Package Manager stage 2 bootloader and kernel ($rev) found."
label="$(count_next_label Haiku)"
# Convert kernel file name like haiku-r1~beta3_hrev55181_56-1-x86_64.hpkg
# or haiku-r1~alpha4_pm_hrev49856-1-x86_gcc2.hpkg into a readable version,
# like "Haiku R1 beta3 (hrev55181_56) 64". Seems to use a travelling space
# technique in the sed stream editor.
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/ $//')"
long="Haiku $rev"
result "$partition:$long:$label:chain"
exit 0
elif system="$(item_in_dir "system" "$mpoint")" &&
item_in_dir -q "haiku_loader" "$mpoint/$system" &&
item_in_dir -q "kernel_.*" "$mpoint/$system"
then
debug "Older non-package manager Haiku stage 2 bootloader and kernel found."
label="$(count_next_label Haiku)"
result "$partition:Haiku:$label:chain"
exit 0
else
debug "Haiku stage 2 bootloader and kernel not found: exiting"
exit 1
fi