From f2d6adf54da7f9037973ac69946bf75ed95b105e Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Mon, 30 Dec 2024 12:59:20 -0500 Subject: [PATCH] feat: Add optfix systemd service --- modules/dnf/bluebuild-optfix.service | 11 +++++++++++ modules/dnf/dnf.sh | 18 +++++++++++++++++- modules/dnf/optfix.sh | 27 +++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 modules/dnf/bluebuild-optfix.service create mode 100644 modules/dnf/optfix.sh diff --git a/modules/dnf/bluebuild-optfix.service b/modules/dnf/bluebuild-optfix.service new file mode 100644 index 0000000..6470559 --- /dev/null +++ b/modules/dnf/bluebuild-optfix.service @@ -0,0 +1,11 @@ +[Unit] +Description=Create symbolic links for directories in /usr/lib/opt/ to /var/opt/ +After=multi-user.target + +[Service] +Type=oneshot +ExecStart=/usr/libexec/bluebuild/optfix.sh +RemainAfterExit=no + +[Install] +WantedBy=default.target diff --git a/modules/dnf/dnf.sh b/modules/dnf/dnf.sh index 2cff5eb..9eeed08 100644 --- a/modules/dnf/dnf.sh +++ b/modules/dnf/dnf.sh @@ -59,16 +59,32 @@ fi # Create symlinks to fix packages that create directories in /opt get_json_array OPTFIX 'try .["optfix"][]' "${1}" if [[ ${#OPTFIX[@]} -gt 0 ]]; then + LIB_EXEC_DIR="/usr/libexec/bluebuild" + SYSTEMD_DIR="/etc/systemd/system" + MODULE_DIR="/tmp/modules/dnf" + + if ! [ -x "${LIB_EXEC_DIR}/optfix.sh" ]; then + mkdir -p "${LIB_EXEC_DIR}" + cp "${MODULE_DIR}/optfix.sh" "${LIB_EXEC_DIR}/" + chmod +x "${LIB_EXEC_DIR}/optfix.sh" + fi + + if ! [ -f "${SYSTEMD_DIR}/bluebuild-optfix.service" ]; then + cp "${MODULE_DIR}/bluebuild-optfix.service" "${SYSTEMD_DIR}/" + systemctl enable bluebuild-optfix.service + fi + echo "Creating symlinks to fix packages that install to /opt" # Create symlink for /opt to /var/opt since it is not created in the image yet mkdir -p "/var/opt" ln -snf "/var/opt" "/opt" + # Create symlinks for each directory specified in recipe.yml for OPTPKG in "${OPTFIX[@]}"; do OPTPKG="${OPTPKG%\"}" OPTPKG="${OPTPKG#\"}" mkdir -p "/usr/lib/opt/${OPTPKG}" - ln -s "../../usr/lib/opt/${OPTPKG}" "/var/opt/${OPTPKG}" + ln -sf "/usr/lib/opt/${OPTPKG}" "/var/opt/${OPTPKG}" echo "Created symlinks for ${OPTPKG}" done fi diff --git a/modules/dnf/optfix.sh b/modules/dnf/optfix.sh new file mode 100644 index 0000000..fcec512 --- /dev/null +++ b/modules/dnf/optfix.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SOURCE_DIR="/usr/lib/opt/" +TARGET_DIR="/var/opt/" + +# Ensure the target directory exists +mkdir -p "$TARGET_DIR" + +# Loop through directories in the source directory +for dir in "$SOURCE_DIR"*/; do + if [ -d "$dir" ]; then + # Get the base name of the directory + dir_name=$(basename "$dir") + + # Check if the symlink already exists in the target directory + if [ -L "$TARGET_DIR/$dir_name" ]; then + echo "Symlink already exists for $dir_name, skipping." + continue + fi + + # Create the symlink + ln -s "$dir" "$TARGET_DIR/$dir_name" + echo "Created symlink for $dir_name" + fi +done