From 0145b2847db4378f86bcd8d266b4453339092bc3 Mon Sep 17 00:00:00 2001 From: William Walker Date: Tue, 1 Oct 2024 14:35:45 -0500 Subject: [PATCH] fix: set correct permissions for .cosmic dir --- scripts/preinstall | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/scripts/preinstall b/scripts/preinstall index f8096a0..0d8f029 100755 --- a/scripts/preinstall +++ b/scripts/preinstall @@ -10,13 +10,30 @@ PKL_URL="https://github.com/apple/pkl/releases/download/${PKL_VERSION}/pkl-${PKL PKL_DEST="$COSMIC_DIR/pkl" PATHS_FILE="/etc/paths.d/cosmic" -# Create the cosmic directory if it does not exist -if [ ! -d "$COSMIC_DIR" ]; then - mkdir -p "$COSMIC_DIR" || { echo "Failed to create directory $COSMIC_DIR"; exit 1; } +# Check the current ownership and permissions of the .cosmic directory +if [ -d "$COSMIC_DIR" ]; then + echo "$COSMIC_DIR already exists. Checking permissions..." + ls -ld "$COSMIC_DIR" else - echo "$COSMIC_DIR already exists." + # Create the .cosmic directory if it does not exist + echo "$COSMIC_DIR does not exist. Creating it now..." + mkdir -p "$COSMIC_DIR" || { echo "Failed to create directory $COSMIC_DIR"; exit 1; } +fi + +# Ensure the current user has ownership of the directory +if [ "$(stat -f '%u' "$COSMIC_DIR")" -ne "$(id -u)" ]; then + echo "Ownership mismatch. Setting ownership of $COSMIC_DIR to $USER..." + sudo chown -R "$USER:staff" "$COSMIC_DIR" || { echo "Failed to change ownership of $COSMIC_DIR"; exit 1; } fi +# Set permissions for the .cosmic directory +echo "Setting permissions of $COSMIC_DIR to 755..." +chmod 755 "$COSMIC_DIR" || { echo "Failed to set permissions of $COSMIC_DIR"; exit 1; } + +# Verify permissions and ownership again +echo "Verifying ownership and permissions:" +ls -ld "$COSMIC_DIR" + # Download the PKL file echo "Downloading PKL from $PKL_URL..." if curl -L -o "$PKL_DEST" "$PKL_URL"; then