Merge pull request #3300 from travier/main-static-config-null

bootloader/grub2: Handle empty static configs
This commit is contained in:
Colin Walters 2024-09-15 13:01:52 -04:00 committed by GitHub
commit 558f260554
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View File

@ -30,6 +30,7 @@
#define BOOTUPD_CONFIG "boot/bootupd-state.json" #define BOOTUPD_CONFIG "boot/bootupd-state.json"
// Horrible hack, to avoid including a JSON parser we just grep for this // Horrible hack, to avoid including a JSON parser we just grep for this
#define BOOTUPD_CONFIG_STATIC_JSON_FRAGMENT "\"static-configs\"" #define BOOTUPD_CONFIG_STATIC_JSON_FRAGMENT "\"static-configs\""
#define BOOTUPD_CONFIG_STATIC_JSON_FRAGMENT_NULL "\"static-configs\":null"
/* Maintain backwards compatibility with legacy GRUB /* Maintain backwards compatibility with legacy GRUB
* installations that might rely on the -16 suffix * installations that might rely on the -16 suffix
@ -89,12 +90,15 @@ _ostree_bootloader_grub2_query (OstreeBootloader *bootloader, gboolean *out_is_a
error)) error))
return glnx_prefix_error (error, "Failed to read bootupd config"); return glnx_prefix_error (error, "Failed to read bootupd config");
if (strstr (bootupd_config_contents, BOOTUPD_CONFIG_STATIC_JSON_FRAGMENT) != NULL) if (strstr (bootupd_config_contents, BOOTUPD_CONFIG_STATIC_JSON_FRAGMENT) != NULL)
{
if (strstr (bootupd_config_contents, BOOTUPD_CONFIG_STATIC_JSON_FRAGMENT_NULL) == NULL)
{ {
g_debug ("Found static bootupd config"); g_debug ("Found static bootupd config");
*out_is_active = FALSE; *out_is_active = FALSE;
return TRUE; return TRUE;
} }
} }
}
/* Look for the BIOS path first */ /* Look for the BIOS path first */
if (g_file_query_exists (self->config_path_bios_1, NULL) if (g_file_query_exists (self->config_path_bios_1, NULL)

View File

@ -10,7 +10,7 @@ bootupd_state=/boot/bootupd-state.json
mount -o remount,rw /boot mount -o remount,rw /boot
if grep -qFe "\"static-configs\"" "${bootupd_state}"; then if grep -qFe "\"static-configs\"" "${bootupd_state}"; then
echo "Host is using static configs already, overriding this" echo "Host is using static configs already, overriding this"
jq 'del(.["static-configs"])' < "${bootupd_state}" > "${bootupd_state}".new jq --compact-output '.["static-configs"] = null' < "${bootupd_state}" > "${bootupd_state}".new
mv "${bootupd_state}.new" "${bootupd_state}" mv "${bootupd_state}.new" "${bootupd_state}"
fi fi