Last active
November 10, 2016 19:31
-
-
Save manelio/2c674bedc0d046d68712 to your computer and use it in GitHub Desktop.
Install wordpress with the Bedrock stack totally from command line, even the generation of keys and salts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # | |
| # YOU CAN USE THIS SCRIPT AS A COMMAND OR JUST COPY AND PASTE THE WHOLE SCRIPT IN TERMINAL | |
| # | |
| <<'COMMENT' | |
| Requirements: | |
| A directory with at least 2 files: .env and setuprc | |
| Examples: | |
| cat <<'EOF' > .env | |
| ### BEGIN FILE .env | |
| DB_NAME=myawesomeblog | |
| DB_USER=dbuser | |
| DB_PASSWORD=dbpassword | |
| DB_HOST=localhost | |
| WP_ENV=development | |
| WP_HOME=http://myawesomeblog.com | |
| WP_SITEURL=${WP_HOME}/wp | |
| ### END FILE .env | |
| EOF | |
| cat <<'EOF' > setuprc | |
| ### BEGIN FILE setuprc | |
| TITLE="My Awesome Blog" | |
| ADMIN_USER="admin" | |
| ADMIN_PASSWORD="somestrongpassword" | |
| ADMIN_EMAIL="manel@manel.io" | |
| # add additional composer packages, if you want | |
| COMPOSER_PACKAGES=$(cat <<'EOT' | |
| "wpackagist-theme/twentysixteen": "1.1" | |
| wpackagist-plugin/akismet | |
| EOT | |
| ) | |
| ### END FILE setuprc | |
| EOF | |
| COMMENT | |
| ### | |
| # Get bedrock from git repo | |
| ### | |
| git init | |
| git remote add origin https://github.com/roots/bedrock.git | |
| git fetch | |
| git checkout -t origin/master | |
| ### | |
| # Check for composer in path and install it if it doesn't exists | |
| ### | |
| if which composer > /dev/null; then export COMPOSERCMD=composer; \ | |
| elif which composer.phar > /dev/null; then COMPOSERCMD=composer.phar; \ | |
| else wget -qO composer.phar "https://getcomposer.org/composer.phar" && chmod +x ./composer.phar && COMPOSERCMD=./composer.phar; \ | |
| fi | |
| ### | |
| # Check for wp-cli in path and install it if it doesn't exists | |
| ### | |
| if which wp > /dev/null; then export WPCLICMD=wp; \ | |
| else $COMPOSERCMD require wp-cli/wp-cli && WPCLICMD=vendor/bin/wp; \ | |
| fi | |
| ### | |
| # Use composer to install required packages | |
| ### | |
| $COMPOSERCMD install | |
| $COMPOSERCMD require aaemnnosttv/wp-cli-dotenv-command | |
| ### | |
| # Install Wordpress | |
| ### | |
| ( | |
| . ./.env; . ./setuprc; | |
| $WPCLICMD core install \ | |
| --url="$WP_HOME" \ | |
| --title="$TITLE" \ | |
| --admin_user="$ADMIN_USER" \ | |
| --admin_password="$ADMIN_PASSWORD" \ | |
| --admin_email="$ADMIN_EMAIL" \ | |
| ) | |
| ### | |
| # Generate keys and salts | |
| ### | |
| $WPCLICMD dotenv salts regenerate | |
| ### | |
| # Install additional composer packages | |
| ### | |
| (. ./setuprc | |
| if [ -z ${COMPOSER_PACKAGES+x} ]; then COMPOSER_PACKAGES=""; fi | |
| echo "$COMPOSER_PACKAGES" | while read -r PACKAGE; do | |
| PACKAGE=$(echo $PACKAGE | sed -e "s/[ \n\r\t\"]\+//g") | |
| if [ "$PACKAGE" ]; then | |
| $COMPOSERCMD require $PACKAGE | |
| fi | |
| done | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment