Skip to content

Commit

Permalink
mount-boot.eclass: Support nonfatal
Browse files Browse the repository at this point in the history
Support making mount-boot_check_status() nonfatal.  This is useful
to amend the error message with additional instructions.

Signed-off-by: Michał Górny <[email protected]>
  • Loading branch information
mgorny committed Jan 16, 2021
1 parent b018602 commit 375261c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions eclass/mount-boot.eclass
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ mount-boot_is_disabled() {
# @INTERNAL
# @DESCRIPTION:
# Check if /boot is sane, i.e., mounted as read-write if on a separate
# partition. Die if conditions are not fulfilled.
# partition. Die if conditions are not fulfilled. If nonfatal is used,
# the function will return a non-zero status instead.
mount-boot_check_status() {
# Get out fast if possible.
mount-boot_is_disabled && return
mount-boot_is_disabled && return 0

# note that /dev/BOOT is in the Gentoo default /etc/fstab file
local fstabstate=$(awk '!/^[[:blank:]]*#|^\/dev\/BOOT/ && $2 == "/boot" \
{ print 1; exit }' /etc/fstab || die "awk failed")

if [[ -z ${fstabstate} ]] ; then
einfo "Assuming you do not have a separate /boot partition."
return
return 0
fi

local procstate=$(awk '$2 == "/boot" { split($4, a, ","); \
Expand All @@ -70,18 +71,21 @@ mount-boot_check_status() {
if [[ -z ${procstate} ]] ; then
eerror "Your boot partition is not mounted at /boot."
eerror "Please mount it and retry."
die "/boot not mounted"
die -n "/boot not mounted"
return 1
fi

if [[ ${procstate} == ro ]] ; then
eerror "Your boot partition, detected as being mounted at /boot," \
"is read-only."
eerror "Please remount it as read-write and retry."
die "/boot mounted read-only"
die -n "/boot mounted read-only"
return 2
fi

einfo "Your boot partition was detected as being mounted at /boot."
einfo "Files will be installed there for ${PN} to function correctly."
return 0
}

mount-boot_pkg_pretend() {
Expand Down

0 comments on commit 375261c

Please sign in to comment.