Last active
May 4, 2024 11:52
-
-
Save protorob/539c383ba4b5a5a0f386417f9234cbd2 to your computer and use it in GitHub Desktop.
Bash Sript to Automate the Configuration of the Artomultiplo's Woocommerce Starter Kit
This file contains 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 | |
# Start allways the same | |
wpuser='yourusername' | |
wpuseremail='[email protected]' | |
wpuserpass=$(date +%s | sha256sum | base64 | head -c 16) | |
dpprefix=$(date +%s | sha256sum | base64 | head -c 6) | |
clear | |
# Say Hello! | |
echo "╔═╗╦═╗╔╦╗╔═╗╔╦╗╦ ╦╦ ╔╦╗╦╔═╗╦ ╔═╗"; | |
echo "╠═╣╠╦╝ ║ ║ ║║║║║ ║║ ║ ║╠═╝║ ║ ║"; | |
echo "╩ ╩╩╚═ ╩ ╚═╝╩ ╩╚═╝╩═╝ ╩ ╩╩ ╩═╝╚═╝"; | |
echo "╦ ╦╔═╗╔═╗╔═╗╔═╗╔╦╗╔╦╗╔═╗╦═╗╔═╗╔═╗ "; | |
echo "║║║║ ║║ ║║ ║ ║║║║║║║║╣ ╠╦╝║ ║╣ "; | |
echo "╚╩╝╚═╝╚═╝╚═╝╚═╝╩ ╩╩ ╩╚═╝╩╚═╚═╝╚═╝ "; | |
echo " ╔═╗╔╦╗╔═╗╦═╗╔╦╗╔═╗╦═╗ "; | |
echo "──────╚═╗ ║ ╠═╣╠╦╝ ║ ║╣ ╠╦╝────── "; | |
echo " ╚═╝ ╩ ╩ ╩╩╚═ ╩ ╚═╝╩╚═ "; | |
# as-seen-on https://indigotree.co.uk/automated-wordpress-installation-with-bash-wp-cli/ | |
# Defining Database Variables: | |
echo "=================================================================" | |
echo "The Database Info" | |
echo "=================================================================" | |
echo "Database Hots: " | |
read -e -r dbhost | |
echo "Database Name: " | |
read -e -r dbname | |
echo "Database User: " | |
read -e -r dbuser | |
echo "Database Password: " | |
read -e -r dbpass | |
# Wordpress Related Options: | |
echo "=================================================================" | |
echo "The Wordpress Site Configuration" | |
echo "=================================================================" | |
#The url of the wordpress installation: | |
echo "What's the url of your wordpress installation?" | |
read -e -r wpurl | |
# The name of our website | |
echo "Give a name to your website:" | |
read -e -r sitename | |
# accept a comma separated list of pages that you need appart of Home - Home page is created automatically | |
echo "Add the pages you need - excluding HOME -(comma separated): " | |
read -e -r allpages | |
echo "=================================================================" | |
echo "Everything seems ok. Do you want to run the Install? (y/n)" | |
echo "=================================================================" | |
read -e -r 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 | |
wp core config --dbhost="$dbhost" --dbname="$dbname" --dbuser="$dbuser" --dbpass="$dbpass" --dbprefix="$dpprefix"_ | |
# create database, and install WordPress | |
# wp db create (in case in the future we want to let the installer to create the database) | |
wp core install --url="$wpurl" --title="$sitename" --admin_user="$wpuser" --admin_password="$wpuserpass" --admin_email="$wpuseremail" <<PHP | |
define( 'DISALLOW_FILE_EDIT', true ); | |
define( 'WP_POST_REVISIONS', false); | |
PHP | |
# 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%/' | |
wp rewrite flush | |
# delete akismet and hello dolly | |
wp plugin delete akismet | |
wp plugin delete hello | |
# install Contact Form 7 plugin | |
wp plugin install contact-form-7 --activate | |
# install Woocommerce | |
wp plugin install woocommerce | |
#install Siteorigin Page Builder | |
wp plugin install siteorigin-panels --activate | |
#install Siteorigin Widgets Bundle | |
wp plugin install so-widgets-bundle --activate | |
#----------------------------------------------- | |
# INSTALLING THEMES | |
#----------------------------------------------- | |
# install the GeneratePress theme | |
wp theme install generatepress --activate | |
#----------------------------------------------- | |
# CREATE THE PRIMARY MENU | |
#----------------------------------------------- | |
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 "Woohoo!" | |
echo "Installation is complete. Your username/password is listed below." | |
echo "" | |
echo "Username: $wpuser" | |
echo "Password: $wpuserpass" | |
echo "" | |
echo "=================================================================" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment