From 3276763384ee6c175ee5633007626253316615d8 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 11 May 2023 14:57:42 +0200 Subject: [PATCH] overlay coreos-base/misc-files: Generate bash symlinks for core user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The package will take over the symlink creation from the sys-apps/baselayout package for the following reasons: - We will use the new location of the bash files as targets for the symlinks (`/usr/share/flatcar/etc/skel/…`). - This package makes sure that the symlinks won't dangle. - `/usr/share/flatcar/etc` does not exist in GCE OEM ACI image because we don't move `/etc` to `/usr/share/flatcar/etc` (actually, `/etc` gets completely removed) when building this image. It makes bash symlinks in core home directory to dangle and thus fail the rootfs check that happens right after installing the `coreos-base/coreos-oem-gce` package. Using the old location for the bash symlinks (that'd be `/usr/share/skel`) wouldn't help, because the files there also became symlinks, and they are dangling too. This can't fix it in the manglefs script because it's invoked too late, after the rootfs check. I decided to move the core home bash symlink creation to `coreos-base/misc-files` as this package won't be installed in ACI image. --- .../misc-files/misc-files-0.ebuild | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/misc-files/misc-files-0.ebuild b/sdk_container/src/third_party/coreos-overlay/coreos-base/misc-files/misc-files-0.ebuild index 4b2c6a15bb..18416bc822 100644 --- a/sdk_container/src/third_party/coreos-overlay/coreos-base/misc-files/misc-files-0.ebuild +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/misc-files/misc-files-0.ebuild @@ -3,6 +3,9 @@ EAPI=8 +TMPFILES_OPTIONAL=1 +inherit tmpfiles + DESCRIPTION='Flatcar miscellaneous files' HOMEPAGE='https://www.flatcar.org/' @@ -19,10 +22,28 @@ RDEPEND=" >=app-shells/bash-5.2_p15-r2 " +declare -A CORE_BASH_SYMLINKS +CORE_BASH_SYMLINKS=( + ['.bash_logout']='../../usr/share/flatcar/etc/skel/.bash_logout' + ['.bash_profile']='../../usr/share/flatcar/etc/skel/.bash_profile' + ['.bashrc']='../../usr/share/flatcar/etc/skel/.bashrc' +) + src_compile() { # An empty file for temporary symlink destinations under # /usr/share/flatcar/etc. touch "${T}/empty-file" + # Generate the tmpfiles config file for bash symlinks in core home + # directory. + local name config config_tmp target + config="${T}/home-core-bash-symlinks.conf" + config_tmp="${config}.tmp" + truncate --size 0 "${config_tmp}" + for name in "${!CORE_BASH_SYMLINKS[@]}"; do + target=${CORE_BASH_SYMLINKS["${name}"]} + echo "L /home/core/${name} - core core - ${target}" >>"${config_tmp}" + done + LC_ALL=C sort "${config_tmp}" >"${config}" } src_install() { @@ -57,4 +78,18 @@ src_install() { insinto '/etc/bash/bashrc.d' doins "${FILESDIR}/99-flatcar-bcc" + + dotmpfiles "${T}/home-core-bash-symlinks.conf" + # Ideally we would be calling systemd-tmpfiles to create the + # symlinks, but at this point systemd may not have any info about + # the core user. Thus we hardcode the id 500. + dodir /home/core + fowners 500:500 /home/core + local name + for name in "${!CORE_BASH_SYMLINKS[@]}"; do + target=${CORE_BASH_SYMLINKS["${name}"]} + link="/home/core/${name}" + dosym "${target}" "${link}" + fowners --no-dereference 500:500 "${link}" + done }