Skip to content

Instantly share code, notes, and snippets.

@jdavidbakr
Last active December 7, 2017 17:02
Show Gist options
  • Save jdavidbakr/4e2a47fb75eee9a444ff452a8c6cd1a7 to your computer and use it in GitHub Desktop.
Save jdavidbakr/4e2a47fb75eee9a444ff452a8c6cd1a7 to your computer and use it in GitHub Desktop.
Script to repair website permissions
#!/bin/bash
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
nice /bin/find ./ -perm 644 | sed 's/.*/"&"/' | xargs -r chmod 664
nice /bin/find ./ -perm 755 | sed 's/.*/"&"/' | xargs -r chmod 2775
nice /bin/find ./ -perm 2755 | sed 's/.*/"&"/' | xargs -r chmod 2775
nice /bin/find ./ -perm 600 | sed 's/.*/"&"/' | xargs -r chmod 664
nice /bin/find ./ -perm 700 | sed 's/.*/"&"/' | xargs -r chmod 2775
nice /bin/find ./ -perm 2700 | sed 's/.*/"&"/' | xargs -r chmod 2775
nice /bin/find ./ \! -group apache | sed 's/.*/"&"/' | xargs -r chgrp apache
sleep 1
fi
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment