Last active
April 17, 2016 15:06
-
-
Save twentyfortysix/64921482d2b445e481982f6cd8fb59cf to your computer and use it in GitHub Desktop.
initial wp installation
This file contains hidden or 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 -e | |
#modified to personal user by 2046, original - https://www.ltconsulting.co.uk/automated-wordpress-installation-with-bash-wp-cli/ | |
wpuser='2046' | |
clear | |
echo "=================================================================" | |
echo "Awesome WordPress Installer!!" | |
echo "=================================================================" | |
# accept user input for the databse name | |
echo "Database Name: " | |
read -e dbname | |
# accept the name of our website | |
echo "Site Name: " | |
read -e sitename | |
# accept a comma separated list of pages | |
echo "Add Pages: " | |
read -e allpages | |
# add a simple yes/no confirmation before we proceed | |
echo "Run Install? (y/n)" | |
read -e run | |
# if the user didn't say no, then go ahead an install | |
if [ "$run" == n ] ; then | |
exit | |
else | |
# download the WordPress core files | |
wp core download | |
# create the wp-config file with our standard setup | |
wp core config --dbname=$dbname --dbuser=root --dbpass=root --extra-php <<PHP | |
define( 'WP_DEBUG', true ); | |
define( 'DISALLOW_FILE_EDIT', true ); | |
PHP | |
# parse the current directory name | |
currentdirectory=${PWD##*/} | |
# generate random 12 character password | |
password=$(LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c 12) | |
# copy password to clipboard | |
echo $password | pbcopy | |
# create database, and install WordPress | |
wp db create | |
wp core install --url="http://localhost/$currentdirectory" --title="$sitename" --admin_user="$wpuser" --admin_password="$password" --admin_email="[email protected]" | |
# discourage search engines | |
wp option update blog_public 0 | |
# show only 6 posts on an archive page | |
wp option update posts_per_page 6 | |
# delete sample page, and create homepage | |
wp post delete $(wp post list --post_type=page --posts_per_page=1 --post_status=publish --pagename="sample-page" --field=ID --format=ids) | |
wp post create --post_type=page --post_title=Home --post_status=publish --post_author=$(wp user get $wpuser --field=ID --format=ids) | |
# set homepage as front page | |
wp option update show_on_front 'page' | |
# set homepage to be the new page | |
wp option update page_on_front $(wp post list --post_type=page --post_status=publish --posts_per_page=1 --pagename=home --field=ID --format=ids) | |
# create all of the pages | |
export IFS="," | |
for page in $allpages; do | |
wp post create --post_type=page --post_status=publish --post_author=$(wp user get $wpuser --field=ID --format=ids) --post_title="$(echo $page | sed -e 's/^ *//' -e 's/ *$//')" | |
done | |
# set pretty urls | |
wp rewrite structure '/%postname%/' --hard | |
wp rewrite flush --hard | |
# delete akismet and hello dolly | |
wp plugin delete akismet | |
wp plugin delete hello | |
# install lt-tables plugin | |
wp plugin install https://github.com/ltconsulting/lt-tables/archive/master.zip --activate | |
# install antispam plugin | |
wp plugin install antispam-bee --activate | |
# install the company starter theme | |
wp theme install ~/Documents/lt-theme.zip --activate | |
clear | |
# create a navigation bar | |
wp menu create "Main Navigation" | |
# add pages to navigation | |
export IFS=" " | |
for pageid in $(wp post list --order="ASC" --orderby="date" --post_type=page --post_status=publish --posts_per_page=-1 --field=ID --format=ids); do | |
wp menu item add-post main-navigation $pageid | |
done | |
# assign navigaiton to primary location | |
wp menu location assign main-navigation primary | |
clear | |
echo "=================================================================" | |
echo "Installation is complete. Your username/password is listed below." | |
echo "" | |
echo "Username: $wpuser" | |
echo "Password: $password" | |
echo "" | |
echo "=================================================================" | |
# Open the new website with Google Chrome | |
/usr/bin/open -a "/Applications/Google Chrome.app" "http://localhost/$currentdirectory/wp-login.php" | |
# Open the project in TextMate | |
/Applications/TextMate.app/Contents/Resources/mate /Applications/MAMP/htdocs/$currentdirectory/wp-content/themes/lt-theme | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment