Skip to content

Commit

Permalink
fix: set correct permissions for .cosmic dir
Browse files Browse the repository at this point in the history
  • Loading branch information
willswire committed Oct 1, 2024
1 parent 1c4a5f2 commit 0145b28
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions scripts/preinstall
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0145b28

Please sign in to comment.