overlay sys-apps/baselayout: Refactor and complete merged-usr process

The initial goals of this commit were:

- drop symlink-usr USE flag and keep the code paths where symlink-usr
was evaluated to true,

- make sbin a symlink to its bin counterpart, effectively doing the
merged-sbin process too

- unify filesystem layouts of the SDK and generic images.

But over the course, more changes have accumulated:

- use EAPI 8,

- drop the check_sym function - it never worked due to typos
  (real_path and real_value versus read_path and read_value),

- do the SDK-specific or generic-image-specific customizations in the
  src_prepare phase,

- follow the changes made in the baselayout repository:

  - remove unnecessary tmpfiles.d conf files instead of fiddling with
    sed to edit them:

    - in the baselayout repo, the conf files were split to make it
      possible,

  - use tmpfiles.d to create core home directory:

    - used to be done differently for generic images and for SDKs,

  - use dumb-tmpfiles-proc.sh instead of systemd's tmpfile processor:

    - this removes the need to install valid passwd and group files
      into /etc before,

    - also it seems to be fixing some issues with installing files for
      users and groups that weren't there anyway,

  - drop generating of baselayout-usr in src_compile, and creating
    debug directories in pkg_preinst, these are handled by the
    Makefile now

    - this made inheriting systemd and tmpfiles eclasses unnecessary

- install files in the src_install phase and install the directory
  structure in the pkg_preinst phase:

  - empty directories created in src_install are not guaranteed to be
    preserved, and indeed at some point /usr/local/bin was not
    installed on the final rootfs,

- currently installed /etc/passwd and /etc/group are now empty

- drop DEPEND variable entirely - systemd isn't really needed, I don't
  know what was the point of depending on libidn2, and the rest were
  conflicts with some old versions of packages.
This commit is contained in:
Krzesimir Nowak 2024-06-28 11:49:41 +02:00
parent 1dd9a2b34b
commit 35325ae5c6
3 changed files with 58 additions and 165 deletions

View File

@ -1 +1 @@
DIST flatcar-baselayout-937a45faef0f7fa88d3d2c3f7ba60a7f3e2e82f7.tar.gz 34560 BLAKE2B f4204cdabb87cc1618d7adcc0f3b0103686d60d1073c7539ffb1e4c0c264308b42cac1a2aaab0153c9762935d1cbf81c0e061a1aaeb53980d6ff278a6d26290b SHA512 9ca214c698fcd144c7dabcbda2226af7d2126b5d104ceb1eab7234a41326cc6a469ebaf2528709234d59019c84e277925e66309f4cb62b17f48be8834f6b611a
DIST flatcar-baselayout-1ad3846c507888ffbb4209f6eaf294a60cda5fe6.tar.gz 36931 BLAKE2B e354aabaf99b2c0c50c05d377e3b51c33b2924640dbc9c49c359e3a50a18d7c6067e5e901f090deb181c787ba7b437d72e5a7a5d477682794d7f9e5b12f10966 SHA512 036c3d174afcf3e81a11ff0b6cf1b9ad4b16e70eeabc68d739eef24c18e8269a27d3f7aa236c885ba6ccf5f6450ee034a553d6017b26902d75274e476a211f87

View File

