@@ -70,6 +70,12 @@ cat <<HELP
7070 -n, --dry-run: Perform no action but display information about what would be
7171 done. Use twice for more information.
7272
73+ -k, --skip-checks: Skip filtering by ownership and permissions. Process all
74+ files and directories regardless of their current state. This is faster
75+ when most or all files need fixing, but slower when only a few files
76+ need changes. Useful for initial setup or after major changes affecting
77+ many files.
78+
7379 -h, --help: Display this help message.
7480
7581
@@ -102,7 +108,14 @@ cat <<HELP
102108 owner and Drupal Path. Process an additional content directory at
103109 '../private', relative to the Drupal path.
104110
105- ` basename " $0 " ` -u=deploy -n -n
111+ ` basename " $0 " ` -u=deploy -k
112+
113+ Fix permissions using 'deploy' as owner, and defaults value for group
114+ owner and Drupal Path. Skip filtering checks to process all files
115+ regardless of their current ownership or permissions. This is useful when
116+ setting up a new site or after major permission changes.
117+
118+ ` basename " $0 " ` -u=deploy -n
106119
107120 Display the list of files and directories that would be fixed, using
108121 'deploy' as owner, and default values for group owner and Drupal Path.
@@ -159,24 +172,37 @@ is_drupal_root() {
159172# Globals:
160173# drupal_user: user to own the files and directories.
161174# httpd_group: group to own the files and directories.
175+ # skip_checks: when set to 1, skip ownership filtering.
162176function fix_ownership() {
163177 case $simulate in
164178 0)
165179 # Real action.
166- find " $1 " $detected_vendor_path \( ! -user $drupal_user -o ! -group $httpd_group \) \( -type f -o -type d \) -print0 | xargs -r -0 -L20 chown $drupal_user :$httpd_group
180+ if [ $skip_checks -eq 1 ]; then
181+ find " $1 " $detected_vendor_path \( -type f -o -type d \) -print0 | xargs -r -0 -L20 chown $drupal_user :$httpd_group
182+ else
183+ find " $1 " $detected_vendor_path \( ! -user $drupal_user -o ! -group $httpd_group \) \( -type f -o -type d \) -print0 | xargs -r -0 -L20 chown $drupal_user :$httpd_group
184+ fi
167185 ;;
168186
169187 1)
170188 # Simulate.
171189 printf " \n Items with wrong ownership: "
172- find " $1 " $detected_vendor_path \( ! -user $drupal_user -o ! -group $httpd_group \) \( -type f -o -type d \) -print | wc -l
190+ if [ $skip_checks -eq 1 ]; then
191+ find " $1 " $detected_vendor_path \( -type f -o -type d \) -print | wc -l
192+ else
193+ find " $1 " $detected_vendor_path \( ! -user $drupal_user -o ! -group $httpd_group \) \( -type f -o -type d \) -print | wc -l
194+ fi
173195 ;;
174196
175197 2)
176198 # Simulate verbosely.
177199 printf " \n Files and directories that would have their ownership fixed: "
178200 # Use a variable to indent output.
179- items=$( find " $1 " $detected_vendor_path \( ! -user $drupal_user -o ! -group $httpd_group \) \( -type f -o -type d \) -print)
201+ if [ $skip_checks -eq 1 ]; then
202+ items=$( find " $1 " $detected_vendor_path \( -type f -o -type d \) -print)
203+ else
204+ items=$( find " $1 " $detected_vendor_path \( ! -user $drupal_user -o ! -group $httpd_group \) \( -type f -o -type d \) -print)
205+ fi
180206 items=${items:- None}
181207 printf " \n ${items// $' \n ' / $' \n ' } \n"
182208 ;;
@@ -191,25 +217,40 @@ function fix_ownership() {
191217# Params:
192218# $1 Path to the directory to process.
193219# $2 Type of element to process. f for files, d for directories.
194- # $3 Permissions wanted compatible with chmod . Exmaple: u=rwx,g=rwxs,o=
220+ # $3 Permissions wanted compatible with chmod . Example: u=rwx,g=rwxs,o=
221+ #
222+ # Globals:
223+ # skip_checks: when set to 1, skip permission filtering.
195224function fix_code_permission_helper() {
196225 case $simulate in
197226 0)
198227 # 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
228+ if [ $skip_checks -eq 1 ]; then
229+ find " $1 " \( -path " $1 " /sites/\* /$file_folder_name -prune \) -o \( -path " $1 " /sites/\* /$private_folder_name -prune \) -o \( -type $2 -print0 \) | xargs -r -0 -L4 chmod $3
230+ else
231+ 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
232+ fi
200233 ;;
201234
202235 1)
203236 # 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)
237+ if [ $skip_checks -eq 1 ]; then
238+ num=$( find " $1 " \( -path " $1 " /sites/\* /$file_folder_name -prune \) -o \( -path " $1 " /sites/\* /$private_folder_name -prune \) -o \( -type $2 -print \) | wc -l)
239+ else
240+ 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)
241+ fi
205242 printf " \n Code items with wrong permissions: $num "
206243 ;;
207244
208245 2)
209246 # Simulate verbosely.
210247 printf " \n Code files and directories that would have their permissions fixed: "
211248 # 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 \) )
249+ if [ $skip_checks -eq 1 ]; then
250+ items=$( find " $1 " \( -path " $1 " /sites/\* /$file_folder_name -prune \) -o \( -path " $1 " /sites/\* /$private_folder_name -prune \) -o \( -type $2 -print \) )
251+ else
252+ items=$( find " $1 " \( -path " $1 " /sites/\* /$file_folder_name -prune \) -o \( -path " $1 " /sites/\* /$private_folder_name -prune \) -o \( -type $2 ! -perm $3 -print \) )
253+ fi
213254 items=${items:- None}
214255 printf " \n ${items// $' \n ' / $' \n ' } \n"
215256 ;;
@@ -224,25 +265,40 @@ function fix_code_permission_helper() {
224265# Params:
225266# $1 Path to the directory to process.
226267# $2 Type of element to process. f for files, d for directories.
227- # $3 Permissions wanted compatible with chmod . Exmaple: u=rwx,g=rwxs,o=
268+ # $3 Permissions wanted compatible with chmod . Example: u=rwx,g=rwxs,o=
269+ #
270+ # Globals:
271+ # skip_checks: when set to 1, skip permission filtering.
228272function fix_content_permission_helper() {
229273 case $simulate in
230274 0)
231275 # Real action. Exclude .htaccess files as they should be treated as code.
232- find " $1 " -type $2 ! -name ' .htaccess' ! -perm $3 -print0 | xargs -r -0 -L20 chmod $3
276+ if [ $skip_checks -eq 1 ]; then
277+ find " $1 " -type $2 ! -name ' .htaccess' -print0 | xargs -r -0 -L20 chmod $3
278+ else
279+ find " $1 " -type $2 ! -name ' .htaccess' ! -perm $3 -print0 | xargs -r -0 -L20 chmod $3
280+ fi
233281 ;;
234282
235283 1)
236284 # Simulate.
237- num=$( find " $1 " -type $2 ! -name ' .htaccess' ! -perm $3 -print | wc -l)
285+ if [ $skip_checks -eq 1 ]; then
286+ num=$( find " $1 " -type $2 ! -name ' .htaccess' -print | wc -l)
287+ else
288+ num=$( find " $1 " -type $2 ! -name ' .htaccess' ! -perm $3 -print | wc -l)
289+ fi
238290 printf " \n Content items with wrong permissions: $num "
239291 ;;
240292
241293 2)
242294 # Simulate verbosely.
243295 printf " \n Content files and directories that would have their permissions fixed: "
244296 # Use a variable to indent output.
245- items=$( find " $1 " -type $2 ! -name ' .htaccess' ! -perm $3 -print)
297+ if [ $skip_checks -eq 1 ]; then
298+ items=$( find " $1 " -type $2 ! -name ' .htaccess' -print)
299+ else
300+ items=$( find " $1 " -type $2 ! -name ' .htaccess' ! -perm $3 -print)
301+ fi
246302 items=${items:- None}
247303 printf " \n ${items// $' \n ' / $' \n ' } \n"
248304 ;;
@@ -290,22 +346,35 @@ function fix_code_permissions() {
290346#
291347# Globals:
292348# code_file_perms: permissions scheme to use for code files.
349+ # skip_checks: when set to 1, skip permission filtering.
293350function fix_htaccess_in_content_helper() {
294351 case $simulate in
295352 0)
296353 # Real action.
297- find " $1 " -type f -name ' .htaccess' ! -perm " $code_file_perms " -print0 | xargs -r -0 -L20 chmod " $code_file_perms "
354+ if [ $skip_checks -eq 1 ]; then
355+ find " $1 " -type f -name ' .htaccess' -print0 | xargs -r -0 -L20 chmod " $code_file_perms "
356+ else
357+ find " $1 " -type f -name ' .htaccess' ! -perm " $code_file_perms " -print0 | xargs -r -0 -L20 chmod " $code_file_perms "
358+ fi
298359 ;;
299360
300361 1)
301362 # Simulate.
302- num=$( find " $1 " -type f -name ' .htaccess' ! -perm " $code_file_perms " -print | wc -l)
363+ if [ $skip_checks -eq 1 ]; then
364+ num=$( find " $1 " -type f -name ' .htaccess' -print | wc -l)
365+ else
366+ num=$( find " $1 " -type f -name ' .htaccess' ! -perm " $code_file_perms " -print | wc -l)
367+ fi
303368 [ $num -gt 0 ] && printf " \n .htaccess files with wrong permissions: $num "
304369 ;;
305370
306371 2)
307372 # Simulate verbosely.
308- items=$( find " $1 " -type f -name ' .htaccess' ! -perm " $code_file_perms " -print)
373+ if [ $skip_checks -eq 1 ]; then
374+ items=$( find " $1 " -type f -name ' .htaccess' -print)
375+ else
376+ items=$( find " $1 " -type f -name ' .htaccess' ! -perm " $code_file_perms " -print)
377+ fi
309378 if [ ! -z " $items " ]
310379 then
311380 printf " \n .htaccess files that would have their permissions fixed: "
@@ -358,6 +427,7 @@ additional_files_paths=""
358427file_folder_name=' files'
359428private_folder_name=' private'
360429simulate=0
430+ skip_checks=0
361431
362432
363433# Parse Command Line Arguments
@@ -387,6 +457,9 @@ while [ "$#" -gt 0 ]; do
387457 --dry-run | -n)
388458 simulate=$(( simulate + 1 ))
389459 ;;
460+ --skip-checks | -k)
461+ skip_checks=1
462+ ;;
390463 --help | -h)
391464 usage
392465 exit 0
@@ -445,6 +518,7 @@ Content dirs perms: $content_dir_perms
445518Content files perms: $content_file_perms
446519File folder name: $file_folder_name
447520Private files folder name: $private_folder_name
521+ Skip permission/ownership checks: $( [ $skip_checks -eq 1 ] && echo " Yes (processes all files)" || echo " No (only processes files that need changes)" )
448522"
449523if [ ! -z " ${additional_files_paths} " ]
450524then
0 commit comments