Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in eclass: mount-boot.eclass
Date: Thu, 30 Jul 2015 07:16:30
Message-Id: 20150730071619.D2F7A111@oystercatcher.gentoo.org
1 vapier 15/07/30 07:16:19
2
3 Modified: mount-boot.eclass
4 Log:
5 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
6
7 Revision Changes Path
8 1.23 eclass/mount-boot.eclass
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/mount-boot.eclass?rev=1.23&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/mount-boot.eclass?rev=1.23&content-type=text/plain
12 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/mount-boot.eclass?r1=1.22&r2=1.23
13
14 Index: mount-boot.eclass
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-x86/eclass/mount-boot.eclass,v
17 retrieving revision 1.22
18 retrieving revision 1.23
19 diff -u -r1.22 -r1.23
20 --- mount-boot.eclass 30 Jul 2015 07:14:49 -0000 1.22
21 +++ mount-boot.eclass 30 Jul 2015 07:16:19 -0000 1.23
22 @@ -1,6 +1,6 @@
23 # Copyright 1999-2015 Gentoo Foundation
24 # Distributed under the terms of the GNU General Public License v2
25 -# $Header: /var/cvsroot/gentoo-x86/eclass/mount-boot.eclass,v 1.22 2015/07/30 07:14:49 vapier Exp $
26 +# $Header: /var/cvsroot/gentoo-x86/eclass/mount-boot.eclass,v 1.23 2015/07/30 07:16:19 vapier Exp $
27
28 # @ECLASS: mount-boot.eclass
29 # @MAINTAINER:
30 @@ -13,7 +13,7 @@
31 # function tries to ensure that it's mounted in rw mode, exiting with an
32 # error if it can't. It does nothing if /boot isn't a separate partition.
33
34 -EXPORT_FUNCTIONS pkg_preinst pkg_postinst pkg_prerm pkg_postrm
35 +EXPORT_FUNCTIONS pkg_pretend pkg_preinst pkg_postinst pkg_prerm pkg_postrm
36
37 # @FUNCTION: mount-boot_disabled
38 # @INTERNAL
39 @@ -40,41 +40,73 @@
40 return 1
41 }
42
43 -mount-boot_mount_boot_partition() {
44 +# @FUNCTION: mount-boot_check_status
45 +# @INTERNAL
46 +# @DESCRIPTION:
47 +# Figure out what kind of work we need to do in order to have /boot be sane.
48 +# Return values are:
49 +# 0 - Do nothing at all!
50 +# 1 - It's mounted, but is currently ro, so need to remount rw.
51 +# 2 - It's not mounted, so need to mount it rw.
52 +mount-boot_check_status() {
53 # Get out fast if possible.
54 mount-boot_is_disabled && return 0
55
56 - elog "To avoid automounting and auto(un)installing with /boot,"
57 - elog "just export the DONT_MOUNT_BOOT variable."
58 -
59 # note that /dev/BOOT is in the Gentoo default /etc/fstab file
60 local fstabstate=$(awk '!/^#|^[[:blank:]]+#|^\/dev\/BOOT/ {print $2}' /etc/fstab | egrep "^/boot$" )
61 local procstate=$(awk '$2 ~ /^\/boot$/ {print $2}' /proc/mounts)
62 local proc_ro=$(awk '{ print $2 " ," $4 "," }' /proc/mounts | sed -n '/\/boot .*,ro,/p')
63
64 - if [ -n "${fstabstate}" ] && [ -n "${procstate}" ]; then
65 - if [ -n "${proc_ro}" ]; then
66 + if [ -n "${fstabstate}" ] && [ -n "${procstate}" ] ; then
67 + if [ -n "${proc_ro}" ] ; then
68 echo
69 einfo "Your boot partition, detected as being mounted at /boot, is read-only."
70 einfo "It will be remounted in read-write mode temporarily."
71 - mount -o remount,rw /boot
72 - if [ "$?" -ne 0 ]; then
73 - echo
74 - eerror "Unable to remount in rw mode. Please do it manually!"
75 - die "Can't remount in rw mode. Please do it manually!"
76 - fi
77 - touch /boot/.e.remount
78 + return 1
79 else
80 echo
81 einfo "Your boot partition was detected as being mounted at /boot."
82 einfo "Files will be installed there for ${PN} to function correctly."
83 + return 0
84 fi
85 - elif [ -n "${fstabstate}" ] && [ -z "${procstate}" ]; then
86 + elif [ -n "${fstabstate}" ] && [ -z "${procstate}" ] ; then
87 echo
88 einfo "Your boot partition was not mounted at /boot, so it will be automounted for you."
89 einfo "Files will be installed there for ${PN} to function correctly."
90 + return 2
91 + else
92 + echo
93 + einfo "Assuming you do not have a separate /boot partition."
94 + return 0
95 + fi
96 +}
97 +
98 +mount-boot_pkg_pretend() {
99 + # Get out fast if possible.
100 + mount-boot_is_disabled && return 0
101 +
102 + elog "To avoid automounting and auto(un)installing with /boot,"
103 + elog "just export the DONT_MOUNT_BOOT variable."
104 + mount-boot_check_status
105 +}
106 +
107 +mount-boot_mount_boot_partition() {
108 + mount-boot_check_status
109 + case $? in
110 + 0) # Nothing to do.
111 + ;;
112 + 1) # Remount it rw.
113 + mount -o remount,rw /boot
114 + if [ $? -ne 0 ] ; then
115 + echo
116 + eerror "Unable to remount in rw mode. Please do it manually!"
117 + die "Can't remount in rw mode. Please do it manually!"
118 + fi
119 + touch /boot/.e.remount
120 + ;;
121 + 2) # Mount it rw.
122 mount /boot -o rw
123 - if [ "$?" -ne 0 ]; then
124 + if [ $? -ne 0 ] ; then
125 echo
126 eerror "Cannot automatically mount your /boot partition."
127 eerror "Your boot partition has to be mounted rw before the installation"
128 @@ -82,13 +114,16 @@
129 die "Please mount your /boot partition manually!"
130 fi
131 touch /boot/.e.mount
132 - else
133 - echo
134 - einfo "Assuming you do not have a separate /boot partition."
135 - fi
136 + ;;
137 + esac
138 }
139
140 mount-boot_pkg_preinst() {
141 + # Handle older EAPIs.
142 + case ${EAPI:-0} in
143 + [0-3]) mount-boot_pkg_pretend ;;
144 + esac
145 +
146 mount-boot_mount_boot_partition
147 }