diff --git a/bin/fix-permissions b/bin/fix-permissions index 6cd6a024..35355388 100755 --- a/bin/fix-permissions +++ b/bin/fix-permissions @@ -3,11 +3,21 @@ # Allow this script to fail without failing a build set +e -# Fix permissions on the given directory to allow group read/write of +# Fix permissions on the given directory or file to allow group read/write of # regular files and execute of directories. -chgrp -R 0 $1; -find -L $1 -xtype l -exec chgrp 0 {} \; -chmod -R g+rw $1; -find -L $1 -xtype l -exec chmod g+rw {} \; -find $1 -type d -exec chmod g+x {} + + +# If argument does not exist, script will still exit with 0, +# but at least we'll see something went wrong in the log +if ! [ -e "$1" ] ; then + echo "ERROR: File or directory $1 does not exist." >&2 + # We still want to end successfully + exit 0 +fi + +find -L "$1" \! -gid 0 -exec chgrp 0 {} + +find -L "$1" \! -perm /g+rw -exec chmod g+rw {} + +find -L "$1" -perm /u+x -a \! -perm /g+x -exec chmod g+x {} + +find -L "$1" -type d \! -perm /g+x -exec chmod g+x {} + + +# Always end successfully exit 0