Created
August 5, 2015 14:08
-
-
Save StefanNyman/c66678d74316e3cf94f8 to your computer and use it in GitHub Desktop.
This file contains 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/bash | |
# Fail on command non zero return code | |
set -e | |
TXT_BOLD=$(tput bold) | |
TXT_RESET=$(tput sgr0) | |
function log { | |
echo "" | |
echo "${TXT_BOLD}$1${TXT_RESET}" | |
echo "" | |
} | |
RECIPE_DIR="recipe-sh-wordpress" | |
# Clean install environment | |
log "Cleaning /app/code/" | |
# Enable extglob extension for easy matching | |
shopt -s extglob | |
rm -rf ../!($RECIPE_DIR) | |
# Disable extglob again | |
shopt -u extglob | |
# Install required daemons | |
log "Installing required daemons" | |
jumpstart -Sy --noconfirm php5 nginx nodejs | |
CODE_DIR="/app/code" | |
# Configure nginx to use two workers | |
log "Configuring nginx" | |
FILE=$CODE_DIR/php5/php-fpm.conf | |
sed -i "s/pm.max_children = 1/pm.max_children = 2/" $FILE | |
sed -i "s/pm.start_servers = 1/pm.start_servers = 2/" $FILE | |
sed -i "s/pm.max_spare_servers = 1/pm.max_spare_servers = 2/" $FILE | |
# Check out the init daemon | |
log "Checking out init daemon" | |
git clone https://github.com/jumpstarter-io/js-init.git $CODE_DIR/js-init | |
ln -s $CODE_DIR/js-init/init.js $CODE_DIR/init | |
# Check out Jumpstarter php env integration | |
log "Checking out js php env integration" | |
git clone https://github.com/jumpstarter-io/js-php-env.git $CODE_DIR/js-php-env | |
# Install the daemons.json | |
log "Installing daemons.json" | |
cp daemons.json $CODE_DIR/daemons.json | |
# Install the nginx.conf tailored for WordPress | |
log "Installing WordPress nginx.conf" | |
cp nginx.conf $CODE_DIR/nginx/nginx.conf | |
### | |
# LEGACY: remove when packages has been updated | |
### | |
log "Legacy stage" | |
TARGET=$CODE_DIR/nginx/pre-exec | |
cp nginx_pre-exec $TARGET | |
chmod +x $TARGET | |
FILE=$CODE_DIR/php5/php.ini | |
sed -i "s#session.save_path = \"/app/state/php-sessions\"#session.save_path = \"$CODE_DIR/run/php5/php-sessions\"#" $FILE | |
TARGET=$CODE_DIR/php5/pre-exec | |
cp php5_pre-exec $TARGET | |
chmod +x $TARGET | |
### | |
# LEGACY: remove above when updated packages. | |
### | |
# Checkout WordPress | |
log "Checking out WordPress" | |
SRC_DIR=$CODE_DIR/src | |
git clone --depth 1 --branch 4.2-branch https://github.com/WordPress/WordPress.git $SRC_DIR | |
WP_CONTENT_DIR=$SRC_DIR/wp-content | |
WP_PLUGINS_DIR=$WP_CONTENT_DIR/plugins | |
WP_THEMES_DIR=$WP_CONTENT_DIR/themes | |
# Checkout sqlite plugin | |
log "Checking out WordPress sqlite plugin" | |
SQLITE_PLUGIN_DIR=$WP_PLUGINS_DIR/sqlite-integration | |
git clone https://github.com/jumpstarter-io/wp-sqlite-integration.git $SQLITE_PLUGIN_DIR | |
mv $SQLITE_PLUGIN_DIR/db.php $WP_CONTENT_DIR/db.php | |
# Checkout the Jumpstarter WordPress plugin | |
log "Checking out WordPress Jumpstarter integration plugin" | |
git clone --branch=ftr-v2 https://github.com/jumpstarter-io/wp-jumpstarter.git $WP_PLUGINS_DIR/jumpstarter | |
# Prepare WordPress | |
log "Preparing WordPress" | |
mv $SRC_DIR/wp-config-sample.php $SRC_DIR/wp-config.php | |
WP_CONF=$SRC_DIR/wp-config.php | |
sed -i -r "/define\('DB_COLLATE', ''\);/a define\('DB_DIR', '$CODE_DIR/wp-db'\);" $WP_CONF | |
# Install the portals file | |
log "Installing portals.json" | |
cp portals.json $CODE_DIR/portals.json | |
# Install the wp-env file | |
log "Installing wp-env.json" | |
cp wp-env.json $CODE_DIR/wp-env.json | |
# Create a cleanup file to run after successful deploy | |
log "Creating cleanup file" | |
CLEANUP_FILE=cleanup.sh | |
CLEANUP_REL=../cleanup.sh | |
cat > $CLEANUP_REL <<EOF | |
#!/bin/bash | |
rm -rf /app/code/{$RECIPE_DIR,.config,.emacs.d,wp-db,$CLEANUP_FILE} | |
echo "Cleanup done, exiting" | |
sleep 3 | |
kill -HUP $PPID | |
EOF | |
chmod +x $CLEANUP_REL | |
log "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment