Skip to content

Commit 04bbfeb

Browse files
committed
Automatically fix ../vendor folder if it exists
1 parent b8f9d23 commit 04bbfeb

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ folders.
8383
If there are content folders outside the Drupal root folder you can use the
8484
`--files-path` option and the script will take care of it.
8585

86+
If a `vendor` folder and a `composer.json` file are detected in the parent
87+
folder of the Drupal root the script assumes the `vendor` folder is a code
88+
folder and fixes permissions accordingly.
89+
8690
## Performance
8791

8892
The script only changes the files and folder with the wrong permissions or

drupal_fix_permissions.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,20 @@ function fix_onwership() {
163163
case $simulate in
164164
0)
165165
# Real action.
166-
find "$1" \( ! -user $drupal_user -o ! -group $httpd_group \) -print0 | xargs -r -0 -L20 chown $drupal_user:$httpd_group
166+
find "$1" $detected_vendor_path \( ! -user $drupal_user -o ! -group $httpd_group \) -print0 | xargs -r -0 -L20 chown $drupal_user:$httpd_group
167167
;;
168168

169169
1)
170170
# Simulate.
171171
printf "\n Items with wrong ownership: "
172-
find "$1" \( ! -user $drupal_user -o ! -group $httpd_group \) -print | wc -l
172+
find "$1" $detected_vendor_path \( ! -user $drupal_user -o ! -group $httpd_group \) -print | wc -l
173173
;;
174174

175175
2)
176176
# Simulate verbosely.
177177
printf "\n Files and directories that would have their ownership fixed: "
178178
# Use a variable to indent output.
179-
items=$(find "$1" \( ! -user $drupal_user -o ! -group $httpd_group \) -print)
179+
items=$(find "$1" $detected_vendor_path -type f -type -d \( ! -user $drupal_user -o ! -group $httpd_group \) -print)
180180
items=${items:-None}
181181
printf "\n ${items//$'\n'/$'\n' }\n"
182182
;;
@@ -196,20 +196,20 @@ function fix_code_permission_helper() {
196196
case $simulate in
197197
0)
198198
# Real action.
199-
find "$1" \( -path "$1"/sites/*/$file_folder_name -prune \) -o \( -path "$1"/sites/*/$private_folder_name -prune \) -o \( -type $2 ! -perm $3 -print0 \) | xargs -r -0 -L4 chmod $3
199+
find "$1" $detected_vendor_path \( -path "$1"/sites/*/$file_folder_name -prune \) -o \( -path "$1"/sites/*/$private_folder_name -prune \) -o \( -type $2 ! -perm $3 -print0 \) | xargs -r -0 -L4 chmod $3
200200
;;
201201

202202
1)
203203
# Simulate.
204-
num=$(find "$1" \( -path "$1"/sites/*/$file_folder_name -prune \) -o \( -path "$1"/sites/*/$private_folder_name -prune \) -o \( -type $2 ! -perm $3 -print \) | wc -l)
204+
num=$(find "$1" $detected_vendor_path \( -path "$1"/sites/*/$file_folder_name -prune \) -o \( -path "$1"/sites/*/$private_folder_name -prune \) -o \( -type $2 ! -perm $3 -print \) | wc -l)
205205
printf "\n Code items with wrong permissions: $num"
206206
;;
207207

208208
2)
209209
# Simulate verbosely.
210210
printf "\n Code files and directories that would have their permissions fixed: "
211211
# Use a variable to indent output.
212-
items=$(find "$1" \( -path "$1"/sites/*/$file_folder_name -prune \) -o \( -path "$1"/sites/*/$private_folder_name -prune \) -o \( -type $2 ! -perm $3 -print \))
212+
items=$(find "$1" $detected_vendor_path \( -path "$1"/sites/*/$file_folder_name -prune \) -o \( -path "$1"/sites/*/$private_folder_name -prune \) -o \( -type $2 ! -perm $3 -print \))
213213
items=${items:-None}
214214
printf "\n ${items//$'\n'/$'\n' }\n"
215215
;;
@@ -377,6 +377,8 @@ content_file_perms='ug=rw,o='
377377
cd $drupal_path
378378
complete_drupal_path=$(pwd)
379379

380+
# Check if there's a vendor folder in the upper folder.
381+
[ -d "../vendor" ] && [ -f "../composer.json" ] && detected_vendor_path="../vendor"
380382

381383

382384
# Show current configuration.
@@ -387,6 +389,7 @@ Owner user: $drupal_user
387389
Owner group: $httpd_group
388390
Code dirs perms: $code_dir_perms
389391
Code files perms: $code_file_perms
392+
Separated vendor folder detected: ${detected_vendor_path:-"No"}
390393
Content dirs perms: $content_dir_perms
391394
Content files perms: $content_file_perms
392395
File folder name: $file_folder_name
@@ -398,7 +401,6 @@ then
398401
fi
399402

400403

401-
402404
# Sanity checks.
403405
################
404406
#

0 commit comments

Comments
 (0)