Skip to content

Instantly share code, notes, and snippets.

@JacobDB
Last active June 23, 2017 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JacobDB/01215d8e4bebc952fcba4ffbf40bad82 to your computer and use it in GitHub Desktop.
Save JacobDB/01215d8e4bebc952fcba4ffbf40bad82 to your computer and use it in GitHub Desktop.
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