Skip to content

Commit

Permalink
sdfdsf
Browse files Browse the repository at this point in the history
  • Loading branch information
say-paul committed Aug 9, 2024
1 parent 6807ec5 commit b57ba40
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
23 changes: 12 additions & 11 deletions usr/libexec/greenboot/greenboot-grub2-set-counter
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/bin/bash
set -eo pipefail

function remount_boot_ro {
if grep -q " /boot .* rw," /proc/mounts; then
mount -o remount,ro /boot || exit 5
fi
return
}

GREENBOOT_CONFIGURATION_FILE=/etc/greenboot/greenboot.conf
if test -f "$GREENBOOT_CONFIGURATION_FILE"; then
# shellcheck source=etc/greenboot/greenboot.conf
Expand All @@ -17,28 +24,22 @@ fi

# Remount /boot as read-only if it was mounted as read-write
if grep -q " /boot .* rw," /proc/mounts; then
mount -o remount,ro /boot || exit 1
mount -o remount,ro /boot || exit 5
fi

if ! /usr/bin/grub2-editenv - set boot_counter="$max_boot_attempts"; then
# If the first command fails, remount /boot as read-only and exit with failure
if grep -q " /boot .* rw," /proc/mounts; then
mount -o remount,ro /boot || exit 1
fi
remount_boot_ro
exit 1
fi

if ! /usr/bin/grub2-editenv /boot/grub2/grubenv set boot_success=0; then
# If the first command fails, remount /boot as read-only and exit with failure
if grep -q " /boot .* rw," /proc/mounts; then
mount -o remount,ro /boot || exit 1
fi
remount_boot_ro
exit 1
fi

# Remount /boot as read-only if it was mounted as read-write
if grep -q " /boot .* rw," /proc/mounts; then
mount -o remount,ro /boot || exit 1
fi
# Revert /boot as read-only
remount_boot_ro

echo "<3>GRUB2 environment variables have been set for system upgrade. Max boot attempts is $max_boot_attempts"
4 changes: 2 additions & 2 deletions usr/libexec/greenboot/greenboot-grub2-set-success
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ set -eo pipefail

function remount_boot_ro {
if grep -q " /boot .* rw," /proc/mounts; then
mount -o remount,ro /boot || exit 1
mount -o remount,ro /boot || exit 5
fi
return
}

# Check if /boot is mounted as read-only, and remount as read-write if necessary
if grep -q " /boot .* ro," /proc/mounts; then
mount -o remount,rw /boot || exit 1
mount -o remount,rw /boot || exit 5
fi

# Run the grub2-editenv commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -euo pipefail

function remount_boot_ro {
if grep -q " /boot .* rw," /proc/mounts; then
mount -o remount,ro /boot || exit 1
mount -o remount,ro /boot || exit 5
fi
return
}
Expand All @@ -23,7 +23,7 @@ if grub2-editenv list | grep -q "^boot_counter=-1$"; then

# Check if /boot is mounted as read-only, and remount as read-write if necessary
if grep -q " /boot .* ro," /proc/mounts; then
mount -o remount,rw /boot || exit 1
mount -o remount,rw /boot || exit 5
fi

if ! /usr/bin/grub2-editenv - unset boot_counter; then
Expand Down

0 comments on commit b57ba40

Please sign in to comment.