/[gentoo-x86]/eclass/mount-boot.eclass
Gentoo

Contents of /eclass/mount-boot.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (hide annotations) (download)
Thu Jul 30 07:16:19 2015 UTC (16 months, 1 week ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Changes since 1.22: +56 -21 lines
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

1 vapier 1.19 # Copyright 1999-2015 Gentoo Foundation
2 vapier 1.5 # Distributed under the terms of the GNU General Public License v2
3 vapier 1.23 # $Header: /var/cvsroot/gentoo-x86/eclass/mount-boot.eclass,v 1.18 2011/01/09 03:18:38 vapier Exp $
4 vapier 1.19
5     # @ECLASS: mount-boot.eclass
6     # @MAINTAINER:
7     # base-system@gentoo.org
8     # @BLURB: functions for packages that install files into /boot
9     # @DESCRIPTION:
10 vapier 1.12 # This eclass is really only useful for bootloaders.
11 vapier 1.8 #
12     # If the live system has a separate /boot partition configured, then this
13     # function tries to ensure that it's mounted in rw mode, exiting with an
14 vapier 1.19 # error if it can't. It does nothing if /boot isn't a separate partition.
15 woodchip 1.1
16 vapier 1.23 EXPORT_FUNCTIONS pkg_pretend pkg_preinst pkg_postinst pkg_prerm pkg_postrm
17 woodchip 1.1
18 vapier 1.22 # @FUNCTION: mount-boot_disabled
19     # @INTERNAL
20     # @DESCRIPTION:
21     # Detect whether the current environment/build settings are such that we do not
22     # want to mess with any mounts.
23     mount-boot_is_disabled() {
24 vapier 1.21 # Since this eclass only deals with /boot, skip things when ROOT is active.
25     if [[ "${ROOT:-/}" != "/" ]] ; then
26 vapier 1.22 return 0
27     fi
28    
29     # If we're only building a package, then there's no need to check things.
30     if [[ "${MERGE_TYPE}" == "buildonly" ]] ; then
31     return 0
32 vapier 1.21 fi
33    
34 vapier 1.22 # The user wants us to leave things be.
35 vapier 1.13 if [[ -n ${DONT_MOUNT_BOOT} ]] ; then
36 vapier 1.22 return 0
37 vapier 1.13 fi
38    
39 vapier 1.22 # OK, we want to handle things ourselves.
40     return 1
41     }
42    
43 vapier 1.23 # @FUNCTION: mount-boot_check_status
44     # @INTERNAL
45     # @DESCRIPTION:
46     # Figure out what kind of work we need to do in order to have /boot be sane.
47     # Return values are:
48     # 0 - Do nothing at all!
49     # 1 - It's mounted, but is currently ro, so need to remount rw.
50     # 2 - It's not mounted, so need to mount it rw.
51     mount-boot_check_status() {
52 vapier 1.22 # Get out fast if possible.
53     mount-boot_is_disabled && return 0
54    
55 woodchip 1.7 # note that /dev/BOOT is in the Gentoo default /etc/fstab file
56 vapier 1.13 local fstabstate=$(awk '!/^#|^[[:blank:]]+#|^\/dev\/BOOT/ {print $2}' /etc/fstab | egrep "^/boot$" )
57     local procstate=$(awk '$2 ~ /^\/boot$/ {print $2}' /proc/mounts)
58 vapier 1.16 local proc_ro=$(awk '{ print $2 " ," $4 "," }' /proc/mounts | sed -n '/\/boot .*,ro,/p')
59 woodchip 1.1
60 vapier 1.23 if [ -n "${fstabstate}" ] && [ -n "${procstate}" ] ; then
61     if [ -n "${proc_ro}" ] ; then
62 vapier 1.20 echo
63     einfo "Your boot partition, detected as being mounted at /boot, is read-only."
64     einfo "It will be remounted in read-write mode temporarily."
65 vapier 1.23 return 1
66 woodchip 1.1 else
67 vapier 1.20 echo
68     einfo "Your boot partition was detected as being mounted at /boot."
69 woodchip 1.1 einfo "Files will be installed there for ${PN} to function correctly."
70 vapier 1.23 return 0
71 woodchip 1.1 fi
72 vapier 1.23 elif [ -n "${fstabstate}" ] && [ -z "${procstate}" ] ; then
73 vapier 1.20 echo
74     einfo "Your boot partition was not mounted at /boot, so it will be automounted for you."
75     einfo "Files will be installed there for ${PN} to function correctly."
76 vapier 1.23 return 2
77     else
78     echo
79     einfo "Assuming you do not have a separate /boot partition."
80     return 0
81     fi
82     }
83    
84     mount-boot_pkg_pretend() {
85     # Get out fast if possible.
86     mount-boot_is_disabled && return 0
87    
88     elog "To avoid automounting and auto(un)installing with /boot,"
89     elog "just export the DONT_MOUNT_BOOT variable."
90     mount-boot_check_status
91     }
92    
93     mount-boot_mount_boot_partition() {
94     mount-boot_check_status
95     case $? in
96     0) # Nothing to do.
97     ;;
98     1) # Remount it rw.
99     mount -o remount,rw /boot
100     if [ $? -ne 0 ] ; then
101     echo
102     eerror "Unable to remount in rw mode. Please do it manually!"
103     die "Can't remount in rw mode. Please do it manually!"
104     fi
105     touch /boot/.e.remount
106     ;;
107     2) # Mount it rw.
108 vapier 1.15 mount /boot -o rw
109 vapier 1.23 if [ $? -ne 0 ] ; then
110 vapier 1.20 echo
111 woodchip 1.7 eerror "Cannot automatically mount your /boot partition."
112     eerror "Your boot partition has to be mounted rw before the installation"
113 woodchip 1.1 eerror "can continue. ${PN} needs to install important files there."
114 woodchip 1.7 die "Please mount your /boot partition manually!"
115 woodchip 1.1 fi
116 vapier 1.18 touch /boot/.e.mount
117 vapier 1.23 ;;
118     esac
119 woodchip 1.1 }
120    
121 vapier 1.13 mount-boot_pkg_preinst() {
122 vapier 1.23 # Handle older EAPIs.
123     case ${EAPI:-0} in
124     [0-3]) mount-boot_pkg_pretend ;;
125     esac
126    
127 woodchip 1.7 mount-boot_mount_boot_partition
128     }
129 vapier 1.17
130     mount-boot_pkg_prerm() {
131     touch "${ROOT}"/boot/.keep 2>/dev/null
132     mount-boot_mount_boot_partition
133     touch "${ROOT}"/boot/.keep 2>/dev/null
134     }
135 vapier 1.18
136     mount-boot_umount_boot_partition() {
137 vapier 1.22 # Get out fast if possible.
138     mount-boot_is_disabled && return 0
139 vapier 1.18
140     if [ -e /boot/.e.remount ] ; then
141 vapier 1.20 einfo "Automatically remounting /boot as ro as it was previously."
142 vapier 1.18 rm -f /boot/.e.remount
143     mount -o remount,ro /boot
144     elif [ -e /boot/.e.mount ] ; then
145 vapier 1.20 einfo "Automatically unmounting /boot as it was previously."
146 vapier 1.18 rm -f /boot/.e.mount
147     umount /boot
148     fi
149     }
150    
151     mount-boot_pkg_postinst() {
152     mount-boot_umount_boot_partition
153     }
154    
155     mount-boot_pkg_postrm() {
156     mount-boot_umount_boot_partition
157     }

  ViewVC Help
Powered by ViewVC 1.1.20