#!/usr/bin/bash
set -Eeuo pipefail

esp=${1:-/boot/efi}
template=/usr/share/nabu/bootloader/refind/refind-nabu.conf
target="$esp/EFI/refind/refind-nabu.conf"

[[ $EUID -eq 0 ]] || { echo 'Run as root.' >&2; exit 1; }
findmnt --mountpoint "$esp" >/dev/null || { echo "ESP is not mounted at $esp." >&2; exit 1; }
[[ -d $esp/EFI/refind ]] || { echo 'rEFInd is not installed on this ESP.' >&2; exit 1; }

install -Dm0644 "$template" "$target"
echo "Created $target. Add 'include refind-nabu.conf' to refind.conf after verifying the Android EFI entry."
