diff --git a/cleanup_samba_rights.sh b/cleanup_samba_rights.sh index 2bec6e9..e0aede1 100755 --- a/cleanup_samba_rights.sh +++ b/cleanup_samba_rights.sh @@ -2,25 +2,26 @@ base_dir=$1 group=$2 -dir_perm=2775 -#dir_perm="u=rwx,g=rwx,o=rx,g+s" -file_perm=664 + +file_perm=${3:-664} +dir_perm=${4:-2775} chmod $dir_perm $base_dir chgrp $group $base_dir while IFS='' read -r -d '' filename ; do - [ -f "$filename" ] && ( chmod $file_perm "$filename"; chgrp $group $"$filename") - [ ! -d "$filename" ] && continue + [[ -f "$filename" ]] && ( chmod $file_perm "$filename"; chgrp $group "$filename") + [[ ! -d "$filename" ]] && continue - [ "$filename" = "lost+found" ] && continue + [[ "$filename" =~ .Trash ]] && continue + [[ "$filename" = "lost+found" ]] && continue chmod $dir_perm "$filename" ; chgrp $group "$filename" - find "$filename" -exec chgrp -R $group {} \; - find "$filename" -type d -exec chmod -R $dir_perm {} \; - find "$filename" -type f -exec chmod -R $file_perm {} \; + find "$filename" ! -group $group -exec chgrp -R $group {} \; + find "$filename" -type d ! -perm $dir_perm -exec chmod -R $dir_perm {} \; + find "$filename" -type f ! -perm $file_perm -exec chmod -R $file_perm {} \; done < <(find $base_dir -mindepth 1 -maxdepth 1 -print0)