mirror of
https://github.com/Monadical-SAS/cubbi.git
synced 2025-12-22 13:19:06 +00:00
fix(uid): use symlink instead of volume for persistent volume in the container
This commit is contained in:
@@ -38,11 +38,9 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create home directory and set permissions if it doesn't exist
|
||||
if [ ! -d "/home/mcuser" ]; then
|
||||
mkdir -p /home/mcuser
|
||||
chown $MC_USER_ID:$MC_GROUP_ID /home/mcuser
|
||||
fi
|
||||
# Create home directory and set permissions
|
||||
mkdir -p /home/mcuser
|
||||
chown $MC_USER_ID:$MC_GROUP_ID /home/mcuser
|
||||
# Ensure /app exists and has correct ownership (important for volume mounts)
|
||||
mkdir -p /app
|
||||
chown $MC_USER_ID:$MC_GROUP_ID /app
|
||||
@@ -112,7 +110,42 @@ else
|
||||
echo "Warning: update-goose-config.sh script not found. Goose configuration will not be updated."
|
||||
fi
|
||||
|
||||
echo "MC driver initialization complete"
|
||||
# Create symlinks for persistent configurations defined in the driver
|
||||
if [ -n "$MC_PERSISTENT_LINKS" ]; then
|
||||
echo "Creating persistent configuration symlinks..."
|
||||
# Split by semicolon
|
||||
IFS=';' read -ra LINKS <<< "$MC_PERSISTENT_LINKS"
|
||||
for link_pair in "${LINKS[@]}"; do
|
||||
# Split by colon
|
||||
IFS=':' read -r source_path target_path <<< "$link_pair"
|
||||
|
||||
if [ -z "$source_path" ] || [ -z "$target_path" ]; then
|
||||
echo "Warning: Invalid link pair format '$link_pair', skipping."
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "Processing link: $source_path -> $target_path"
|
||||
parent_dir=$(dirname "$source_path")
|
||||
|
||||
# Ensure parent directory of the link source exists and is owned by mcuser
|
||||
if [ ! -d "$parent_dir" ]; then
|
||||
echo "Creating parent directory: $parent_dir"
|
||||
mkdir -p "$parent_dir"
|
||||
echo "Changing ownership of parent $parent_dir to $MC_USER_ID:$MC_GROUP_ID"
|
||||
chown "$MC_USER_ID:$MC_GROUP_ID" "$parent_dir" || echo "Warning: Could not chown parent $parent_dir"
|
||||
fi
|
||||
|
||||
# Create the symlink (force, no-dereference)
|
||||
echo "Creating symlink: ln -sfn $target_path $source_path"
|
||||
ln -sfn "$target_path" "$source_path"
|
||||
|
||||
# Optionally, change ownership of the symlink itself
|
||||
echo "Changing ownership of symlink $source_path to $MC_USER_ID:$MC_GROUP_ID"
|
||||
chown -h "$MC_USER_ID:$MC_GROUP_ID" "$source_path" || echo "Warning: Could not chown symlink $source_path"
|
||||
|
||||
done
|
||||
echo "Persistent configuration symlinks created."
|
||||
fi
|
||||
|
||||
# Mark initialization as complete
|
||||
echo "=== MC Initialization completed at $(date) ==="
|
||||
@@ -126,21 +159,4 @@ if [ -n "$MC_RUN_COMMAND" ]; then
|
||||
echo "--- Initial command finished (exit code: $COMMAND_EXIT_CODE) ---";
|
||||
fi;
|
||||
|
||||
# Determine the final command (the interactive shell)
|
||||
FINAL_CMD=("$@")
|
||||
if [ ${#FINAL_CMD[@]} -eq 0 ]; then
|
||||
# Default to /bin/bash if CMD wasn't passed or was empty
|
||||
FINAL_CMD=("/bin/bash")
|
||||
fi
|
||||
|
||||
# If the final command is bash, ensure it runs interactively
|
||||
# Check if the first argument is /bin/bash and -i is not already present
|
||||
if [ "${FINAL_CMD[0]}" = "/bin/bash" ] && [[ ! " ${FINAL_CMD[@]} " =~ " -i " ]]; then
|
||||
# Add the -i flag to the command array
|
||||
FINAL_CMD+=("-i")
|
||||
fi
|
||||
|
||||
echo "--- Starting interactive shell (${FINAL_CMD[*]}) ---";
|
||||
# Now exec gosu directly into the final command, replacing this script process
|
||||
# "${FINAL_CMD[@]}" ensures arguments are passed correctly (e.g., /bin/bash -i)
|
||||
exec gosu mcuser "${FINAL_CMD[@]}"
|
||||
exec gosu mcuser "$@"
|
||||
|
||||
Reference in New Issue
Block a user