Skip to content

Instantly share code, notes, and snippets.

@jasonraimondi
Created October 15, 2015 02:31
Show Gist options
  • Save jasonraimondi/b5245f80205aedb0b75c to your computer and use it in GitHub Desktop.
Save jasonraimondi/b5245f80205aedb0b75c to your computer and use it in GitHub Desktop.
#!/bin/bash
echo -n 'Are you in the root of the WordPress install? [Y/n]:'
read wproot
echo -n "WordPress Owner: "
read wpowner
echo -n "WordPress Group: "
read wpgroup
echo -n "WebServer Group: "
read webgroup
echo -n "Are you ready? [y/N]: "
read ready
if [[ "$wproot" != "n" ]]; then
WP_ROOT=$PWD
fi
if [[ "$wpowner" != "" ]]; then
WP_OWNER=$wpowner
fi
if [[ "$wpgroup" != "" ]]; then
WP_GROUP=$wpgroup
fi
if [[ "$webgroup" != "" ]]; then
WS_GROUP=$webgroup
fi
if [[ "$ready" == "y" ]]; then
# reset to safe defaults
find ${WP_ROOT} -exec chown ${WP_OWNER}:${WP_GROUP} {} \;
find ${WP_ROOT} -type d -exec chmod 775 {} \;
find ${WP_ROOT} -type f -exec chmod 664 {} \;
# allow wordpress to manage wp-config.php (but prevent world access)
chgrp ${WS_GROUP} ${WP_ROOT}/wp-config.php
chmod 660 ${WP_ROOT}/wp-config.php
# allow wordpress to manage .htaccess
touch ${WP_ROOT}/.htaccess
chgrp ${WS_GROUP} ${WP_ROOT}/.htaccess
chmod 664 ${WP_ROOT}/.htaccess
# allow wordpress to manage wp-content
find ${WP_ROOT}/wp-content -exec chgrp ${WS_GROUP} {} \;
find ${WP_ROOT}/wp-content -type d -exec chmod 775 {} \;
find ${WP_ROOT}/wp-content -type f -exec chmod 664 {} \;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment