feat: refactor build.sh to use the new yafti launcher

This implements the new "yafti" launcher and ties everything together:

- The "/etc/profile.d" script is now a symlink to an immutable location, instead of an actual plaintext file, to prevent risk of user systems breaking due to ostree thinking that the script had been modified. We can now be certain that systems always work properly when switching between distros or uBlue flavors.

- Yafti is only installed if the "yafti" flag is enabled.

- If the user disables the "yafti" flag, we completely wipe out the entire yafti.yml configuration, all of our new "yafti autostart" components, and the "profile.d" symlink, so that nothing remains on the system image. If an upstream image installed yafti itself in `/usr/bin`, then we leave that component alone though (because "pip uninstall" and the potential errors it might throw seems like a pointless hassle just for a tiny, unused binary).
This commit is contained in:
Arcitec
2023-05-13 05:13:14 +02:00
committed by Eino Rauhala
parent 32c06b0867
commit 63a5e3583b

View File

@@ -5,22 +5,22 @@ set -oue pipefail
# Helper functions. # Helper functions.
RECIPE_FILE="/usr/share/ublue-os/recipe.yml" RECIPE_FILE="/usr/share/ublue-os/recipe.yml"
YAFTI_FILE="/usr/share/ublue-os/firstboot/yafti.yml"
get_yaml_array() { get_yaml_array() {
mapfile -t "$1" < <(yq -- "$2" "$RECIPE_FILE") mapfile -t "${1}" < <(yq -- "${2}" "${RECIPE_FILE}")
} }
get_yaml_string() { get_yaml_string() {
yq -- "$1" "$RECIPE_FILE" yq -- "${1}" "${RECIPE_FILE}"
} }
# Automatically determine which Fedora version we're building. # Automatically determine which Fedora version we're building.
FEDORA_VERSION="$(cat /usr/lib/os-release | grep '^VERSION_ID=' | head -1 | sed 's,^VERSION_ID=,,')" FEDORA_VERSION="$(cat /usr/lib/os-release | grep '^VERSION_ID=' | head -1 | sed 's,^VERSION_ID=,,')"
# Read configuration variables. # Read configuration variables.
base_image="$(get_yaml_string '.base-image')" BASE_IMAGE="$(get_yaml_string '.base-image')"
YAFTI_ENABLED="$(get_yaml_string '.firstboot.yafti')"
# Welcome. # Welcome.
echo "Building custom Fedora ${FEDORA_VERSION} from image: \"${base_image}\"." echo "Building custom Fedora ${FEDORA_VERSION} from image: \"${BASE_IMAGE}\"."
# Add custom repos. # Add custom repos.
get_yaml_array repos '.rpm.repos[]' get_yaml_array repos '.rpm.repos[]'
@@ -28,7 +28,7 @@ if [[ ${#repos[@]} -gt 0 ]]; then
echo "-- Adding repos defined in recipe.yml --" echo "-- Adding repos defined in recipe.yml --"
for repo in "${repos[@]}"; do for repo in "${repos[@]}"; do
repo="${repo//%FEDORA_VERSION%/${FEDORA_VERSION}}" repo="${repo//%FEDORA_VERSION%/${FEDORA_VERSION}}"
wget "$repo" -P /etc/yum.repos.d/ wget "${repo}" -P "/etc/yum.repos.d/"
done done
echo "---" echo "---"
fi fi
@@ -41,7 +41,7 @@ run_scripts() {
echo "-- Running [${script_mode}] scripts defined in recipe.yml --" echo "-- Running [${script_mode}] scripts defined in recipe.yml --"
for script in "${buildscripts[@]}"; do for script in "${buildscripts[@]}"; do
echo "Running [${script_mode}]: ${script}" echo "Running [${script_mode}]: ${script}"
/tmp/scripts/"$script" "${script_mode}" "/tmp/scripts/${script}" "${script_mode}"
done done
echo "---" echo "---"
fi fi
@@ -66,22 +66,41 @@ if [[ ${#install_rpms[@]} -gt 0 ]]; then
echo "---" echo "---"
fi fi
# Install yafti to install flatpaks on first boot, https://github.com/ublue-os/yafti. # Toggle yafti, which provides the "first boot" experience, https://github.com/ublue-os/yafti.
FIRSTBOOT_DATA="/usr/share/ublue-os/firstboot"
FIRSTBOOT_LINK="/usr/etc/profile.d/ublue-firstboot.sh"
if [[ "${YAFTI_ENABLED}" == "true" ]]; then
echo "-- firstboot: Installing and enabling \"yafti\" --"
pip install --prefix=/usr yafti pip install --prefix=/usr yafti
# Create symlink to our profile script, which creates the per-user "autorun yafti" links.
mkdir -p "$(dirname "${FIRSTBOOT_LINK}")"
ln -s "${FIRSTBOOT_DATA}/launcher/login-profile.sh" "${FIRSTBOOT_LINK}"
else
echo "-- firstboot: Removing all \"firstboot\" components --"
# Removes the script symlink that creates the per-user autostart symlinks.
# We must forcibly remove this here, in case it was added by an upstream image.
rm -f "${FIRSTBOOT_LINK}"
# Remove all of the launcher-scripts and yafti config, to de-clutter image and
# ensure it can't run by accident due to lingering symlinks or upstream image.
rm -rf "${FIRSTBOOT_DATA}"
fi
# Add a new yafti "package group" called Custom, for the packages defined in recipe.yml. # Add a new yafti "package group" called Custom, for the packages defined in recipe.yml.
# Only adds the package group if some flatpaks are defined in the recipe. # Only adds the package group if yafti is enabled and Flatpaks are defined in the recipe.
get_yaml_array flatpaks '.flatpaks[]' if [[ "${YAFTI_ENABLED}" == "true" ]]; then
YAFTI_FILE="${FIRSTBOOT_DATA}/yafti.yml"
get_yaml_array flatpaks '.firstboot.flatpaks[]'
if [[ ${#flatpaks[@]} -gt 0 ]]; then if [[ ${#flatpaks[@]} -gt 0 ]]; then
echo "-- yafti: Adding Flatpaks defined in recipe.yml --" echo "-- yafti: Adding Flatpaks defined in recipe.yml --"
yq -i '.screens.applications.values.groups.Custom.description = "Flatpaks defined by the image maintainer"' "$YAFTI_FILE" yq -i '.screens.applications.values.groups.Custom.description = "Flatpaks suggested by the image maintainer."' "${YAFTI_FILE}"
yq -i '.screens.applications.values.groups.Custom.default = true' "$YAFTI_FILE" yq -i '.screens.applications.values.groups.Custom.default = true' "${YAFTI_FILE}"
for pkg in "${flatpaks[@]}"; do for pkg in "${flatpaks[@]}"; do
echo "Adding to yafti: ${pkg}" echo "Adding to yafti: ${pkg}"
yq -i ".screens.applications.values.groups.Custom.packages += [{\"$pkg\": \"$pkg\"}]" "$YAFTI_FILE" yq -i ".screens.applications.values.groups.Custom.packages += [{\"${pkg}\": \"${pkg}\"}]" "${YAFTI_FILE}"
done done
echo "---" echo "---"
fi fi
fi
# Run "post" scripts. # Run "post" scripts.
run_scripts "post" run_scripts "post"