From 396e27cfe3356408782c648cf7dd1542b4e27754 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Thu, 26 Oct 2023 03:30:16 +0200 Subject: [PATCH] refactor(script): Comment steps --- pacman-zbm-syslinux-regen.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pacman-zbm-syslinux-regen.sh b/pacman-zbm-syslinux-regen.sh index 0c95df8..75a0c8b 100644 --- a/pacman-zbm-syslinux-regen.sh +++ b/pacman-zbm-syslinux-regen.sh @@ -2,6 +2,8 @@ boot_dir='/boot/syslinux' boot_dir="${boot_dir%/}" + +# Returns e.g. '/dev/sda1' boot_fs="$(findmnt --noheadings --target "${boot_dir}" --output 'SOURCE')" || { printf -- '%s\n' \ 'Unable to identify boot drive for '"'${boot_dir}'"' boot dir.' \ @@ -15,14 +17,20 @@ if [[ "$(<<<"${boot_fs}" wc -l)" -gt '1' ]]; then exit 1 fi +# Returns e.g. 'sda1'. This is the format used when traversing through lsblk +# JSON output. boot_fs_name="$(basename "${boot_fs}")" + +# May return e.g. 'sda' if "${boot_fs}" has a parent. boot_disk="$(lsblk --output 'NAME' --json --tree | jq --raw-output '.[][] | select(.children | length > 0) | select(.children[].name=="'"${boot_fs_name}"'") | .name')" if [[ ! "${boot_disk}" ]]; then # There's no parent drive over "${boot_fs}" meaning "${boot_fs}" itself # already is the parent. This is a file system on a drive and not on a - # partition. + # partition. We stick to the long-form device name, e.g. '/dev/sda1'. boot_disk="${boot_fs}" else + # We found a parent, e.g. 'sda'. In order to work with commands below + # we'll prefix it with '/dev/'. boot_disk='/dev/'"${boot_disk}" fi