Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create a systemd unit to create opt links on boot #380

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions modules/rpm-ostree/bluebuild-optfix.service
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions modules/rpm-ostree/optfix.sh
Original file line number Diff line number Diff line change
@@ -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
20 changes: 18 additions & 2 deletions modules/rpm-ostree/rpm-ostree.sh
gmpinder marked this conversation as resolved.
Show resolved Hide resolved
gmpinder marked this conversation as resolved.
Show resolved Hide resolved
gmpinder marked this conversation as resolved.
Show resolved Hide resolved
gmpinder marked this conversation as resolved.
Show resolved Hide resolved
gmpinder marked this conversation as resolved.
Show resolved Hide resolved
gmpinder marked this conversation as resolved.
Show resolved Hide resolved
gmpinder marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,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/rpm-ostree"

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 -s "/var/opt" "/opt"
ln -fs "/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 -fs "/usr/lib/opt/${OPTPKG}" "/var/opt/${OPTPKG}"
echo "Created symlinks for ${OPTPKG}"
done
fi
Expand Down
Loading