Skip to content

Instantly share code, notes, and snippets.

@jsoningram
Last active August 29, 2015 14:05
Show Gist options
  • Save jsoningram/0a6ed100ee274da33d57 to your computer and use it in GitHub Desktop.
Save jsoningram/0a6ed100ee274da33d57 to your computer and use it in GitHub Desktop.
Install WordPress and Zurb Foundation
#!/bin/bash
# Install WordPress and Zurb Foundation
# Usage: wpbase <dirname> <themename>
# Installs into ~/$local/$dir
dir=$1
theme=$2
# Define local server dir
local="www"
# Set table prefix
random_number=$RANDOM
sep='_'
table_prefix=$theme$random_number$sep
# Set production info
dbpass=$(env LC_CTYPE=C tr -dc "a-zA-Z0-9&*(){}_+?><~;\!@#$%^" < /dev/urandom | head -c 15)
dbun=$RANDOM$theme
# Get secret keys
curl https://api.wordpress.org/secret-key/1.1/salt/ > ~/$local/$dir/keys.txt
# Install latest WP
cd ~/$local/$dir
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mv wordpress/* ~/$local/$dir
# Install _s
git clone https://github.com/Automattic/_s.git ~/$local/$dir/wp-content/themes/$theme
# Download bower file from gist
cd ~/$local/$dir/wp-content/themes/$theme/
git clone https://gist.github.com/19a995445b52786194e5.git
mv ~/$local/$dir/wp-content/themes/$theme/19a995445b52786194e5/bower.json ~/$local/$dir/wp-content/themes/$theme/bower.json
# Download package file for gulp from gist
cd ~/$local/$dir/wp-content/themes/$theme/
git clone https://gist.github.com/d1cf5b837a6831136599.git
mv ~/$local/$dir/wp-content/themes/$theme/d1cf5b837a6831136599/package.json ~/$local/$dir/wp-content/themes/$theme/package.json
# Download wp-config from gist
cd ~/$local/$dir
git clone https://gist.github.com/b3313c7457647cb0544c.git
mv ~/$local/$dir/b3313c7457647cb0544c/wp-config.php ~/$local/$dir/wp-config.php
# Download Foundation init from gist
cd ~/$local/$dir/wp-content/themes/$theme/js
git clone https://gist.github.com/d8958509b2dccaf5e2ff.git
mv ~/$local/$dir/wp-content/themes/$theme/js/d8958509b2dccaf5e2ff/foundation-init.js ~/$local/$dir/wp-content/themes/$theme/js/foundation-init.js
# Namespace theme
cd ~/$local/$dir/wp-content/themes/$theme
find -E . -regex '.*\.(php|css|scss)' -print0 | xargs -0 sed -i '' -e "s/'_s'/'$theme'/g"
find -E . -regex '.*\.(php|css|scss)' -print0 | xargs -0 sed -i '' -e "s/_s_/${theme}_/g"
find -E . -regex '.*\.(php|css|scss)' -print0 | xargs -0 sed -i '' -e "s/Text Domain: _s/Text Domain: $theme/g"
find -E . -regex '.*\.(php|css|scss)' -print0 | xargs -0 sed -i '' -e "s/ _s/ $theme/g"
find -E . -regex '.*\.(php|css|scss)' -print0 | xargs -0 sed -i '' -e "s/_s-/${theme}-/g"
# Structure
mkdir ~/$local/$dir/wp-content/themes/$theme/fonts
mkdir ~/$local/$dir/wp-content/themes/$theme/css
mkdir ~/$local/$dir/wp-content/themes/$theme/images
mkdir ~/$local/$dir/wp-content/themes/$theme/images/working
mkdir ~/$local/$dir/wp-content/themes/$theme/images/source
touch ~/$local/$dir/wp-content/themes/$theme/css/googlefonts.css
# Create .bowerrc in theme folder
echo '{"directory" : "components"}' > ~/$local/$dir/wp-content/themes/$theme/.bowerrc
# Create base .gitignore in theme folder
echo '.DS_STORE
/components
/bower_components
/node_modules
/images/source
/images/working' > ~/$local/$dir/wp-content/themes/$theme/.gitignore
# Install components
cd ~/$local/$dir/wp-content/themes/$theme/
bower install
# Create empty Git repo in the theme directory
git init ~/$local/$dir/wp-content/themes/$theme/
# Set local HTTP_HOST
sed -i "" "s/%%INSTALL_DIR%%/${dir}/g" ~/$local/$dir/wp-config.php
# Set default theme
sed -i "" "s/%%DEFAULT_THEME%%/${theme}/g" ~/$local/$dir/wp-config.php
# Set DB, DB user and pass (include "" after -i for OS X)
sed -i "" "s/DEV_DBNAME/${theme}/g" ~/$local/$dir/wp-config.php
sed -i "" "s/DEV_DBUSER/${theme}/g" ~/$local/$dir/wp-config.php
sed -i "" "s/DEV_DBPASS/${theme}/g" ~/$local/$dir/wp-config.php
sed -i "" "s/PRODUCTION_DBNAME/${dbun}/g" ~/$local/$dir/wp-config.php
sed -i "" "s/PRODUCTION_DBUSER/${dbun}/g" ~/$local/$dir/wp-config.php
sed -i "" "s/PRODUCTION_DBPASS/${dbpass}/g" ~/$local/$dir/wp-config.php
# Set secret keys
cd ~/$local/$dir
sed -i "" "/%%SECRET_KEYS%%/{
s/%%SECRET_KEYS%%//g
r keys.txt
}" ~/$local/$dir/wp-config.php
# Set table prefix
sed -i "" "s/%%REPLACEPREFIX_%%/${table_prefix}/g" ~/$local/$dir/wp-config.php
# Cleanup
rm ~/$local/$dir/latest.tar.gz
rm ~/$local/$dir/wp-config-sample.php
rm -rf ~/$local/$dir/wordpress
rm -rf ~/$local/$dir/b3313c7457647cb0544c/
rm -rf ~/$local/$dir/wp-content/themes/$theme/js/d8958509b2dccaf5e2ff/
rm -rf ~/$local/$dir/wp-content/themes/$theme/19a995445b52786194e5/
rm -rf ~/$local/$dir/wp-content/themes/$theme/d1cf5b837a6831136599/
rm -rf ~/$local/$dir/wp-content/themes/twenty*
rm -rf ~/$local/$dir/wp-content/themes/$theme/.git
rm ~/$local/$dir/wp-content/themes/$theme/CONTRIBUTING.md
rm ~/$local/$dir/keys.txt
# Verify wp-config
cat ~/$local/$dir/wp-config.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment