Skip to content

Instantly share code, notes, and snippets.

@JacobDB
Last active June 23, 2017 16:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Small script to fix web permissions
#!/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