Skip to content

Instantly share code, notes, and snippets.

@tecking tecking/setup.sh

Last active Dec 27, 2015
Embed
What would you like to do?
WordPress installation script using WP-CLI (require: Vagrant and VVV (Varying Vagrant Vagrants) ).
#!/bin/sh
#
# Enter arguments.
#
echo "Enter some arguments for installation."
while true; do
echo -n "Target directory? (e.g., /vagrant/www/foo) : "
read TARGET_DIR
if [ ! -d $TARGET_DIR ]; then
echo "Target directory doesn't exist! Try again."
else
break
fi
done
echo -n "DB host? (default = localhost) : "
read DB_HOST
echo -n "DB name? : "
read DB_NAME
echo -n "DB user? : "
read DB_USER
echo -n "DB password? : "
read DB_PASSWORD
echo -n "Site URL? (e.g., http://www.example.com) : "
read SITE_URL
echo -n "Site title? : "
read SITE_TITLE
echo -n "Admin name? : "
read ADMIN_NAME
echo -n "Admin password? : "
read ADMIN_PASSWORD
echo -n "Admin email? : "
read ADMIN_EMAIL
echo -n "Import theme unit test data(ja)? (y/n) : "
read IMPORT_DATA
while true; do
echo -n "Generate site configuration file? (y/n) : "
read SITE_CONFIG
if [ "$SITE_CONFIG" = "y" -o "$SITE_CONFIG" = "yes" ]; then
if [ ! -d "/vagrant/config/nginx-config/sites" ]; then
echo "nginx configuration directory doesn't exist! Try again."
elif [ ! -f "/vagrant/www/vvv-hosts" ]; then
echo "vvv-hosts file doesn't exist! Try again."
else
break
fi
else
break
fi
done
#
# Replace strings and assign variables.
#
TARGET_DIR=${TARGET_DIR%/}
DOCUMENT_ROOT=${TARGET_DIR##*/}
SITE_URL=${SITE_URL%/}
SERVER_NAME=${SITE_URL#http*//}
if [ ! $DB_HOST ]; then
DB_HOST="localhost"
fi
#
# Setup WordPress.
#
cd $TARGET_DIR
echo ""
wp core download --locale=ja
wp core config --dbhost=$DB_HOST --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASSWORD --locale=ja
wp db create
wp core install --url=$SITE_URL --title="$SITE_TITLE" --admin_user=$ADMIN_NAME --admin_password=$ADMIN_PASSWORD --admin_email=$ADMIN_EMAIL
wp plugin activate wp-multibyte-patch
#
# Download and activate plugins.
#
PLUGIN="reloadr-for-wp wp-sitemanager wp-migrate-db debug-bar debug-bar-extender wp-total-hacks wordpress-importer contact-form-7"
for I in $PLUGIN
do
wp plugin install $I --activate
done
#
# Download and import theme unit data.
#
if [ "$IMPORT_DATA" = "y" -o "$IMPORT_DATA" = "yes" ]; then
wget --no-check-certificate https://raw.github.com/jawordpressorg/theme-test-data-ja/master/wordpress-theme-test-date-ja.xml
wp import --authors=skip wordpress-theme-test-date-ja.xml
rm -f wordpress-theme-test-date-ja.xml
fi
#
# Generate site configuration file and restart nginx service.
#
if [ "$SITE_CONFIG" = "y" -o "$SITE_CONFIG" = "yes" ]; then
cd /vagrant/config/nginx-config/sites
cp local-nginx-example.conf-sample "$SERVER_NAME".conf
sed -i -e "s/testserver\.com/$SERVER_NAME/" "$SERVER_NAME".conf
sed -i -e "s/wordpress-local/$DOCUMENT_ROOT/" "$SERVER_NAME".conf
if ! grep -q "$SERVER_NAME" /vagrant/www/vvv-hosts; then
echo $SERVER_NAME >> /vagrant/www/vvv-hosts
fi
sudo service nginx restart
fi
echo "Installation completed successfully. Have fun :)"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.