Last active
June 23, 2017 16:11
-
-
Save JacobDB/01215d8e4bebc952fcba4ffbf40bad82 to your computer and use it in GitHub Desktop.
Small script to fix web permissions
This file contains 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 | |
directory=$1 | |
if [ "$directory" == "" ] | |
then | |
echo -e $"${0##*/}: missing operand" | |
exit 1; | |
fi; | |
if ! [[ -r "$directory" && -w "$directory" ]] | |
then | |
echo -e $"${0##*/}: cannot fix web permissions on '$directory': Permission denied" | |
exit 1; | |
fi | |
if ! chown -R www-data:www-data $directory | |
then | |
echo -e $"${0##*/}: changing ownership failed" | |
exit; | |
fi | |
if ! find $directory -type f -exec chmod 644 {} \; | |
then | |
echo -e $"${0##*/}: Setting file permissions failed" | |
exit; | |
fi | |
if ! find $directory -type d -exec chmod 755 {} \; | |
then | |
echo -e $"${0##*/}: Setting directory permissions failed" | |
exit; | |
fi | |
echo -e $"${0##*/}: ownership and permissions have been set for web use at \"$directory\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment