Skip to content

Commit 33fca9e

Browse files
authored
Add set-codebase-owner function (#320)
1 parent cdc3322 commit 33fca9e

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

Makefile

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,35 @@ download-default-certs: mkcert
305305
composer_update:
306306
docker compose exec -T drupal with-contenv bash -lc su nginx -s /bin/bash -c "composer update"
307307

308+
.PHONY: set-codebase-owner
309+
.SILENT: set-codebase-owner
310+
## JHU: Updates codebase folder to be owned by the host user and nginx group and ensures vendor directory permissions.
311+
set-codebase-owner:
312+
@echo ""
313+
@echo "Setting codebase/ folder owner back to $(shell id -u):101"
314+
if [ -n "$$(docker ps -q -f name=drupal)" ]; then \
315+
echo " └─ Using docker-compose codebase/ directory"; \
316+
docker-compose exec -T drupal with-contenv bash -lc "find . -not -user $(shell id -u) -not -path '*/sites/default/files' -exec chown $(shell id -u):101 {} \;" ; \
317+
docker-compose exec -T drupal with-contenv bash -lc "find . -not -group 101 -not -path '*/sites/default/files' -exec chown $(shell id -u):101 {} \;" ; \
318+
# Check and fix vendor directory ownership and permissions \
319+
echo " └─ Checking vendor directory permissions"; \
320+
docker-compose exec -T drupal with-contenv bash -lc "[ ! -d ./vendor ] && mkdir -p ./vendor" ; \
321+
docker-compose exec -T drupal with-contenv bash -lc "[ ! -d ./vendor ] || find ./vendor -not -user $(shell id -u) -exec chown $(shell id -u):101 {} \;" ; \
322+
docker-compose exec -T drupal with-contenv bash -lc "[ ! -d ./vendor ] || chmod -R 775 ./vendor" ; \
323+
elif [ -d "codebase" ]; then \
324+
echo " └─ Using local codebase/ directory"; \
325+
sudo find ./codebase -not -user $(shell id -u) -not -path '*/sites/default/files' -exec chown $(shell id -u):101 {} \; ; \
326+
sudo find ./codebase -not -group 101 -not -path '*/sites/default/files' -exec chown $(shell id -u):101 {} \; ; \
327+
# Check and fix vendor directory ownership and permissions \
328+
echo " └─ Checking vendor directory permissions"; \
329+
[ ! -d ./codebase/vendor ] || sudo mkdir -p ./codebase/vendor ; \
330+
[ ! -d ./codebase/vendor ] || sudo find ./codebase/vendor -not -user $(shell id -u) -exec chown $(shell id -u):101 {} \; ; \
331+
[ ! -d ./codebase/vendor ] || sudo chmod -R 775 ./codebase/vendor ; \
332+
else \
333+
echo " └─ No codebase/ directory found, skipping"; \
334+
fi
335+
@echo " └─ Done"
336+
@echo ""
308337

309338
reindex-fcrepo-metadata:
310339
# Re-index RDF in Fedora
@@ -376,9 +405,9 @@ endif
376405
.SILENT: config-export
377406
## Exports the sites configuration.
378407
config-export:
408+
$(MAKE) set-codebase-owner
379409
docker compose exec -T drupal drush -l $(SITE) config:export -y
380410

381-
382411
.PHONY: config-import
383412
.SILENT: config-import
384413
## Import the sites configuration. N.B You may need to run this multiple times in succession due to errors in the configurations dependencies.

0 commit comments

Comments
 (0)