Skip to content

Commit

Permalink
Avoid errors when the process does not have enough permissions to cha…
Browse files Browse the repository at this point in the history
…nge attributes

Closes sclorg#112, closes sclorg#123
  • Loading branch information
hhorak authored and pkubatrh committed Jun 20, 2017
1 parent ee76c59 commit 47dd175
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions bin/fix-permissions
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 47dd175

Please sign in to comment.