From 52ad61d5805105ee619d91d4396dc9fff5e5de49 Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Sat, 12 Oct 2024 14:34:52 +0200 Subject: [PATCH] fix: DEV-2107: Make setup-base.sh not create self-referencing link on repeated runs. --- scripts/setup-base.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/scripts/setup-base.sh b/scripts/setup-base.sh index ce45bf7c45..42bb22f500 100755 --- a/scripts/setup-base.sh +++ b/scripts/setup-base.sh @@ -39,13 +39,17 @@ for SITE in `ls -d web/sites/*/`; do mkdir -p $PERSISTENT_FILES_DIR/$SITE/private if [ -n "$ENV_UNIX_GROUP_WEBSERVER" ]; then - sudo chown -R :$ENV_UNIX_GROUP_WEBSERVER $PERSISTENT_FILES_DIR/$SITE/ - # When a custom group is set, ensure sub-directory and files are always - # webserver writable via the setgid bit. This makes the right group to be - # propagated down. - sudo chmod 2775 $PERSISTENT_FILES_DIR/$SITE/public - sudo chmod 2775 $PERSISTENT_FILES_DIR/$SITE/public/translations - sudo chmod 2775 $PERSISTENT_FILES_DIR/$SITE/private + if [[ $(id -u) -eq 0 || $(command -v sudo) ]]; then + # Note: this group may not exist on the host OS (MacOS), so the command + # fails. Just ignore the error; chmods are still done and things work OK. + sudo chown -R :$ENV_UNIX_GROUP_WEBSERVER $PERSISTENT_FILES_DIR/$SITE/ + # When a custom group is set, ensure sub-directory and files are always + # webserver writable via the setgid bit. This makes the right group to be + # propagated down. + sudo chmod 2775 $PERSISTENT_FILES_DIR/$SITE/public + sudo chmod 2775 $PERSISTENT_FILES_DIR/$SITE/public/translations + sudo chmod 2775 $PERSISTENT_FILES_DIR/$SITE/private + fi fi # Move files for existing dev-installations. @@ -57,6 +61,8 @@ for SITE in `ls -d web/sites/*/`; do # Link public files directory to persistent files. mkdir -p web/sites/$SITE - os_compat_link_directory ../../../$PERSISTENT_FILES_DIR/$SITE/public web/sites/$SITE/files + if [[ ! -L web/sites/$SITE/files ]]; then + os_compat_link_directory ../../../$PERSISTENT_FILES_DIR/$SITE/public web/sites/$SITE/files + fi done