vapier      15/07/30 07:16:19

  Modified:             mount-boot.eclass
  Log:
  add support for pkg_pretend and split apart the testing/message logic from 
the actual mount logic so we can provide better details up front #532264 by 
Ulrich Müller

Revision  Changes    Path
1.23                 eclass/mount-boot.eclass

file : 
http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/mount-boot.eclass?rev=1.23&view=markup
plain: 
http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/mount-boot.eclass?rev=1.23&content-type=text/plain
diff : 
http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/mount-boot.eclass?r1=1.22&r2=1.23

Index: mount-boot.eclass
===================================================================
RCS file: /var/cvsroot/gentoo-x86/eclass/mount-boot.eclass,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- mount-boot.eclass   30 Jul 2015 07:14:49 -0000      1.22
+++ mount-boot.eclass   30 Jul 2015 07:16:19 -0000      1.23
@@ -1,6 +1,6 @@
 # Copyright 1999-2015 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/mount-boot.eclass,v 1.22 2015/07/30 
07:14:49 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/mount-boot.eclass,v 1.23 2015/07/30 
07:16:19 vapier Exp $
 
 # @ECLASS: mount-boot.eclass
 # @MAINTAINER:
@@ -13,7 +13,7 @@
 # function tries to ensure that it's mounted in rw mode, exiting with an
 # error if it can't. It does nothing if /boot isn't a separate partition.
 
-EXPORT_FUNCTIONS pkg_preinst pkg_postinst pkg_prerm pkg_postrm
+EXPORT_FUNCTIONS pkg_pretend pkg_preinst pkg_postinst pkg_prerm pkg_postrm
 
 # @FUNCTION: mount-boot_disabled
 # @INTERNAL
@@ -40,41 +40,73 @@
        return 1
 }
 
-mount-boot_mount_boot_partition() {
+# @FUNCTION: mount-boot_check_status
+# @INTERNAL
+# @DESCRIPTION:
+# Figure out what kind of work we need to do in order to have /boot be sane.
+# Return values are:
+# 0 - Do nothing at all!
+# 1 - It's mounted, but is currently ro, so need to remount rw.
+# 2 - It's not mounted, so need to mount it rw.
+mount-boot_check_status() {
        # Get out fast if possible.
        mount-boot_is_disabled && return 0
 
-       elog "To avoid automounting and auto(un)installing with /boot,"
-       elog "just export the DONT_MOUNT_BOOT variable."
-
        # note that /dev/BOOT is in the Gentoo default /etc/fstab file
        local fstabstate=$(awk '!/^#|^[[:blank:]]+#|^\/dev\/BOOT/ {print $2}' 
/etc/fstab | egrep "^/boot$" )
        local procstate=$(awk '$2 ~ /^\/boot$/ {print $2}' /proc/mounts)
        local proc_ro=$(awk '{ print $2 " ," $4 "," }' /proc/mounts | sed -n 
'/\/boot .*,ro,/p')
 
-       if [ -n "${fstabstate}" ] && [ -n "${procstate}" ]; then
-               if [ -n "${proc_ro}" ]; then
+       if [ -n "${fstabstate}" ] && [ -n "${procstate}" ] ; then
+               if [ -n "${proc_ro}" ] ; then
                        echo
                        einfo "Your boot partition, detected as being mounted 
at /boot, is read-only."
                        einfo "It will be remounted in read-write mode 
temporarily."
-                       mount -o remount,rw /boot
-                       if [ "$?" -ne 0 ]; then
-                               echo
-                               eerror "Unable to remount in rw mode. Please do 
it manually!"
-                               die "Can't remount in rw mode. Please do it 
manually!"
-                       fi
-                       touch /boot/.e.remount
+                       return 1
                else
                        echo
                        einfo "Your boot partition was detected as being 
mounted at /boot."
                        einfo "Files will be installed there for ${PN} to 
function correctly."
+                       return 0
                fi
-       elif [ -n "${fstabstate}" ] && [ -z "${procstate}" ]; then
+       elif [ -n "${fstabstate}" ] && [ -z "${procstate}" ] ; then
                echo
                einfo "Your boot partition was not mounted at /boot, so it will 
be automounted for you."
                einfo "Files will be installed there for ${PN} to function 
correctly."
+               return 2
+       else
+               echo
+               einfo "Assuming you do not have a separate /boot partition."
+               return 0
+       fi
+}
+
+mount-boot_pkg_pretend() {
+       # Get out fast if possible.
+       mount-boot_is_disabled && return 0
+
+       elog "To avoid automounting and auto(un)installing with /boot,"
+       elog "just export the DONT_MOUNT_BOOT variable."
+       mount-boot_check_status
+}
+
+mount-boot_mount_boot_partition() {
+       mount-boot_check_status
+       case $? in
+       0)      # Nothing to do.
+               ;;
+       1)      # Remount it rw.
+               mount -o remount,rw /boot
+               if [ $? -ne 0 ] ; then
+                       echo
+                       eerror "Unable to remount in rw mode. Please do it 
manually!"
+                       die "Can't remount in rw mode. Please do it manually!"
+               fi
+               touch /boot/.e.remount
+               ;;
+       2)      # Mount it rw.
                mount /boot -o rw
-               if [ "$?" -ne 0 ]; then
+               if [ $? -ne 0 ] ; then
                        echo
                        eerror "Cannot automatically mount your /boot 
partition."
                        eerror "Your boot partition has to be mounted rw before 
the installation"
@@ -82,13 +114,16 @@
                        die "Please mount your /boot partition manually!"
                fi
                touch /boot/.e.mount
-       else
-               echo
-               einfo "Assuming you do not have a separate /boot partition."
-       fi
+               ;;
+       esac
 }
 
 mount-boot_pkg_preinst() {
+       # Handle older EAPIs.
+       case ${EAPI:-0} in
+       [0-3]) mount-boot_pkg_pretend ;;
+       esac
+
        mount-boot_mount_boot_partition
 }
 




Reply via email to