Joelwarren
3/12/2015 - 12:54 AM

WP new install

WP new install

#!/bin/bash
echo "Website Name: "
read -e website_name
echo "Website slug: "
read -e website_slug
echo "Admin Username: "
read -e admin_username
echo "Admin Email: "
read -e admin_email
echo "Admin Password: "
read -e admin_password

website_db=`echo $website_slug | cut -c1-8`

#Setup wordpress files
mkdir "$website_slug"
cd "$website_slug"
curl -O https://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz
cd wordpress
cp -rf . ..
cd ..

#setup database
C:/wamp/bin/mysql/mysql5.6.17/bin/mysql.exe --verbose --user=root --password= --execute="create database $website_slug"

#configure install
cp ../default/livereload.js livereload.js
cp ../default/wp-config.php wp-config-sample.php
cp ../default/local-config.php local-config.php
cp ../default/staging-config.php staging-config.php
cp ../default/production-config.php production-config.php
sed -i "s/default/$website_slug/g" local-config.php
sed -i "s/default/inthewii/g" staging-config.php
sed -i "s/default/$website_db/g" production-config.php

# Fetch salt data and insert into the config file
# This downloads the salt data to a file called salt.txt, removes lines 45-52 in the wp-config which contain the placeholder for the salt, and insert the contents of salt.txt into the config
curl -o salt.txt https://api.wordpress.org/secret-key/1.1/salt/
sed '58,65d'  wp-config-sample.php > wp-config-stripped.php
sed '57 r salt.txt' wp-config-stripped.php > wp-config.php
rm salt.txt
rm wp-config-sample.php
rm wp-config-stripped.php
echo "Sample config file setup"

#Common plugin
cp -r ../default/wp-content/plugins/ wp-content/
rm wp-content/plugins/hello.php

#theme setup
cp -r ../default/wp-content/themes/_theme/ wp-content/themes/_theme/
sed -i "s/_theme/$website_name/g" wp-content/themes/_theme/sass/style.scss
sed -i "s/_theme/$website_slug/g" wp-content/themes/_theme/package.json

mv wp-content/themes/_theme/ wp-content/themes/"$website_slug"/

cp ../default/wp-content/KIA-comment-blacklist.txt wp-content/KIA-comment-blacklist.txt
cp ../default/wp-content/KIA-comment-moderation-list.txt wp-content/KIA-comment-moderation-list.txt
cp ../default/wp-content/install.php wp-content/install.php
cp -r ../default/wp-content/uploads/ wp-content/uploads/
cp ../default/wp-content/uploads/.htaccess wp-content/uploads/.htaccess
sed -i "s/_theme/$website_slug/g" wp-content/uploads/.htaccess
cp ../default/wp-content/maintenance.php wp-content/maintenance.php
rm -R wp-content/themes/twentytwelve
rm -R wp-content/themes/twentythirteen
rm -R wp-content/themes/twentyfourteen

#remove files from wordpress folder
rm -R wordpress
rm readme.html
rm latest.tar.gz

#add hosts and virtual directory
echo -e "\n127.0.0.1       loc.$website_slug.com.au" >> "C:\Windows\System32\drivers\etc\hosts"

echo -e "\n<VirtualHost *:80>" 										 		 >> "C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf"
echo -e "    DocumentRoot \"C:/Users/Joel/Dropbox/www/$website_slug/\"" 	 >> "C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf"
echo -e "    ServerName loc.$website_slug.com.au" 							 >> "C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf"
echo -e "</VirtualHost>" 													 >> "C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf"

#restart wamp
net stop wampapache
net start wampapache

#install wordpress, change default username, disallow search engines - requires wp-cli
wp core install --url=loc.$website_slug.com.au --title="$website_name" --admin_name=$admin_username --admin_password=$admin_password --admin_email=$admin_email

#remove install helper files
rm wp-content/KIA-comment-blacklist.txt
rm wp-content/KIA-comment-moderation-list.txt
rm wp-content/install.php

wp plugin install bootstrap-3-shortcodes --activate
wp plugin install contact-form-7 --activate
wp plugin install force-regenerate-thumbnails
wp plugin install jetpack
wp plugin install limit-login-attempts --activate
wp plugin install simple-history --activate
wp plugin install simple-image-widget
wp plugin install theme-check --activate
wp plugin install wordpress-seo
wp plugin install wp-quick-pages --activate

wp rewrite structure '%year%/%monthnum%/%postname%'

cd wp-content/themes/"$website_slug"/
#run compass
npm install
grunt dist

#create git repo
git init

#switch wordpress to use custom theme - requires wp-cli
wp theme activate $website_slug

#open browser at site address
"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "http://loc.$website_slug.com.au/"

echo "Complete"
read