Skip to content

Instantly share code, notes, and snippets.

@MiquelAdell
Created May 27, 2016 12:55
Show Gist options
  • Save MiquelAdell/4f578d20aa2490e1dc84bda8cc939465 to your computer and use it in GitHub Desktop.
Save MiquelAdell/4f578d20aa2490e1dc84bda8cc939465 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
USER="miqueladell";
GROUP="www-data";
# Make sure only root can run our script
function execute {
printf "$1\n";
if eval "$1"; then
printf " \e[32;1mOK\033[0m\n";
else
printf " \e[31;1mKO\033[0m\n" 1>&2;
exit 1;
fi
}
if [[ $EUID -ne 0 ]]; then
printf "\e[31mThis script must be run as root\033[0m\n" 1>&2;
exit 1;
else
execute "find $DIR/wp-content \! -user $USER -exec echo {} + -exec chown miqueladell {} \;";
execute "find $DIR/wp-content \! -group $GROUP -exec echo {} + -exec chgrp www-data {} \;";
execute "find $DIR/wp-content -type d -not -perm 775 -exec echo {} + -exec chmod 775 {} \;";
execute "find $DIR/wp-content -type f -not -perm 664 -exec echo {} + -exec chmod 664 {} \;";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment