Skip to content

Instantly share code, notes, and snippets.

@flashx
Created April 4, 2012 17:40
Show Gist options
  • Save flashx/2304170 to your computer and use it in GitHub Desktop.
Save flashx/2304170 to your computer and use it in GitHub Desktop.
bash script
#!/bin/bash -x
set -e -u
set -o pipefail
# Variables
DB_NAME="$1"
DB_USER="$2"
DB_PASS="$3"
DB_ADMIN="$4"
ADMIN_PASS="$5"
# Getting WP Files
wget http://wordpress.org/latest.zip
unzip -q latest.zip
mv wordpress/* ./
rmdir ./wordpress/
rm -f latest.zip
cd wp-content
wget https://raw.github.com/gist/2321659/c0c6d38180c392c45a0e976460ac3bfa70e2e6ac/install.php
cd plugins
wget https://github.com/dealertrend/wordpress-plugin-inventory-api/zipball/production
unzip -q production
rm -f production
cd ../
cd themes
wget http://thecloud99.com/customchildtheme.zip
unzip -q customchildtheme.zip
rm customchildtheme.zip
cd ../../
# Create + Customize WP-Config
sed -e 's/database_name_here/'$DB_NAME'/' \
-e 's/username_here/'$DB_USER'/' \
-e 's/password_here/'$DB_PASS'/' < wp-config-sample.php > wp-config.php
# Create DB
mysql -u "$DB_ADMIN" --password="$ADMIN_PASS" <<EOF
CREATE DATABASE $DB_NAME;
CREATE USER $DB_USER;
GRANT ALL ON $DB_NAME.* TO $DB_USER@localhost IDENTIFIED BY '$DB_PASS';
FLUSH PRIVILEGES;
EOF
# Get + Customize SQL
wget https://raw.github.com/gist/2347184/49f21561afeacb8044b247765f8087d9fdc57c6b/db.sql
sed -e 's/blog_name_here/'$DB_NAME'/g' \
-e 's/user_name_here/'$DB_USER'/g' \
-e 's/pass_here/'$DB_PASS'/g' < db.sql > wp.sql
rm db.sql
# Import SQL
mysql -u "$DB_USER" --password="$DB_PASS" $DB_NAME < wp.sql
rm wp.sql
# Convert password to MD5
mysql -u "$DB_ADMIN" --password="$ADMIN_PASS" $DB_NAME <<EOF
UPDATE $DB_NAME.wp_users SET user_pass = MD5( '$DB_PASS' ) WHERE wp_users.ID =1;
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment