Skip to content

Commit

Permalink
move boot mount scripts to seperate file
Browse files Browse the repository at this point in the history
Signed-off-by: saypaul <[email protected]>
  • Loading branch information
say-paul committed Aug 16, 2024
1 parent b7ebeb2 commit 83ecd7d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 46 deletions.
1 change: 1 addition & 0 deletions greenboot.spec
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ install -DpZm 0644 etc/greenboot/greenboot.conf %{buildroot}%{_sysconfdir}/%{nam
%{_unitdir}/greenboot-status.service
%{_libexecdir}/%{name}/greenboot-grub2-set-counter
%{_libexecdir}/%{name}/greenboot-grub2-set-success
%{_libexecdir}/%{name}/greenboot-boot-remount.sh
%{_unitdir}/greenboot-grub2-set-success.service
%{_unitdir}/greenboot-grub2-set-counter.service
%{_libexecdir}/%{name}/greenboot-rpm-ostree-grub2-check-fallback
Expand Down
23 changes: 23 additions & 0 deletions usr/libexec/greenboot/greenboot-boot-remount.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -eo pipefail

# Boolean variable to track if /boot was initially mounted as read-only
# Ensure compatibility with rpm-ostree where /boot is rw but in bootc /boot is ro
boot_was_ro=false

# Remount /boot as read-only if it was mounted as read-only ealier
function remount_boot_ro {
if $boot_was_ro; then
mount -o remount,ro /boot || exit 13
fi
return
}

# Remount /boot as read-write if it was mounted as read-only
function remount_boot_rw {
if grep -q " /boot .* ro," /proc/mounts; then
mount -o remount,rw /boot || exit 13
boot_was_ro=true
fi
return
}
17 changes: 2 additions & 15 deletions usr/libexec/greenboot/greenboot-grub2-set-counter
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#!/bin/bash
set -eo pipefail

# Boolean variable to track if /boot was initially mounted as read-only
# Ensure compatibility with rpm-ostree where /boot is rw but in bootc /boot is ro
boot_was_ro=false

function remount_boot_ro {
if $boot_was_ro; then
mount -o remount,ro /boot || exit 13
fi
return
}

GREENBOOT_CONFIGURATION_FILE=/etc/greenboot/greenboot.conf
if test -f "$GREENBOOT_CONFIGURATION_FILE"; then
Expand All @@ -26,11 +16,8 @@ else
max_boot_attempts=3 # default to 3 attempts
fi

# Remount /boot as read-write if it was mounted as read-only
if grep -q " /boot .* ro," /proc/mounts; then
mount -o remount,rw /boot || exit 13
boot_was_ro=true
fi
source /usr/libexec/greenboot/greenboot-boot-remount.sh
remount_boot_rw

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
Expand Down
18 changes: 2 additions & 16 deletions usr/libexec/greenboot/greenboot-grub2-set-success
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,8 @@

set -eo pipefail

# Boolean variable to track if /boot was initially mounted as read-only
# Ensure compatibility with rpm-ostree where /boot is rw but in bootc /boot is ro
boot_was_ro=false

function remount_boot_ro {
if $boot_was_ro; then
mount -o remount,ro /boot || exit 13
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 13
boot_was_ro=true
fi
source /usr/libexec/greenboot/greenboot-boot-remount.sh
remount_boot_rw

# Run the grub2-editenv commands
if ! /usr/bin/grub2-editenv /boot/grub2/grubenv set boot_success=1; then
Expand Down
17 changes: 2 additions & 15 deletions usr/libexec/greenboot/greenboot-rpm-ostree-grub2-check-fallback
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#!/bin/bash
set -euo pipefail

# Boolean variable to track if /boot was initially mounted as read-only
# Ensure compatibility with rpm-ostree where /boot is rw but in bootc /boot is ro
boot_was_ro=false

function remount_boot_ro {
if $boot_was_ro; then
mount -o remount,ro /boot || exit 13
fi
return
}

function attempt_rollback {
# Check if the bootc command is available
Expand Down Expand Up @@ -44,11 +34,8 @@ if grub2-editenv list | grep -q "^boot_counter=-1$"; then
fi


# 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 13
boot_was_ro=true
fi
source /usr/libexec/greenboot/greenboot-boot-remount.sh
remount_boot_rw

if ! /usr/bin/grub2-editenv - unset boot_counter; then
# If the above command fails, remount /boot as read-only and exit with failure
Expand Down

0 comments on commit 83ecd7d

Please sign in to comment.