Add guards for $EFI_CODE and $EFI_VARS

Make sure that $EFI_VARS references an actual writable file.

Check if $EFI_CODE reference a symlink, if so resolve the the real file.
This commit is contained in:
Martin Wimpress 2021-10-19 23:39:44 +01:00
parent ca03a4dada
commit 44673e94c6
No known key found for this signature in database
GPG Key ID: 61DF940515E06DA3

View File

@ -381,7 +381,6 @@ function vm_boot() {
echo " Please install OVMF firmware."
exit 1
fi
BOOT_STATUS="EFI (${guest_os^}), OVMF ($(basename "${EFI_CODE}")), SecureBoot (${secureboot})."
;;
*)
if [ -e "/usr/share/OVMF/OVMF_CODE_4M.fd" ]; then
@ -398,9 +397,26 @@ function vm_boot() {
echo " Please install OVMF firmware."
exit 1
fi
BOOT_STATUS="EFI (${guest_os^}), OVMF ($(basename "${EFI_CODE}")), SecureBoot (${secureboot})."
;;
esac
# Make sure EFI_VARS references an actual, writeable, file
if [ ! -f "${EFI_VARS}" ] || [ ! -w "${EFI_VARS}" ]; then
echo " - EFI: ERROR! ${EFI_VARS} is not a regular file or not writeable."
echo " Deleting ${EFI_VARS}. Please re-run quickemu."
rm -f "${EFI_VARS}"
exit 1
fi
# If EFI firmware path is a symlink, resolve it to a real file.
#if [ -L "${EFI_CODE}" ]; then
if true; then
echo " - EFI: WARNING! ${EFI_CODE} is a symlink."
echo -n " Resolving to... "
EFI_CODE=$(realpath "${EFI_CODE}")
echo "${EFI_CODE}"
fi
BOOT_STATUS="EFI (${guest_os^}), OVMF ($(basename "${EFI_CODE}")), SecureBoot (${secureboot})."
else
BOOT_STATUS="Legacy BIOS (${guest_os^})"
secureboot="off"