Created
August 7, 2017 20:14
-
-
Save jdavidbakr/18eb18ee6eb26d1f65637beb7ef83ae8 to your computer and use it in GitHub Desktop.
Script to fix website permissions when multiple users are publishing with npm install + deployer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Run this script on a regular basis to clean up permissions in all website projects. | |
# It makes sure all files are group-writable, and that the group is apache. | |
# The lock file prevents it from running on top of another process. | |
LOCK_FILE=/tmp/permission-repair-lock | |
if [ ! -e $LOCK_FILE ]; then | |
trap "rm -f $LOCK_FILE; exit" 0 1 2 3 15 | |
touch $LOCK_FILE | |
for d in /var/www/html/* | |
do | |
cd $d | |
if [ -d releases ]; then | |
echo Searching in $d ... | |
nice /bin/find ./releases/ -perm 644 | sed 's/.*/"&"/' | xargs -r chmod 664 | |
nice /bin/find ./releases/ -perm 755 | sed 's/.*/"&"/' | xargs -r chmod 775 | |
nice /bin/find ./releases/ -perm 600 | sed 's/.*/"&"/' | xargs -r chmod 664 | |
nice /bin/find ./releases/ -perm 700 | sed 's/.*/"&"/' | xargs -r chmod 755 | |
nice /bin/find ./releases/ \! -group apache | sed 's/.*/"&"/' | xargs -r chgrp apache | |
echo Done. | |
sleep 5 | |
fi | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment