mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-15 17:06:58 +02:00
eclass/mount-boot: Sync with gentoo
It's from gentoo commit 33bb454c9678ab13d58662a07a143f1bee47cafe.
This commit is contained in:
parent
956b4f2558
commit
256394a73e
@ -1,9 +1,10 @@
|
|||||||
# Copyright 1999-2015 Gentoo Foundation
|
# Copyright 1999-2021 Gentoo Authors
|
||||||
# Distributed under the terms of the GNU General Public License v2
|
# Distributed under the terms of the GNU General Public License v2
|
||||||
|
|
||||||
# @ECLASS: mount-boot.eclass
|
# @ECLASS: mount-boot.eclass
|
||||||
# @MAINTAINER:
|
# @MAINTAINER:
|
||||||
# base-system@gentoo.org
|
# base-system@gentoo.org
|
||||||
|
# @SUPPORTED_EAPIS: 6 7 8
|
||||||
# @BLURB: functions for packages that install files into /boot
|
# @BLURB: functions for packages that install files into /boot
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# This eclass is really only useful for bootloaders.
|
# This eclass is really only useful for bootloaders.
|
||||||
@ -12,21 +13,26 @@
|
|||||||
# function tries to ensure that it's mounted in rw mode, exiting with an
|
# 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.
|
# error if it can't. It does nothing if /boot isn't a separate partition.
|
||||||
|
|
||||||
|
case ${EAPI:-0} in
|
||||||
|
6|7|8) ;;
|
||||||
|
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
EXPORT_FUNCTIONS pkg_pretend pkg_preinst pkg_postinst pkg_prerm pkg_postrm
|
EXPORT_FUNCTIONS pkg_pretend pkg_preinst pkg_postinst pkg_prerm pkg_postrm
|
||||||
|
|
||||||
# @FUNCTION: mount-boot_disabled
|
# @FUNCTION: mount-boot_is_disabled
|
||||||
# @INTERNAL
|
# @INTERNAL
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Detect whether the current environment/build settings are such that we do not
|
# Detect whether the current environment/build settings are such that we do not
|
||||||
# want to mess with any mounts.
|
# want to mess with any mounts.
|
||||||
mount-boot_is_disabled() {
|
mount-boot_is_disabled() {
|
||||||
# Since this eclass only deals with /boot, skip things when ROOT is active.
|
# Since this eclass only deals with /boot, skip things when EROOT is active.
|
||||||
if [[ "${ROOT:-/}" != "/" ]] ; then
|
if [[ ${EROOT:-/} != / ]] ; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If we're only building a package, then there's no need to check things.
|
# If we're only building a package, then there's no need to check things.
|
||||||
if [[ "${MERGE_TYPE}" == "buildonly" ]] ; then
|
if [[ ${MERGE_TYPE} == buildonly ]] ; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -42,115 +48,66 @@ mount-boot_is_disabled() {
|
|||||||
# @FUNCTION: mount-boot_check_status
|
# @FUNCTION: mount-boot_check_status
|
||||||
# @INTERNAL
|
# @INTERNAL
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Figure out what kind of work we need to do in order to have /boot be sane.
|
# Check if /boot is sane, i.e., mounted as read-write if on a separate
|
||||||
# Return values are:
|
# partition. Die if conditions are not fulfilled. If nonfatal is used,
|
||||||
# 0 - Do nothing at all!
|
# the function will return a non-zero status instead.
|
||||||
# 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() {
|
mount-boot_check_status() {
|
||||||
# Get out fast if possible.
|
# Get out fast if possible.
|
||||||
mount-boot_is_disabled && return 0
|
mount-boot_is_disabled && return 0
|
||||||
|
|
||||||
# note that /dev/BOOT is in the Gentoo default /etc/fstab file
|
# 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 fstabstate=$(awk '!/^[[:blank:]]*#|^\/dev\/BOOT/ && $2 == "/boot" \
|
||||||
local procstate=$(awk '$2 ~ /^\/boot$/ {print $2}' /proc/mounts)
|
{ print 1; exit }' /etc/fstab || die "awk failed")
|
||||||
local proc_ro=$(awk '{ print $2 " ," $4 "," }' /proc/mounts | sed -n '/\/boot .*,ro,/p')
|
|
||||||
|
|
||||||
if [ -n "${fstabstate}" ] && [ -n "${procstate}" ] ; then
|
if [[ -z ${fstabstate} ]] ; 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."
|
|
||||||
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
|
|
||||||
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."
|
einfo "Assuming you do not have a separate /boot partition."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local procstate=$(awk '$2 == "/boot" { split($4, a, ","); \
|
||||||
|
for (i in a) if (a[i] ~ /^r[ow]$/) { print a[i]; break }; exit }' \
|
||||||
|
/proc/mounts || die "awk failed")
|
||||||
|
|
||||||
|
if [[ -z ${procstate} ]] ; then
|
||||||
|
eerror "Your boot partition is not mounted at /boot."
|
||||||
|
eerror "Please mount it and retry."
|
||||||
|
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 -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() {
|
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_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
|
|
||||||
echo
|
|
||||||
eerror "Cannot automatically mount your /boot partition."
|
|
||||||
eerror "Your boot partition has to be mounted rw before the installation"
|
|
||||||
eerror "can continue. ${PN} needs to install important files there."
|
|
||||||
die "Please mount your /boot partition manually!"
|
|
||||||
fi
|
|
||||||
touch /boot/.e.mount
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
mount-boot_pkg_preinst() {
|
mount-boot_pkg_preinst() {
|
||||||
# Handle older EAPIs.
|
mount-boot_check_status
|
||||||
case ${EAPI:-0} in
|
|
||||||
[0-3]) mount-boot_pkg_pretend ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
mount-boot_mount_boot_partition
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mount-boot_pkg_prerm() {
|
mount-boot_pkg_prerm() {
|
||||||
touch "${ROOT}"/boot/.keep 2>/dev/null
|
mount-boot_check_status
|
||||||
mount-boot_mount_boot_partition
|
|
||||||
touch "${ROOT}"/boot/.keep 2>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
mount-boot_umount_boot_partition() {
|
if [[ -z ${EPREFIX} ]] \
|
||||||
# Get out fast if possible.
|
&& ! ( shopt -s failglob; : "${EROOT}"/boot/.keep* ) 2>/dev/null
|
||||||
mount-boot_is_disabled && return 0
|
then
|
||||||
|
# Create a .keep file, in case it is shadowed at the mount point
|
||||||
if [ -e /boot/.e.remount ] ; then
|
touch "${EROOT}"/boot/.keep 2>/dev/null
|
||||||
einfo "Automatically remounting /boot as ro as it was previously."
|
|
||||||
rm -f /boot/.e.remount
|
|
||||||
mount -o remount,ro /boot
|
|
||||||
elif [ -e /boot/.e.mount ] ; then
|
|
||||||
einfo "Automatically unmounting /boot as it was previously."
|
|
||||||
rm -f /boot/.e.mount
|
|
||||||
umount /boot
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
mount-boot_pkg_postinst() {
|
# No-op phases for backwards compatibility
|
||||||
mount-boot_umount_boot_partition
|
mount-boot_pkg_postinst() { :; }
|
||||||
}
|
|
||||||
|
|
||||||
mount-boot_pkg_postrm() {
|
mount-boot_pkg_postrm() { :; }
|
||||||
mount-boot_umount_boot_partition
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user