@ -1,138 +1,60 @@
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
EAPI=7
EAPI=8
EGIT_REPO_URI="https://github.com/flatcar/baselayout.git"
if [[ "${PV}" == 9999 ]]; then
inherit git-r3
KEYWORDS="~amd64 ~arm ~arm64 ~x86"
KEYWORDS="~amd64 ~arm64"
else
EGIT_COMMIT="937a45faef0f7fa88d3d2c3f7ba60a7f3e2e82f7" # flatcar-master
EGIT_COMMIT="1ad3846c507888ffbb4209f6eaf294a60cda5fe6" # flatcar-master
SRC_URI="https://github.com/flatcar/baselayout/archive/${EGIT_COMMIT}.tar.gz -> flatcar-${PN}-${EGIT_COMMIT}.tar.gz"
S="${WORKDIR}/${PN}-${EGIT_COMMIT}"
KEYWORDS="amd64 arm arm64 x86"
KEYWORDS="amd64 arm64"
fi
TMPFILES_OPTIONAL=1
inherit multilib systemd tmpfiles
inherit multilib
DESCRIPTION="Filesystem baselayout for CoreOS"
HOMEPAGE="http://www.coreos.com/"
DESCRIPTION="Filesystem baselayout for Flatcar"
HOMEPAGE="https://www.flatcar.org/"
LICENSE="GPL-2"
SLOT="0"
IUSE="cros_host symlink-usr"
# This version of baselayout replaces coreos-base
DEPEND="sys-apps/systemd
net-dns/libidn2:=
!coreos-base/coreos-base
!<sys-libs/glibc-2.17-r1
!<=sys-libs/nss-usrfiles-2.18.1_pre"
IUSE="cros_host"
# Make sure coreos-init is not installed in the SDK
RDEPEND="${DEPEND}
RDEPEND="
>=sys-apps/gentoo-functions-0.10
cros_host? ( !coreos-base/coreos-init )"
cros_host? ( !coreos-base/coreos-init )
"
MOUNT_POINTS=(
/dev
/proc
/sys
)
declare -A USR_SYMS # list of /foo->usr/foo symlinks
declare -a BASE_DIRS # list of absolute paths that should be directories
# Check that a pre-existing symlink is correct
check_sym() {
local path="$1" value="$2"
local real_path=$(readlink -f "${ROOT}${path}")
local real_value=$(readlink -f "${ROOT}${path%/*}/${value}")
if [[ -e "${read_path}" && "${read_path}" != "${read_value}" ]]; then
die "${path} is not a symlink to ${value}"
fi
}
pkg_setup() {
local libdirs=$(get_all_libdirs)
if [[ -z "${libdirs}" ]]; then
die "your DEFAULT_ABI=$DEFAULT_ABI appears to be invalid"
fi
# figure out which paths should be symlinks and which should be directories
local d
for d in bin sbin ${libdirs} ; do
if use symlink-usr; then
USR_SYMS["/$d"]="usr/$d"
BASE_DIRS+=( "/usr/$d" "/usr/local/$d" )
else
BASE_DIRS+=( "/$d" "/usr/$d" "/usr/local/$d" )
fi
done
# make sure any pre-existing symlinks map to the expected locations.
local sym
if use symlink-usr; then
for sym in "${!USR_SYMS[@]}" ; do
check_sym "${sym}" "${USR_SYMS[$sym]}"
done
fi
}
src_compile() {
src_prepare() {
default
# generate a tmpfiles.d config to cover our /usr symlinks
if use symlink-usr; then
local tmpfiles="${T}/baselayout-usr.conf"
echo -n > ${tmpfiles} || die
for sym in "${!USR_SYMS[@]}" ; do
echo "L+ ${sym} - - - - ${USR_SYMS[$sym]}" >> ${tmpfiles}
done
fi
}
src_install() {
dodir "${BASE_DIRS[@]}"
if use cros_host; then
# Since later systemd-tmpfiles --root is used only users from
# /etc/passwd are considered but we don't want to add core there
# because it would make emerge overwrite the system's database on
# installation when the SDK user is already there. Instead, just
# create the folder manually and remove the tmpfile directive.
rm "${S}/tmpfiles.d/baselayout-home.conf"
mkdir -p "${D}"/home/core
chown 500:500 "${D}"/home/core
# Undesirable in the SDK
rm -f lib/tmpfiles.d/baselayout-etc-profile-flatcar-profile.conf || die
# Provided by vim in the SDK
rm -f lib/tmpfiles.d/baselayout-etc-vim.conf || die
# Don't initialize /etc/passwd, group, and friends on boot.
rm -rf bin || die
rm -rf lib/systemd || die
# Inject custom SSL configuration required for signing
# payloads from the SDK container using OpenSSL.
mkdir -p etc/ssl || die
cp -a share/baselayout/pkcs11.cnf etc/ssl || die
else
# Initialize /etc/passwd, group, and friends now, so
# systemd-tmpfiles can resolve user information in ${D}
# rootfs.
bash "scripts/flatcar-tmpfiles" "${D}" "${S}/baselayout" || die
# Don't install /etc/issue since it is handled by coreos-init right now
rm -f lib/tmpfiles.d/baselayout-etc-issue.conf || die
fi
if use symlink-usr; then
dotmpfiles "${T}/baselayout-usr.conf"
systemd-tmpfiles --root="${D}" --create
# sssd not yet building on arm64
if use arm64; then
sed -i -e 's/ sss//' share/baselayout/nsswitch.conf || die
sed -i -e '/pam_sss.so/d' lib/pam.d/* || die
fi
emake DESTDIR="${D}" install
# Fill in all other paths defined in tmpfiles configs
systemd-tmpfiles --root="${D}" --create
# The above created a few mount points but leave those out of the
# package since they may be mounted read-only. postinst can make them.
local mnt
for mnt in "${MOUNT_POINTS[@]}"; do
rmdir "${D}${mnt}" || die
done
doenvd "env.d/99flatcar_ldpath"
# handle multilib paths. do it here because we want this behavior
# regardless of the C library that you're using. we do explicitly
# list paths which the native ldconfig searches, but this isn't
@ -141,9 +63,10 @@ src_install() {
# path and the symlinked path doesn't change the resulting cache.
local libdir ldpaths
for libdir in $(get_all_libdirs) ; do
ldpaths+=":/${libdir}:/usr/${libdir}:/usr/local/${libdir}"
ldpaths+=":${EPREFIX}/usr/${libdir}"
ldpaths+=":${EPREFIX}/usr/local/${libdir}"
done
echo "LDPATH='${ldpaths#:}'" >> "${D}"/etc/env.d/00basic || die
echo "LDPATH='${ldpaths#:}'" >> etc/env.d/00basic || die
# Add oem/lib64 to search path towards end of the system's list.
# This simplifies the configuration of OEMs with dynamic libs.
@ -151,70 +74,40 @@ src_install() {
for libdir in $(get_all_libdirs) ; do
ldpaths+=":/oem/${libdir}"
done
echo "LDPATH='${ldpaths#:}'" >> "${D}"/etc/env.d/80oem || die
echo "LDPATH='${ldpaths#:}'" >> etc/env.d/80oem || die
}
if ! use symlink-usr ; then
# modprobe uses /lib instead of /usr/lib
mv "${D}"/usr/lib/modprobe.d "${D}"/lib/modprobe.d || die
fi
src_compile() {
local libdirs
if use arm64; then
sed -i 's/ sss//' "${D}"/usr/share/baselayout/nsswitch.conf || die
fi
libdirs=$(get_all_libdirs)
emake LIBDIRS="${libdirs}" all
}
if use cros_host; then
# Provided by vim in the SDK
rm -r "${D}"/etc/vim || die
# Undesirable in the SDK
rm "${D}"/etc/profile.d/flatcar-profile.sh || die
else
# Don't install /etc/issue since it is handled by coreos-init right now
rm "${D}"/etc/issue || die
sed -i -e '/\/etc\/issue/d' \
"${D}"/usr/lib/tmpfiles.d/baselayout-etc.conf || die
src_install() {
emake DESTDIR="${ED}" install
# GID 190 is taken from acct-group/systemd-journal eclass
SYSTEMD_JOURNAL_GID=${ACCT_GROUP_SYSTEMD_JOURNAL_ID:-190} ROOT_UID=0 ROOT_GID=0 CORE_UID=500 CORE_GID=500 DESTDIR=${D} ./dumb-tmpfiles-proc.sh --exclude d "${ED}/usr/lib/tmpfiles.d" || die
# Initialize /etc/passwd, group, and friends on boot.
dosbin "scripts/flatcar-tmpfiles"
systemd_dounit "scripts/flatcar-tmpfiles.service"
systemd_enable_service sysinit.target flatcar-tmpfiles.service
fi
insinto /usr/share/baselayout
doins Makefile
exeinto /usr/share/baselayout
doexe dumb-tmpfiles-proc.sh
}
# sssd not yet building on arm64
if use arm64; then
sed -i -e '/pam_sss.so/d' "${D}"/usr/lib/pam.d/* || die
fi
pkg_preinst() {
local libdirs
libdirs=$(get_all_libdirs)
emake -C "${ED}/usr/share/${PN}" DESTDIR="${EROOT}" LIBDIRS="${libdirs}" layout
SYSTEMD_JOURNAL_GID=${ACCT_GROUP_SYSTEMD_JOURNAL_ID:-190} ROOT_UID=0 ROOT_GID=0 CORE_UID=500 CORE_GID=500 DESTDIR=${D} "${ED}/usr/share/${PN}/dumb-tmpfiles-proc.sh" "${ED}/usr/lib/tmpfiles.d" || die
rm -f "${ED}/usr/share/${PN}/Makefile" "${ED}/usr/share/${PN}/dumb-tmpfiles-proc.sh" || die
if use cros_host; then
# inject custom SSL configuration required for signing payloads from the SDK container using OpenSSL.
insinto "/etc/ssl/"
doins "${S}/baselayout/pkcs11.cnf"
fi
# The default passwd/group files must exist for some ebuilds
touch "${ED}/etc/"{group,gshadow,passwd,shadow}
chmod 640 "${ED}/etc/"{gshadow,shadow}
}
pkg_postinst() {
# best-effort creation of mount points
local mnt
for mnt in "${MOUNT_POINTS[@]}"; do
[[ -d "${ROOT}${mnt}" ]] || mkdir "${ROOT}${mnt}"
done
# Set up /usr/lib/debug to match the root filesystem layout
# FIXME: This is done in postinst right now and all errors are ignored
# as a transitional scheme, this isn't important enough to migrate
# existing SDK environments.
local dir
for dir in "${BASE_DIRS[@]}"; do
mkdir -p "${ROOT}/usr/lib/debug/${dir}"
done
if use symlink-usr; then
for sym in "${!USR_SYMS[@]}" ; do
ln -sfT "${USR_SYMS[$sym]}" "${ROOT}/usr/lib/debug/${sym}"
done
fi
# The default passwd/group files must exist in the SDK for some ebuilds
if use cros_host; then
touch "${ROOT}/etc/"{group,gshadow,passwd,shadow}
chmod 640 "${ROOT}/etc/"{gshadow,shadow}
fi
# compat symlink for packages that haven't migrated to gentoo-functions
local func=../../lib/gentoo/functions.sh
if [[ "$(readlink "${ROOT}/etc/init.d/functions.sh")" != "${func}" ]]; then