Files
configure-stormux/.includes/eeprom.sh
2025-12-20 05:31:16 -05:00

78 lines
2.7 KiB
Bash

#!/usr/bin/env bash
# EEPROM Update for Raspberry Pi 4/400/5/500
# Checks for and applies firmware updates to the Pi's EEPROM
# sudoFlags is defined in the main configure-stormux.sh script
# shellcheck disable=SC2154
updateEeprom() {
# Detect Pi version from device tree
local piModel
piModel=$(cat /sys/firmware/devicetree/base/model 2>/dev/null)
# Determine which EEPROM package is needed
local eepromPackage=""
if [[ "$piModel" == *"Raspberry Pi 5"* ]] || [[ "$piModel" == *"Raspberry Pi 500"* ]]; then
eepromPackage="rpi5-eeprom"
elif [[ "$piModel" == *"Raspberry Pi 4"* ]] || [[ "$piModel" == *"Raspberry Pi 400"* ]]; then
eepromPackage="rpi4-eeprom"
else
# Default to rpi4-eeprom for unknown models
eepromPackage="rpi4-eeprom"
fi
# Install EEPROM package if not present
if ! pacman -Q "$eepromPackage" &> /dev/null; then
infobox "Installing ${eepromPackage}..."
if ! install_package "$eepromPackage"; then
msgbox "Failed to install ${eepromPackage}. Please check your internet connection and try again."
return 1
fi
fi
# Check for EEPROM updates
infobox "Checking for EEPROM updates..."
local checkOutput
local checkResult
checkOutput=$(sudo "${sudoFlags[@]}" rpi-eeprom-update 2>&1)
checkResult=$?
case $checkResult in
0)
# Up to date
msgbox "EEPROM is up to date.\n\n${checkOutput}"
;;
1)
# Update available
if [[ "$(yesno "An EEPROM update is available.\n\n${checkOutput}\n\nWould you like to apply this update?")" == "Yes" ]]; then
infobox "Applying EEPROM update..."
if sudo "${sudoFlags[@]}" rpi-eeprom-update -a; then
msgbox "EEPROM update applied successfully. A reboot is required to complete the update."
restart
else
msgbox "Failed to apply EEPROM update. Please try again or check the log file for details."
return 1
fi
fi
;;
2)
# Failed
msgbox "EEPROM update check failed.\n\n${checkOutput}"
return 1
;;
3)
# EEPROM frozen
msgbox "EEPROM is currently frozen and cannot be updated.\n\n${checkOutput}\n\nThis may require a reboot to resolve."
return 1
;;
*)
# Unknown error
msgbox "Unexpected error checking EEPROM status (exit code: ${checkResult}).\n\n${checkOutput}"
return 1
;;
esac
}
# Execute the update function when sourced
updateEeprom