Skip to content

Instantly share code, notes, and snippets.

@mdrmike
Last active November 15, 2017 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mdrmike/ebb914947a0e36aac14e1d983a8e8b76 to your computer and use it in GitHub Desktop.
Save mdrmike/ebb914947a0e36aac14e1d983a8e8b76 to your computer and use it in GitHub Desktop.
#!/bin/bash -ex
# SETUP PERMISSIONS
VPATH=${1%/}
GROUP_WEBWORK=${2}
WEBSERVER="www-data"
HELP="\nHelp: This script is used to fix permissions\nPlease provide the following arguments:\n\t 1) Path to web root\n\t 2) Shared workgroup of website. AKA group ownership\nNote: \"www-data\" (apache default) is assumed as the owner of the web files.\n\nUsage: [sudo] bash ${0##*/} [web_root_path] [group_name]\n"
[ -z "$VPATH" ] && VPATH=`pwd` # is null, use present dir
[ -z "$GROUP_WEBWORK" ] && GROUP_WEBWORK=webwork # is null, set default
echo -e "\n\n\nNOTICE!!!"
echo -e "Changing permissions of: $VPATH"
echo -e " and workgroup: $GROUP_WEBWORK\n"
echo -n "This action cannot be undone. Proceed? [y/N] "
read action
if [ -z "${action}" ] || [[ "${action}" != [yY] ]]; then
echo "Exiting ..."
echo -e $HELP
exit
else
echo -e "PROCEEDING ...\n\n"
fi
cd $path;
# SETUP APACHE AS USER:GROUP
chown -R www-data:"$GROUP_WEBWORK" "$VPATH"
# How to read command:
# https://en.wikipedia.org/wiki/File_system_permissions#Symbolic_notation
# https://en.wikipedia.org/wiki/Chmod#Octal_modes
find "$VPATH" -type f | xargs chmod ug=r,o= #=440 #660 adds write
find "$VPATH" -type d | xargs chmod ug=rX,o= #=550 #770 adds write
find "$VPATH/wp-content" -type f | xargs chmod ug=rw,o= #=440 #660 adds write
find "$VPATH/wp-content" -type d | xargs chmod ug=rwX,o= #=550 #770 adds write
find "$VPATH" -type d | xargs chmod g+s # setgid: new files inherit parent dir perms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment