commit:     375261ca73010b5c3d094f1c7d44baacd9edd9ae
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Tue Jan 12 12:28:50 2021 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sat Jan 16 09:53:00 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=375261ca

mount-boot.eclass: Support nonfatal

Support making mount-boot_check_status() nonfatal.  This is useful
to amend the error message with additional instructions.

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 eclass/mount-boot.eclass | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/eclass/mount-boot.eclass b/eclass/mount-boot.eclass
index 2874f9aae11..8f59822db68 100644
--- a/eclass/mount-boot.eclass
+++ b/eclass/mount-boot.eclass
@@ -49,10 +49,11 @@ 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" 
\
@@ -60,7 +61,7 @@ mount-boot_check_status() {
 
        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, ","); \
@@ -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() {

Reply via email to