Skip to content

Instantly share code, notes, and snippets.

@joshcanhelp
Created April 18, 2018 21:51
Show Gist options
  • Select an option

  • Save joshcanhelp/59906908ac1cd22e50b9ae186f04bf23 to your computer and use it in GitHub Desktop.

Select an option

Save joshcanhelp/59906908ac1cd22e50b9ae186f04bf23 to your computer and use it in GitHub Desktop.
Generate a WP-Auth0 testing platform with PHP and MySQL already installed
#!/usr/bin/env bash
#
# Check for flags
#
# -d will use all default values
USE_DEFAULTS=false;
# -r will reset the install first (delete the DB and files)
DO_RESET=false;
while getopts 'dr' flag; do
case "${flag}" in
d) USE_DEFAULTS=true ;;
r) DO_RESET=true ;;
esac
done
#
# Variables
#
DEFAULT_DB_NAME="${DEFAULT_DB_NAME:-wp_test_fixture}"
DEFAULT_DB_USER="${DEFAULT_DB_USER:-root}"
DEFAULT_DB_PASS="$DEFAULT_DB_PASS"
# Pulls from environment variables
DEFAULT_ADMIN_EMAIL="$DEFAULT_ADMIN_EMAIL"
DEFAULT_ADMIN_PASS="$DEFAULT_ADMIN_PASS"
DEFAULT_ADMIN_AUTH0_ID="$DEFAULT_ADMIN_AUTH0_ID"
DEFAULT_AUTH0_DOMAIN="$DEFAULT_WP_AUTH0_DOMAIN"
DEFAULT_AUTH0_CLIENT_ID="$DEFAULT_WP_AUTH0_CLIENT_ID"
DEFAULT_AUTH0_CLIENT_SECRET="$DEFAULT_WP_AUTH0_CLIENT_SECRET"
if [ "$USE_DEFAULTS" = true ] ; then
DB_NAME="$DEFAULT_DB_NAME"
DB_USER="$DEFAULT_DB_USER"
DB_PASS="$DEFAULT_DB_PASS"
ADMIN_EMAIL="$DEFAULT_ADMIN_EMAIL"
ADMIN_PASS="$DEFAULT_ADMIN_PASS"
ADMIN_AUTH0_ID="$DEFAULT_ADMIN_AUTH0_ID"
AUTH0_DOMAIN="$DEFAULT_AUTH0_DOMAIN"
AUTH0_CLIENT_ID="$DEFAULT_AUTH0_CLIENT_ID"
AUTH0_CLIENT_SECRET="$DEFAULT_AUTH0_CLIENT_SECRET"
else
read -e -p "Enter the database name ($DEFAULT_DB_NAME): " DB_NAME
DB_NAME="${DB_NAME:-$DEFAULT_DB_NAME}"
read -e -p "Enter the database username ($DEFAULT_DB_USER): " DB_USER
DB_USER="${DB_USER:-$DEFAULT_DB_USER}"
read -e -p "Enter the database password ($DEFAULT_DB_PASS): " DB_PASS
DB_PASS="${DB_PASS:-$DEFAULT_DB_PASS}"
read -e -p "Enter the WP admin email ($DEFAULT_ADMIN_EMAIL): " ADMIN_EMAIL
ADMIN_EMAIL="${ADMIN_EMAIL:-$DEFAULT_ADMIN_EMAIL}"
read -e -p "Enter the WP admin password ($DEFAULT_ADMIN_PASS): " ADMIN_PASS
ADMIN_PASS="${ADMIN_PASS:-$DEFAULT_ADMIN_PASS}"
read -e -p "Enter the WP admin Auth0 ID: " ADMIN_AUTH0_ID
read -e -p "Enter the Auth0 Domain: " AUTH0_DOMAIN
read -e -p "Enter the Auth0 Client ID: " AUTH0_CLIENT_ID
read -e -p "Enter the Auth0 Client Secret: " AUTH0_CLIENT_SECRET
fi
if [ "$DO_RESET" = true ] ; then
mysql -uroot -e "DROP DATABASE $DB_NAME;";
rm -rf wp-auth0;
fi
# make the working dir
mkdir wp-auth0;
cd wp-auth0;
# get wp-cli
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
# download and install wp-auth0
php wp-cli.phar core download --skip-content --force;
cp ./wp-config-sample.php ./wp-config.php;
mysql -uroot -e "CREATE DATABASE $DB_NAME /*\!40100 DEFAULT CHARACTER SET utf8 */;";
mysql -uroot -e "GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'localhost';";
mysql -uroot -e "FLUSH PRIVILEGES;"
php wp-cli.phar config set DB_NAME "$DB_NAME";
php wp-cli.phar config set DB_USER "$DB_USER";
php wp-cli.phar config set DB_PASSWORD "$DB_PASS";
php wp-cli.phar config set DB_HOST "localhost";
php wp-cli.phar config set WP_DEBUG true;
php wp-cli.phar core install --url=http://wp.localhost.test \
--title="Auth0 ♥ WordPress" \
--admin_user="$ADMIN_EMAIL" \
--admin_email="$ADMIN_EMAIL" \
--admin_password="$ADMIN_PASS" --skip-email;
# set various wp options
php wp-cli.phar rewrite structure "/%postname%/";
php wp-cli.phar rewrite flush;
echo "<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>" >> .htaccess;
php wp-cli.phar option update users_can_register 1;
# install the test theme, which comes with wp-cli commands
git clone https://github.com/joshcanhelp/auth0-wp-test.git wp-content/themes/auth0-wp-test;
php wp-cli.phar theme activate auth0-wp-test;
php wp-cli.phar auth0 make_test_pages;
# clone and activate the plugin
git clone https://github.com/auth0/wp-auth0.git wp-content/plugins/auth0;
php wp-cli.phar plugin activate auth0;
if [ ! -z "$ADMIN_AUTH0_ID" ]; then
php wp-cli.phar user meta add 1 auth0_id "$ADMIN_AUTH0_ID"
fi
if [ ! -z "$AUTH0_DOMAIN" ]; then
php wp-cli.phar auth0 set_opt domain "$AUTH0_DOMAIN"
fi
if [ ! -z "$AUTH0_DOMAIN" ]; then
php wp-cli.phar auth0 set_opt client_id "$AUTH0_CLIENT_ID"
fi
if [ ! -z "$AUTH0_CLIENT_SECRET" ]; then
php wp-cli.phar auth0 set_opt client_secret "$AUTH0_CLIENT_SECRET"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment