96 lines
2.5 KiB
Bash
96 lines
2.5 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
RECOVERY_DIR="/boot/bastionguard-recovery"
|
|
LIVE_DIR="$RECOVERY_DIR/live"
|
|
|
|
SQUASHFS="$LIVE_DIR/filesystem.squashfs"
|
|
VMLINUZ="$RECOVERY_DIR/vmlinuz"
|
|
INITRD="$RECOVERY_DIR/initrd.img"
|
|
|
|
# Non generare nulla se i file recovery non esistono
|
|
[ -f "$SQUASHFS" ] || exit 0
|
|
[ -f "$VMLINUZ" ] || exit 0
|
|
[ -f "$INITRD" ] || exit 0
|
|
|
|
find_uuid() {
|
|
findmnt -n -o UUID "$1" 2>/dev/null || true
|
|
}
|
|
|
|
# Determina dove si trova davvero bastionguard-recovery
|
|
if mountpoint -q /boot 2>/dev/null; then
|
|
BOOT_UUID="$(find_uuid /boot)"
|
|
ROOT_UUID=""
|
|
VMLINUZ_REL="/bastionguard-recovery/vmlinuz"
|
|
INITRD_REL="/bastionguard-recovery/initrd.img"
|
|
LIVE_MEDIA_PATH="/bastionguard-recovery/live"
|
|
else
|
|
BOOT_UUID=""
|
|
ROOT_UUID="$(find_uuid /)"
|
|
VMLINUZ_REL="/boot/bastionguard-recovery/vmlinuz"
|
|
INITRD_REL="/boot/bastionguard-recovery/initrd.img"
|
|
LIVE_MEDIA_PATH="/boot/bastionguard-recovery/live"
|
|
fi
|
|
|
|
# Se non riusciamo a trovare nessun UUID, meglio non generare una entry rotta
|
|
if [ -z "${BOOT_UUID}" ] && [ -z "${ROOT_UUID}" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
if [ -n "${BOOT_UUID}" ]; then
|
|
SEARCH_CMD="search --no-floppy --fs-uuid --set=root ${BOOT_UUID}"
|
|
else
|
|
SEARCH_CMD="search --no-floppy --fs-uuid --set=root ${ROOT_UUID}"
|
|
fi
|
|
|
|
COMMON_PARAMS="boot=live live-media-path=${LIVE_MEDIA_PATH} hostname=bastionguard-recovery username=root noeject noswap bastionguard.recovery=1 console=tty1"
|
|
|
|
cat <<EOF
|
|
menuentry "BastionGuard Recovery" --class bastionguard --class gnu-linux --class gnu --class os {
|
|
load_video
|
|
insmod gzio
|
|
insmod part_gpt
|
|
insmod part_msdos
|
|
insmod ext2
|
|
insmod all_video
|
|
|
|
${SEARCH_CMD}
|
|
|
|
echo "Avvio BastionGuard Recovery..."
|
|
|
|
linux ${VMLINUZ_REL} ${COMMON_PARAMS} quiet splash
|
|
initrd ${INITRD_REL}
|
|
}
|
|
|
|
menuentry "BastionGuard Recovery (debug)" --class bastionguard --class gnu-linux --class gnu --class os {
|
|
load_video
|
|
insmod gzio
|
|
insmod part_gpt
|
|
insmod part_msdos
|
|
insmod ext2
|
|
insmod all_video
|
|
|
|
${SEARCH_CMD}
|
|
|
|
echo "Avvio BastionGuard Recovery (debug)..."
|
|
|
|
linux ${VMLINUZ_REL} ${COMMON_PARAMS}
|
|
initrd ${INITRD_REL}
|
|
}
|
|
|
|
menuentry "BastionGuard Recovery (bassa RAM)" --class bastionguard --class gnu-linux --class gnu --class os {
|
|
load_video
|
|
insmod gzio
|
|
insmod part_gpt
|
|
insmod part_msdos
|
|
insmod ext2
|
|
insmod all_video
|
|
|
|
${SEARCH_CMD}
|
|
|
|
echo "Avvio BastionGuard Recovery (bassa RAM)..."
|
|
|
|
linux ${VMLINUZ_REL} ${COMMON_PARAMS} quiet
|
|
initrd ${INITRD_REL}
|
|
}
|
|
EOF
|