diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/clique/README.md b/clique/README.md new file mode 100755 index 0000000..1d2865b --- /dev/null +++ b/clique/README.md @@ -0,0 +1,70 @@ +# Clique Studios Local Backend WP Install + +## Prerequisites: +* Install `valet` or `valet-plus` +* If running `valet`, install `wp-cli` +* `mkdir` a folder in your `/Sites/` folder, or whever you have `valet park` set with a sub-dir for the **[`wp-boilerplate` repository]** +* Check the following lines + * Line 15: For the correct /path/to/Sites_folder + * Line 18: That `wp-boilerplate` is the correct folder name where the WP-Boilerplate repository lives + * Line 19: The .TLD is the correct setup for your env. To check, run `valet domain` and see what it states. + * You can run `.app` as your domain, but you WILL need to create an SSL certificate for each folder you have parked, which this script does automatically. + +## Description +The following below describes what this shell script does. + +* Asks for a few prompts for you to fill in : your password (for `valet`), the sitename, blog description *(optional)*, database name, database password, +* Fetches the latest wp-boilerplate from the repo, assuming you have a dedicated folder for the repository +* Copies the zip file from the wp-boilerplate repo, unpacks it and updates the wordpress core to the latest version +* Copies the `.sql` file from `dup-installer` and renames it. +* Deletes the `wp-config.php` file in the unpackaged folder +* Creates a new `wp-config.php` and creates a new `db` with a conditional if the db already exists, to allow one more change to try again. I could extend it to the typical Legend of Zelda 3 tries to defeat the boss, but shouldn’t need to, haha. +* Imports the `.sql` file to the database +* Next asks if you wanna create some top level pages (optional) +* Asks if you want to disable comments, which if yes, will disable pings and trackbacks +* Deletes the default wordpress “Hello World” post, the default Comment, and renames “Sample Page” to “Home” with the slug “home” +* Runs through a loop to create the pages listed above (if you entered any, otherwise it skips this) +* Since this is an import of a duplicator theme, it updates the `option` for the following `home`, siteurl`, `blogname`, and if you entered a description `blogdescription` +* Sets the `show_front_page` to `page` +* Sets the `page_on_front` to `Home` by ID 2 +* Runs a database search/replace to replace `http://wp-boilerplate.test:8080` with `https://you_folder_name.tls` + * **Example**: `https://wordpress_core.app` +* Flushes the rewrite permalinks +* Updates all the plugins +* Installs and activates classic-editor +* Activates WP-Accessibility +* Asks if you’re like to activate additional plugins: + * Gravity Forms + * Also installs @cho’s Gravity Forms WCAG 20 Form Fields + * Activate Sitemap (Which I want to make obsolete and replace with a shortcode I created on the PFI onboarding project, which offers more parameters, including a Classic Editor pop-up to choose your post type, include children pages and up to what depth, or if we move on to Gutenberg, a new block that will do the same thing. I wasn’t impressed by that plugin, and I wanted to give us more control over the markup and addition of classes, if not just a template we can override. May make into a plugin, may just be something I want to merge into the sage9 theme). + * Activate Yoast SEO, which will also download and install ACF Content Analysis for Yoast SEO +* Cleans up the `.zip file`, copied `.sql` file, `CLIQUE-CHANGELOG.txt` and `admin-creds-PLEASE-DELETE.txt`. The latter due to terminal informing you of the user name and password. +* Next valet will run `valet secure $dirName` where `$dirName` is grabbed by the initial shell execution via the set vairable `dirName=${PWD##*/}` + * I find it best to run local sites via SSL to mimic the live site to it’s truest form +* The final thing on screen will showcase the domain you can command click on to access the front-end, a link to access the back end, the login creds based on the repo, and a link to Duplicators cleanup files. + +## Postface +Unfortunately since the repo file is `zip` and not `tar.gz` it take a little longer. + +This is my first complex automate as much as possible script, and when starting `SAWS` I was able to get everything setup in under 2 minutes. + +### **[Download the Bash Script]** + +If you wanna try it, I suggest creating a `.custom_bash_scripts` dir on `$HOME` or `$USER$` and adding that folder to your path. + +* Example: `export PATH="$PATH:$HOME/.custom_bash_scripts:$PATH"` + +Running the command in terminal `chmod 755 clique_wp.sh` followed by `source ~/.bash_profile` or `source ~/.bashrc` where ever you’re storing your `PATH` declarations, will allow you to then call to the shell script in terminal wherever. + +This will be my baby and maintenance will be on going, so PLEASE any issues you encounter OR any improvements you feel I would make, create tickets [here][3]. + + +## @TODO List + +* **@TODO**: Allow the addition of sub pages, but will need to rethink the logic on this + + + +[`wp-boilerplate` repository]:https://bitbucket.org/clique_studios/wp-boilerplate/src/master/ +[Download the Bash Script]:https://github.com/kupoback/shell_scripts/blob/master/clique/clique_wp.sh +[3]:https://github.com/kupoback/shell_scripts/issues diff --git a/clique/clique_wp.sh b/clique/clique_wp.sh new file mode 100755 index 0000000..f364c6f --- /dev/null +++ b/clique/clique_wp.sh @@ -0,0 +1,335 @@ +#!/bin/bash + +# Styles +VP_NONE=$'\033[00m' +VP_RED=$'\033[01;31m' +VP_GREEN=$'\033[01;32m' +VP_YELLOW=$'\033[01;33m' +VP_PURPLE=$'\033[01;35m' +VP_CYAN=$'\033[01;36m' +VP_WHITE=$'\033[01;37m' +VP_BOLD=$'\033[1m' +VP_UNDERLINE=$'\033[4m' + + +# Setup some folder paths to variables +folderPath="${HOME}/Sites/" +dirName="${PWD##*/}" +installPath="${folderPath}/${dirName}/" +wpBoilerplate="${folderPath}/wp-boilerplate/" +themeFolder="${folderPath}/${dirName}/wp-content/themes/" +url="https://${dirName}.app" + +# Inform the user that this is assuming they're using Valet-plus +echo -e "${VP_CYAN}This bash script is under the assumption that you are using valet-plus to set up this WordPress install. +${VP_CYAN}${VP_BOLD}This script will now clear your terminal window. +${VP_WHITE} + +${VP_WHITE}${VP_BOLD}Please press enter to continue.${VP_WHITE}" +read -r + +clear && printf '\e[3J' + +# We will now try to cache the sudo password, as we'll be setting up an SSL for their dev environment +echo -e "${VP_RED}${VP_BOLD}You may be asked twice for your password, but this is to setup an SSL locally to best mimic a live environment.${VP_NONE}" +sudo -v + +# Grab the Site Name +read -p "${VP_WHITE}Enter the site name: ${VP_NONE}" siteName + +# Grab the Blog Description +echo -e "\\n${VP_WHITE}Enter a blog description (optional):${VP_NONE}" +read -r blogDescription + +# Grab the theme folder name +read -p $'\n'"${VP_WHITE}Enter the theme folder name, ommiting -theme${VP_NONE}: " themeName + + +# Grab the database name +echo -e "\\n${VP_WHITE}Enter your chosen database name. + +${VP_RED}Note${VP_WHITE}: wp_ is automatically prefixed.${VP_NONE}" +read -r dbName + +# Grab the database username +read -p $'\n'"${VP_WHITE}Enter your database user name if it differs from \"${VP_YELLOW}root${VP_WHITE}\", otherwise hit enter.${VP_NONE} " dbUser + +# Grab the database password +read -p "${VP_WHITE}Enter your database password if it differs from \"${VP_YELLOW}root${VP_WHITE}\", otherwise hit enter.${VP_NONE} " dbPassword + +# If a $dbUser was not entered, we'll default to valet-plus' mysql username +[ -z "${dbUser}" ] && dbUser=root + +# If a $dbUser was not entered, we'll default to valet-plus' mysql password +[ -z "${dbPassword}" ] && dbPassword=root + +# Fetch the latest files from the wp-boilerplate repo and then pull it +cd "${wpBoilerplate}" || exit 1 + +echo -e "\\n${VP_WHITE}Fetching and pulling the latest version of ${VP_CYAN}wp-boilerplate${VP_WHITE}${VP_NONE}" +git fetch --force +git pull --force + +# With a fresh pull, copy the zip file into the new project folder and unzip the contents +cp -a ./*.zip "${installPath}"/ +cd "${installPath}" || exit 1 +unzip -q ./*.zip + +# Copy the .sql file, and rename it +cp ./dup-installer/*.sql ./import.sql + +# We want to remove the wp-config file here and create a new one +echo -e "\\n${VP_RED}Deleting wp-config file and creating a new one.${VP_WHITE}${VP_NONE}" +rm -rf wp-config.php + +# Creating the new wp-config file +echo -e "\\n${VP_WHITE}Creating database and setting up wp-config.php file.${VP_NONE}" +wp config create --dbname=wp_"${dbName}" --dbuser="${dbUser}" --dbpass="${dbPassword}" + +wp db create + +# Check to see if there were any errors in creating the database +# We'll give the user 2 tries before we exit the script +if [ ! $? -eq 0 ] +then + # Remove the old wp-config file + rm -rf wp-config.php + + # Let's try re-try the database name, login and password + echo -e "\\n${VP_RED}Error${VP_WHITE}: Either the database name already exists, the database username or password is incorrect, please double check. + + Enter your chosen database name. + + ${VP_RED}Note${VP_WHITE}: wp_ is automatically prefixed.${VP_NONE}" + read -r dbNameReTry + + # Get the database username - retry + read -p $'\n'"${VP_WHITE}Enter your database user name if it differs from ${VP_YELLOW}root${VP_WHITE}, otherwise hit enter${VP_NONE}: " dbUserRetry + + # Get the database password - retry + read -p $'\n'"${VP_WHITE}Enter your database password if it differs from ${VP_YELLOW}root${VP_WHITE}, otherwise hit enter:${VP_NONE} " dbPasswordRetry + + # If a $dbUser was not entered, we'll default to valet-plus' mysql username + [ -z "${dbUserRetry}" ] && dbUserRetry=root + + # If a $dbUser was not entered, we'll default to valet-plus' mysql password + [ -z "${dbPasswordRetry}" ] && dbPasswordRetry=root + + # Create the wp-config file again + wp config create --dbname=wp_"${dbNameReTry}" --dbuser="${dbUserRetry}" --dbpass="${dbPasswordRetry}" + + # Try to create the database again + wp db create + + if [ ! $? -eq 0 ] + then + echo -e "\\n{$VP_RED}Please double check that either the database doesn't already exist, or the user name and password is correct. + + ${VP_WHITE}Exiting script.${VP_NONE}" + + exit 1 + fi + +fi + +# With the database created, we'll need to now import our .sql file +echo -e "\\n${VP_GREEN}Database created!${VP_WHITE} + +${VP_CYAN}Now importing the .sql file.${VP_NONE}" + +wp db import import.sql + +# Check to see if there were any errors importing the database +# If so, we'll quit the script +if [ ! $? -eq 0 ] +then + echo -e "\\n${VP_RED}Opps, something went wrong with the database import. + + ${VP_WHITE}If you know what happened, please report the issue.${VP_NONE}" + + exit 1 +fi + +# Ask to update to the latest version of WordPress +read -p $'\n'"${VP_PURPLE}Update to the lates version of ${VP_YELLOW}WordPress [y/n]${VP_WHITE}${VP_NONE} " updateWordPress + +if [[ "${updateWordPress}" == "y" ]] +then + # Update to the latest version of WordPress + echo -e "\\nUpdating to the latest version of ${VP_PURPLE}WordPress${VP_WHITE}.${VP_NONE}" + wp core update +fi + +# Change the theme folder name +echo -e "\\n${VP_WHITE}Now changing the theme folder name from ${VP_CYAN}${VP_BOLD}sage9-project-name-theme${VP_WHITE}${VP_NONE} to ${VP_CYAN}${VP_BOLD}${themeName}-theme${VP_WHITE}${VP_NONE}" + +mv $themeFolder/sage9-project-name-theme $themeFolder/$themeName-theme + +echo -e "\\n${VP_WHITE}Folder name changed. + +You can choose to create top level pages you know you'll need here, otherwise just hit enter to skip this. + +Please separate page names with a comma (,) and no space. The ${VP_CYAN}Homepage${VP_WHITE} is already created. + +${VP_CYAN}Example:${VP_WHITE} About Us,Contact Us,Blog ${VP_NONE} " +read -r pageList + +# Lets remove the default "Hellow World" post +echo -e "Removing \"Hello World\" post." +wp post delete 1 --force + +# Let's remove the default WordPress comment +# echo -e "\\nDeleting default example comment." +# wp comment delete 1 --force + +# Do we want to disable comments? +read -p $'\n'"${VP_YELLOW}Disable comments? [y/n]${VP_WHITE}${VP_NONE} " disableComments + +# If they want to disable comments, we'll also disable trackbacks and pings +if [[ "${disableComments}" == "y" ]] +then + # Disabling Comments + echo -e "\\n${VP_YELLOW}Disabling Comments${VP_WHITE}${VP_NONE}" + wp post list --format=ids | xargs wp post update --comment_status=closed + + # Disabling Trackbacks/Pings + echo -e "\\n${VP_YELLOW}Disabling Trackbacks/Pings${VP_WHITE}${VP_NONE}" + wp post list --format=ids | xargs wp post update --ping_status=closed +fi + +# Now we'll update the "Sample Page" to "Home" +echo -e "\\nChanging \"Sample Page\" to \"Home\"." +wp post update 2 --post_title=Home --post_name=home --post_type=page --post_status=publish --post_content= --post_excerpt= + +# If there's pages to create, let's create them +if [[ -n "${pageList}" ]] +then + echo -e "\\n${VP_CYAN}Creating pages.${VP_WHITE}${VP_NONE}" + IFS=", " + arr=("${pageList}") + for i in "${!arr[@]}" + do + wp post create --post_title="${arr[i]}" --post_type=page --post_status="publish" + done + unset IFS +fi + +# Option updates + +# Execture a query to update the siteurl and home url +echo -e "\\n${VP_CYAN}Updating the home and siteurl, and setting the blogname.${VP_WHITE}${VP_NONE}" +wp option update home "${url}" +wp option update siteurl "${url}" +wp option update blogname "${siteName}" + +if [[ -n "${blogDescription}" ]] +then + echo -e "\\n${VP_CYAN}Setting the blogdescription.${VP_WHITE}${VP_NONE}" + wp option update blogdescription "${blogDescription}" +fi + +# Set the homepage +echo -e "\\n${VP_CYAN}Setting Homepage to front_page.${VP_WHITE}${VP_NONE}" +wp option update show_on_front 'page' +wp option update page_on_front 2 + +# Set the Timezone to Chicago +echo -e "\\n${VP_CYAN}Changing timezone to Chicago.${VP_WHITE}${VP_NONE}" +wp option update timezone_string "America/Chicago" + +# Replace the old http://wp-boilerplate.test:8080 with the sitename +echo -e "\\n${VP_YELLOW}Replacing ${VP_UNDERLINE}${VP_WHITE}http://wp-boilerplate.test:8080${VP_NONE} ${VP_YELLOW}with ${VP_UNDERLINE}${VP_WHITE}${url}${VP_NONE}" +wp search-replace 'http://wp-boilerplate.test:8080' "${url}" --all-tables --quiet + +# Save the permalinks +echo -e "\\n${VP_CYAN}Flushing permalinks.${VP_WHITE}${VP_NONE}" +wp rewrite flush + +# One last step with the database, let's optimize it +echo -e "\\n${VP_CYAN}Optimizing database.${VP_WHITE}${VP_NONE}" +wp db optimize --quiet + +# Update plugins +echo -e "\\n${VP_GREEN}Updating plugins.${VP_WHITE}" +wp plugin update --all + +# Activate the wp-accessibility plugin +echo -e "\\n${VP_GREEN}Activating${VP_WHITE}: the WP-Accessibility Plugin. ${VP_WHITE}${VP_NONE}" +wp plugin activate wp-accessibility + +# Ask if they want to install the Classic Editor +read -p $'\n'"${VP_YELLOW}Install Classic Editor? [y/n]${VP_WHITE}${VP_NONE} " classicEditor + +if [[ "${classicEditor}" == "y" ]] +then + echo -e "\\n${VP_CYAN}Installing and Activating the Classic Editor.${VP_WHITE}${VP_NONE}" + wp plugin install classic-editor --activate +fi + +# Ask if they want to activate any additional default plugins +read -p $'\n'"${VP_YELLOW}Activate additional default plugins? [y/n]${VP_WHITE}${VP_NONE} " additionalPlugins + +# Run through a couple of the common activated plugins they may want. +if [[ "${additionalPlugins}" == "y" ]] +then + # Ask which of these plugins to activate + # There is currently an issue with gravity forms. + # read -p $'\n'"${VP_YELLOW}Activate Gravity Forms? [y/n]${VP_WHITE}${VP_NONE} " gravityForms + + read -p $'\n'"${VP_YELLOW}Activate Sitemap? [y/n]${VP_WHITE}${VP_NONE} " siteMap + + read -p $'\n'"${VP_YELLOW}Activate Yoast SEO? [y/n]${VP_WHITE}${VP_NONE} " yoastSEO + + # Activate Gravity Forms and WCAG Gravity Forms extension + # if [[ "${gravityForms}" == "y" ]] + # then + # echo -e "\\n${VP_CYAN}Activating Gravity Forms and WCAG for Gravity Forms.${VP_WHITE}${VP_NONE}" + # wp plugin activate gravityforms + # wp plugin activate gravity-forms-wcag-20-form-fields + # fi + + # Activate Sitemap plugin, but may be replaced + if [ "${siteMap}" == "y" ] + then + echo -e "\\n${VP_CYAN}Activating Sitemap.${VP_WHITE}${VP_NONE}" + wp plugin activate sitemap + fi + + # Activate Yoast SEO and install ACF for Yoast + if [ "${yoastSEO}" == "y" ] + then + echo -e "\\n${VP_CYAN}Activating Yoast SEO and ACF Content Analysis for Yoast.${VP_WHITE}${VP_NONE}" + wp plugin activate wordpress-seo + wp plugin install acf-content-analysis-for-yoast-seo --activate + fi + +fi + +# Clean up some root installation files +echo -e "\\n${VP_WHITE}Deleting ${VP_RED}${VP_BOLD}import.sql${VP_NONE}${VP_WHITE} and the ${VP_RED}${VP_BOLD}duplicator.zip${VP_NONE}${VP_WHITE} files.${VP_WHITE}${VP_NONE}" +rm -rf ./*.zip import.sql CLIQUE-CHANGELOG.txt admin-creds-PLEASE-DELETE.txt + +# Confirm the site is setup +echo -e "\\n${VP_GREEN}Your site is setup and ${VP_BOLD}${VP_WHITE}WordPress${VP_NONE}${VP_GREEN} is installed.${VP_WHITE}${VP_NONE}" + +# Setup SSL for valet +echo -e "\\nSetting up an SSL cert for ${VP_UNDERLINE}${VP_WHITE}${url}${VP_NONE}\\n" +valet secure "${dirName}" + +# Final notice on everything being complete +echo -e " + +${VP_GREEN}All done. You can access your site and login. + +${VP_GREEN}Front End${VP_WHITE}: ${VP_UNDERLINE}${url}${VP_NONE} +${VP_GREEN}Back End${VP_WHITE}: ${VP_UNDERLINE}${url}/wp-admin${VP_NONE} + +${VP_WHITE}Login Credentials${VP_NONE} +${VP_GREEN}Username:${VP_WHITE}${VP_BOLD} admin${VP_NONE} +${VP_GREEN}Password:${VP_WHITE}${VP_BOLD} Cl!que2019${VP_NONE} + +${VP_RED}Due to the copied files being generated from a duplicator package, you will need to head here to clean up any files. ${VP_UNDERLINE}${VP_WHITE}${url}/wp-admin/admin.php?page=duplicator-tools&tab=diagnostics + +${VP_GREEN}Exiting script.${VP_WHITE}${VP_NONE}" + +exit 1 \ No newline at end of file diff --git a/clique/env_install.sh b/clique/env_install.sh new file mode 100755 index 0000000..a184302 --- /dev/null +++ b/clique/env_install.sh @@ -0,0 +1,368 @@ +#!/usr/bin/env bash + +# USAGE +usage() { echo -e " +USAGE: ${0} [OPTIONS]\\n +OPTIONS:\\n +-m (optional) Monochrome output colors +-q (optional) Suppress informational messages +-h Display this usage information\\n +"; } + +# OPTIONS +while getopts "mqh" opt ; do + case "${opt}" in + m) monochrome="yes" ;; + q) quiet="yes" ;; + h) usage ; exit 0 ;; + *) usage ; exit 1 ;; + esac +done + +# COMMON VARIABLES & FUNCTIONS +# colors +if [[ -n "${monochrome}" ]] ; then + ink_clear="\\x1b[0m" + ink_grey="\\x1b[38;5;244m" + ink_red="\\x1b[0m" + ink_green="\\x1b[0m" + ink_blue="\\x1b[0m" + ink_yellow="\\x1b[0m" + ink_purple="\\x1b[0m" +else + ink_clear="\\x1b[0m" + ink_grey="\\x1b[38;5;244m" + ink_red="\\x1b[38;5;204m" + ink_green="\\x1b[38;5;120m" + ink_blue="\\x1b[38;5;081m" + ink_yellow="\\x1b[38;5;228m" + ink_purple="\\x1b[38;5;207m" +fi + +# output +yes_no="${ink_blue}[${ink_clear} ${ink_green}yes${ink_clear} ${ink_blue}/${ink_clear} ${ink_red}no${ink_clear} ${ink_blue}]${ink_clear}" +mysql_maria="${ink_blue}[${ink_clear} ${ink_yellow}mysql${ink_clear} ${ink_blue}/${ink_clear} ${ink_purple}mariadb${ink_clear} ${ink_blue}]${ink_clear}" +latest="${ink_yellow}latest version" +yuicompressor="" +path="${HOME}" +sitepath="${HOME}/Sites" +phpmyadmin=https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-english.tar.gz +nl () { if [[ -z "${quiet}" ]]; then echo; fi; } +say () { if [[ -z "${quiet}" ]]; then echo -e "\\n${ink_grey}${1}${ink_clear}"; fi; } +success () { if [[ -z "${quiet}" ]] ; then echo -e "\\n${ink_green}${1}${ink_clear}" ; fi ; } +tinysay () { if [[ -z "${quiet}" ]] ; then echo -e "${ink_grey}${1}${ink_clear}" ; fi ; } +errsay () { echo -e "\\n${ink_red}${1}. Script aborted!${ink_clear}"; } +sucsay () { echo -e "${ink_green}${1} successfully installed.${ink_clear}"; } +err () { echo -e "\\n${ink_red}${1}${ink_clear}"; } +ask () { echo -en "\\n${ink_grey}${1} ${ink_clear}"; } +askinfo () { echo -en "${ink_grey}${1} ${ink_clear}" ; read -r "${2}" ; } +saysitepath () { echo -en "${ink_grey}${1}: ${ink_clear}\\n${ink_blue}${path} ${ink_clear}" ; } + +# confirm +confirm() { + ask "${1}" + read -r INPUT + case "${INPUT}" in + [yY][eE][sS] | [yY]) ;; + [mM][yY][sS][qQ][lL] | [mM][aA][rR][iI][aA][dD][bB] | [mM][aA][rR][iI][aA]) ;; + [nN][oO] | [nN]) say "Script aborted.\\n" && exit 0 ;; + *) confirm "${1}" ;; + esac +} + +# Cache the sudo password +cache_sudo_password() { + + say "Please enter your local user password." + sudo -k + sudo -v && tinysay "${ink_blue}OK" +} + +# Gather all the Install Parameters +collect_install_parameters() { + + say "This script will install the basic tools used for local development." + nl + + confirm "Would you like to continue? ${yes_no}" + clear + + askinfo "Would you like to use MySQL or mariaDB? mariaDB runs SQL statements quicker and uses less resources compared to MySQL, though may eventually become uncompatible with MySQL: ${mysql_maria}" dbStructure + askinfo "${dbStructure} username (default: root):" dbUserName + askinfo "${dbStructure} password (default: root):" dbUserPass + nl + tinysay "What TLS would you like your sites to be served under? Default is ${ink_blue}test${ink_grey}" + askinfo "${ink_red}Note${ink_grey}: Using ${ink_blue}app${ink_grey} or ${ink_blue}dev${ink_grey} will require you to run ${ink_yellow}valet secure {folder_name}${ink_grey} before visiting the page:" getTLS + askinfo "Install phpmyadmin? ${yes_no}: " installPhpMyAdmin + askinfo "If using phpStorm, would you like to install yuicompressor for JavaScript and CSS minification watcher? ${yes_no}" getYUI + + # # setting defaults if values were omitted + if [[ -z "${dbStructure}" ]]; then dbStructure="mariadb"; fi + if [[ -z "${getTLS}" ]]; then getTLS="test"; fi + if [[ -z "${getYUI}" ]]; then getYUI="no"; fi + if [[ -z "${dbUserName}" ]] ; then dbUserName="root" ; fi + if [[ -z "${dbUserPass}" ]] ; then dbUserPass="root" ; fi + + say "This ${ink_yellow}computer${ink_grey} will have the following installed:" + nl + + say "${ink_green}PACKAGE MANAGER" + tinysay "${ink_blue}Homebrew${ink_grey} - A tool/repo installer similar to NPM" + tinysay "${ink_blue}Composer${ink_grey}: ${latest}" + tinysay "${ink_blue}Node/NPM${ink_grey}: ${latest}" + nl + + say "${ink_green}ENVIRONMENT" + tinysay "${ink_blue}Laravel Valet${ink_grey} - Local Dev Environment." + tinysay "${ink_blue}php${ink_grey}: ${ink_yellow}Latest Version of 7" + tinysay "${ink_blue}Database${ink_grey}: ${ink_yellow}${dbStructure}" + tinysay "${ink_blue}Database username${ink_grey}: ${ink_yellow}${dbUserName}" + tinysay "${ink_blue}Database password${ink_grey}: ${ink_yellow}${dbUserPass}" + + if [[ "${installPhpMyAdmin}" != n* ]]; then + tinysay "${ink_blue}phpMyAdmin${ink_grey}: ${latest}" + fi + tinysay "${ink_blue}Local site TLS${ink_grey}: ${ink_yellow}${getTLS}" + nl + + say "${ink_green}TOOLS" + tinysay "${ink_blue}Gulp${ink_grey} - Sage8 Projects: ${latest}" + tinysay "${ink_blue}WP-CLI${ink_grey}: ${latest}" + tinysay "${ink_blue}Yarn${ink_grey} (for Sage9 Projects): ${latest}" + if [[ "${getYUI}" != n* ]]; then + tinysay "${ink_blue}YUICompressor${ink_grey}: ${latest}" + fi + nl + + confirm "Would you like to continue? ${yes_no}" +} + +# Install homebrew +install_homebrew() { + if ! hash brew 2>/dev/null; then + say "Downloading and installing Homebrew. Please wait…" + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + say "Homebrew is installed. You can use it to install packages by calling to the command ${ink_blue}brew${ink_grey}" + confirm "Would you like to continue? ${yes_no}" + else + tinysay "Homebrew is already installed. You can call to it with the command ${ink_blue}brew${ink_grey}" + confirm "Would you like to continue? ${yes_no}" + fi +} + +# Install Composer, node, php, wget, SASS, yuicompressor, and database of choice +install_homebrew_packages() { + if ! type brew >/dev/null 2>&1; then + if [[ "${getYUI}" != n* ]] ; then + yuicompressor="yuicompressor" + fi + + tinysay "Installing ${ink_yellow} brew packages${ink_grey}. Please wait…" + brew install composer node php wget sass/sass/sass ${dbStructure} ${yuicompressor} + brew services start ${dbStructure} + tinysay "${ink_green}Install Complete!${ink_grey}" + fi +} + +# Check for any errors when installing brew packages +brew_error_checks() { + tinysay "Checking ${ink_blue}brew${ink_grey} for errors." + + if ! type composer >/dev/null 2>&1; then + errsay "There was an error installing Composer. Please review why and report back to the script creator." + else + sucsay composer + fi + + if ! type mysql >/dev/null 2>&1; then + errsay "There was an error installing ${dbStructure}. Please review why and report back to the script creator." + else + sucsay ${dbStructure} + fi + + if ! type node >/dev/null 2>&1; then + errsay "There was an error installing Node. Please review why and report back to the script creator." + else + sucsay node + fi + + if ! type php >/dev/null 2>&1; then + errsay "There was an error installing php. Please review why and report back to the script creator." + else + sucsay php + fi + + if ! type sass >/dev/null 2>&1; then + errsay "There was an error installing sass. Please review why and report back to the script creator." + else + sucsay sass + fi + + if ! type wget >/dev/null 2>&1; then + errsay "There was an error installing wget. Please review why and report back to the script creator." + else + sucsay wget + fi + + if [[ "${getYUI}" != n* ]] ; then + if ! type yuicompressor >/dev/null 2>&1; then + errsay "There was an error installing yuicompressor. Please review why and report back to the script creator." + else + sucsay yuicompressor + fi + fi +} + +# Writes exports to ./bash_profile +bash_profile_write() { + if [[ ! -e "${HOME}"/.bash_profile ]]; then + tinysay "Creating a .bash_profile file at ${HOME}" + fi + + if ! grep -q "export PATH" "${HOME}"/.bash_profile; then + tinysay "Adding export PATH to ~/.bash_profile" + echo "export PATH" >> "${HOME}"/.bash_profile + fi + + if ! grep -q "export PATH=\"$PATH:${HOME}/npm/bin\"" "${HOME}"/.bash_profile; then + tinysay "Adding NPM to your \$PATH" + echo "export PATH=\"$PATH:${HOME}/npm/bin\"" >> "${HOME}"/.bash_profile + fi + + if ! grep -q "export PATH=\"/usr/local/bin:$PATH\"" "${HOME}"/.bash_profile; then + tinysay "Adding bin to your \$Path" + echo "export PATH=\"/usr/local/bin:$PATH\"" >> "${HOME}"/.bash_profile + fi + + if ! grep -q "export PATH=\"/usr/local/sbin:$PATH\"" "${HOME}"/.bash_profile; then + tinysay "Adding sbin to your \$Path" + echo "export PATH=\"/usr/local/sbin:$PATH\"" >> "${HOME}"/.bash_profile + fi + + if ! grep -q "export PATH=\"$PATH:${HOME}/.composer/vendor/bin\"" "${HOME}"/.bash_profile; then + tinysay "Adding Composer to ~/.bash_profile" + echo "export PATH=\"$PATH:${HOME}/.composer/vendor/bin\"" >> "${HOME}"/.bash_profile + fi + + # Make an SSH Alias file + mkdir "${HOME}"/.custom_bash_files + cd "${HOME}"/.custom_bash_files || exit + cat > .alias_ssh.sh + echo "# This file can be used to set aliases for utiliing ssh for servers" > .alias_ssh.sh + echo "# Example: alias sitessh=\"ssh root@test.sandbox6.cliquedomains.com\" would create a quick tab completeion to ssh into the Sandbox 6 Digital Ocean Server." >> .alias_ssh.sh + nl + cat > .alias_commands.sh + echo "# This file can be used to set up various alias' needed to make development easier." > .alias_commands.sh + + source "${HOME}"/.bash_profile + tinysay "Reloaded your ${ink_yellow}.bash_proflie${ink_grey}" + +} + +# Installs npm packages +install_npm_packages() { + if type npm >/dev/null 2>&1; then + if ! type yarn >/dev/null 2>&1; then + tinysay "Installing ${ink_blue}yarn${ink_grey}" + npm install -g yarn + if ! yarn -v; then + errsay "There was an error installing yarn. Please review why and report back to the script creator." ; exit 1 + fi + sucsay "yarn" + fi + if ! type gulp >/dev/null 2>&1; then + tinysay "Installing ${ink_blue}gulp${ink_grey}" + npm install -g gulp + if ! gulp -v; then + errsay "There was an error installing gulp. Please review why and report back to the script creator." ; exit 1 + fi + sucsay "Gulp" + fi + fi +} + +# Installs WP-CLI and wp-completion.bash +install_wpcli() { + + if ! type wp >/dev/null 2>&1; then + curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar + if php wp-cli.phar --info ; then + chmod +x wp-cli.phar + sudo mv wp-cli.phar /usr/local/bin/wp + else + errsay "WP-CLI didn't install correctly, please see why." + fi + fi + + if type wp >/dev/null 2>&1; then + cd "${HOME}" || exit + mkdir .bash_completions + cd .bash_completions || exit + if [[ -e "${HOME}"/.bash_completions/wp-completion.bash ]]; then + curl -O https://raw.githubusercontent.com/wp-cli/wp-cli/v1.5.1/utils/wp-completion.bash + echo "source \"${HOME}\"/.bash_completions/wp-completion.bash" >> "${HOME}"/.bash_profile + fi + fi + + + tinysay "Installing Blade Plugin for ${ink_yellow}WP-CLI${ink_grey}" + tinysay "This will allow you to compile, wipe, or clear the blade cache files used in Sage 9." + php -d memory_limit=-1 "$(which wp)" package install git@github.com:alwaysblank/blade-generate.git + + source "${HOME}"/.bash_profile + +} + +# Sets up MySQL/MariaDB +setup_mysql() { + tinysay "${ink_yellow}Opening up MySQL portion of install, this will require user interaction. Enter in a password, then just hit enter.${ink_clear}" + secs=$((10)) + while [ $secs -gt 0 ]; do + tinysay "${secs}…" + sleep 1 + : $((secs--)) + done + mysql_secure_installation --user=${dbUserName} --password=${dbUserPass} +} + +# Installs valet +install_valet() { + if ! type composer >/dev/null 2>&1; then + tinysay "Beginning the installation of ${ink_yellow}laravel/valet${ink_grey}, your dev env." + composer global require laravel/valet + if ! type valet >/dev/null 2>&1; then + tinysay "Valet's downloaded, let's install it." + valet install + sudo valet trust + valet domain "${getTLS}" + cd "${path}" || exit + if [[ ! -d ${sitepath} ]]; then + mkdir Sites + fi + cd "${sitepath}" || exit + valet park + sucsay "You now have a Sites directory located at ${sitepath}. You can create new folders within here, and valet will serve them in your browser using the ${getTLS} as your TLS." + fi + fi +} + +# Installs phpmyadmin and adds a syslink to the Sites directory +install_phpmyadmin() { + cd "${sitepath}" || exit + brew install phpmyadmin + ln -s /usr/local/share/phpmyadmin . + valet secure phpmyadmin +} + +# Main Script Start +cache_sudo_password +collect_install_parameters +install_homebrew +install_homebrew_packages +brew_error_checks +bash_profile_write +install_npm_packages +install_wpcli +setup_mysql +install_valet +install_phpmyadmin \ No newline at end of file diff --git a/clique_wp.sh b/clique_wp.sh deleted file mode 100755 index 1e77ec2..0000000 --- a/clique_wp.sh +++ /dev/null @@ -1,254 +0,0 @@ -#!/bin/bash - -# Styles -VP_NONE='\033[00m' -VP_RED='\033[01;31m' -VP_GREEN='\033[01;32m' -VP_YELLOW='\033[01;33m' -VP_PURPLE='\033[01;35m' -VP_CYAN='\033[01;36m' -VP_WHITE='\033[01;37m' -VP_BOLD='\033[1m' -VP_UNDERLINE='\033[4m' - -# Setup some folder paths to variables -folderPath=$HOME/Sites/ -dirName=${PWD##*/} -installPath=$folderPath/$dirName/ -wpBoilerplate=$folderPath/wp-boilerplate/ -url="https://$dirName.app" - -# Inform the user that this is assuming they're using Valet-plus -echo -e "${VP_CYAN}This bash script is under the assumption that you are using valet-plus to set up this WordPress install.${VP_NONE}" -echo -e "${VP_CYAN}${VP_BOLD}This script will now clear your terminal window.${VP_NONE}" -echo "" -echo -e "${VP_WHITE}${VP_BOLD}Please press enter to continue." -read clearTerminal - -clear && printf '\e[3J' - -# We will now try to cache the sudo password, as we'll be setting up an SSL for their dev environment -echo -e "${VP_RED}${VP_BOLD}You may be asked twice for your password, but this is to setup an SSL locally to best mimic a live environment.${VP_NONE}" -sudo -v - -# Set the Site Name -echo -e "Enter the site name." -read siteName -echo "" - -echo -e "Enter a blog description (optional)." -read $blogDescription -echo "" - -# Set the database name -echo -e "Enter your chosen database name." -echo -e "${VP_CYAN}Note:${VP_WHITE} wp_ is automatically prefixed" -read dbName -echo "" - -# Fetch the latest files from the wp-boilerplate repo and then pull it -cd $wpBoilerplate -git fetch --force -git pull --force - -# With a fresh pull, copy the zip file into the new project folder and unzip the contents -cp -a ./*.zip $installPath -cd $installPath -unzip -q ./*.zip - -wp core update - -# Copy the .sql file, and rename it -cp ./dup-installer/*.sql ./import.sql - -# We want to remove the wp-config file here and create a new one -echo -e "${VP_RED}Deleting wp-config file and creating a new one.${VP_NONE}${VP_WHITE}" -rm -rf wp-config.php - -echo -e "Creating database and setting up wp-config.php file." -wp config create --dbname=wp_$dbName --dbuser=root --dbpass=root --extra-php </dev/null 2>&1 && ! type valet >/dev/null 2>&1; then + err "${ink_red}This script requires the installation of wp-cli and valet or valet plus" + tinyerr "You can install ${ink_blue}wp-cli${ink_red} using Homebrew or by visiting ${ink_purple}https://wp-cli.org" + tinyerr "You can install ${ink_blue}valet${ink_red} from ${ink_purple}https://laravel.com/docs/master/valet" + tinyerr "OR" + tinyerr "You can install ${ink_blue}valet-plus${ink_red} from ${ink_purple}https://github.com/weprovide/valet-plus" + say "Exiting script\\n" && exit 0 + fi + + say "This script is under the assumption that you're using ${ink_blue}valet${ink_gray} or ${ink_blue}valet-plus${ink_gray} to setup this WordPress environment." + confirm "Would you like to continue? ${yes_no}" + clear + say "Starting new WordPress environment setup ..." + +} + +cache_sudo_password () { + + say "Please enter your local user password." + sudo -k ; sudo -v && tinysay "${ink_blue}OK" + +} + +collect_environment_information () { + + say "Please provide the necessary information for the new environment:" + nl + askinfo "Site name:" siteName + askinfo "Enter your TLS (omit the period [.] ): " domainTLS + askinfo "Install SSL (default: yes): ${yes_no}" addSSL + askinfo "WordPress version (default: latest):" wpVersion + askinfo "MySQL Localhost or IP (default: localhost):" dbHost + askinfo "Database Name (include prefix if desired):" dbName + askinfo "Database Table Prefix (default: wp_):" dbTablePrefix + askinfo "Database User Name (default: root):" dbUserName + askinfo "Database User Password:" dbUserPass + askinfo "WP Admin User Name:" adminUserName + askinfo "WP Admin User Password:" adminUserPass + askinfo "WP Admin Email:" adminUserEmail + askinfo "Install Blank Site; This will still install ${ink_yellow}Twentynineteen${ink_gray} theme (default: no): ${yes_no}" blankInstall + askinfo "Disable Comments (default: no): ${yes_no}" disableComments + askinfo "Disable Trackbacks (default: no): ${yes_no}" disableTrackbacks + askinfo "Create additional pages? ${yes_no}" createPages + + sslURL="https://${PWD##*/}.${domainTLS}" + nonSSLURL="http://${PWD##*/}.${domainTLS}" + + # setting defaults if values were omitted + if [[ -z "${domainTLS}" ]] ; then tinysay "You must enter a TLS. Exiting script\\n" && exit 0 ; fi + if [[ -z "${addSSL}" ]] ; then addSSL="yes" ; fi + if [[ -z "${dbHost}" ]] ; then dbHost="localhost" ; fi + if [[ -z "${dbName}" ]] ; then + err "\\nYou didn't enter in a database name." + askinfo "Database Name (include prefix if desired):" dbName + fi + if [[ -z "${dbTablePrefix}" ]] ; then dbTablePrefix="wp_" ; fi + if [[ -z "${dbUserName}" ]] ; then dbUserName="root" ; fi + if [[ -z "${dbUserPass}" ]] ; then dbUserPass="" ; fi + if [[ -z "${wpVersion}" ]] ; then wpVersion="latest" ; fi + if [[ -z "${disableComments}" ]] ; then disableComments="no" ; fi + if [[ -z "${disableTrackbacks}" ]] ; then disableTrackbacks="no" ; fi + if [[ -z "${blankInstall}" ]] ; then blankInstall="no" ; fi + if [[ "${createPages}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then create_pages ; fi + + say "The ${ink_yellow}new environment${ink_gray} will be created with the following information:" + nl + tinysay "Site name: ${ink_yellow}${siteName}" + if [[ "${addSSL}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + tinysay "URL: ${ink_yellow}${sslURL}" + else + tinysay "URL: ${ink_yellow}${nonSSLURL}" + fi + tinysay "WordPress version: ${ink_yellow}${wpVersion}" + tinysay "Database Host: ${ink_yellow}${dbHost}" + tinysay "Database Name: ${ink_yellow}${dbName}" + tinysay "Database Table Prefix: ${ink_yellow}${dbTablePrefix}" + tinysay "Database User Name: ${ink_yellow}${dbUserName}" + if [[ -z "${dbUserPass}" ]] ; then + tinysay "Database User Password: ${ink_yellow}No Password" + else + tinysay "Database User Password: ${ink_yellow}${dbUserPass}" + fi + tinysay "WP Admin User Name: ${ink_yellow}${adminUserName}" + tinysay "WP Admin User Password: ${ink_yellow}${adminUserPass}" + tinysay "WP Admin User Email: ${ink_yellow}${adminUserEmail}" + if [[ "${blankInstall}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + tinysay "Default Contents: ${ink_yellow}TwentyNineteen Theme Only" + fi + if [[ "${createPages}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + tinysay "Creating pages: ${ink_yellow}${pageList}" + fi + + confirm "Would you like to continue? ${yes_no}" + +} + +download_wordpress () { + + say "Downloading WordPress ..." + if [[ "${wpVersion}" == "latest" ]] ; then + if [[ "${blankInstall}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + if ! wp core download --skip-content ; then + errsay "Error during WordPress download" ; exit 1 + fi + else + if ! wp core download ; then + errsay "Error during WordPress download" ; exit 1 + fi + fi + else + if [[ "${blankInstall}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + if ! wp core download --version="${wpVersion}" --skip-content; then + errsay "Error during WordPress download" ; exit 1 + fi + else + if ! wp core download --version="${wpVersion}" ; then + errsay "Error during WordPress download" ; exit 1 + fi + fi + fi + +} + +create_wp_config () { + + say "Creating WordPress configuration file (wp-config.php) ..." + rm -rf wp-config.php + if ! wp config create --dbhost=${dbHost} --dbname="${dbName}" --dbuser="${dbUserName}" --dbpass="${dbUserPass}" --dbprefix="${dbTablePrefix}" + then errsay "Error during creation of wp-config.php" ; exit 1 ; fi + +} + +create_wp_database () { + + say "Creating WordPress database ..." + if ! wp db create ; then + errsay "Error during database creation" ; exit 1 + fi + +} + +build_wp_site () { + + say "Building WordPress site ..." + if ! wp core install --url="${dirName}.${domainTLS}" --title="${siteName}" --admin_user="${adminUserName}" --admin_password="${adminUserPass}" --admin_email="${adminUserEmail}" ; then + errsay "Error during building of site" ; exit 1 + fi + + if [[ "${blankInstall}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + add_missing_folders + + fi + + say "Changing ${ink_yellow}\"Sampe Page\"${ink_gray} to ${ink_yellow}\"Home\"${ink_gray}" + wp post update 2 --post_title=Home --post_name=home --post_type=page --post_status=publish --post_content= --post_excerpt= + + say "Setting \"Home\" as the Front Page" + wp option update show_on_front 'page' + wp option update page_on_front 2 + + say "Changing timezone to Chicago" + wp option update timezone_string "America/Chicago" + + if [[ "${disableComments}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then disable_comments ; fi + if [[ "${disableTrackbacks}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then disable_tackbacks ; fi + if [[ "${createPages}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then loop_create_pages ; fi + + say "Flushing permalinks" + wp rewrite structure /%postname%/ + wp cache flush + +} + + +enable_tls_for_env () { + + if [[ "${addSSL}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + say "Enabling TLS for site ..." + if ! valet secure "${dirName}" ; then + errsay "Error while securing site" + fi + fi + +} + +setup_complete() { + say "Environment sucessfully setup." + tinysay "You may now sign in to your website." + nl + if [[ "${addSSL}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + tinysay "Front End URL: ${ink_yellow}${sslURL}" + tinysay "Back End URL: ${ink_yellow}${sslURL}/wp-admin" + else + tinysay "Front End URL: ${ink_yellow}${nonSSLURL}" + tinysay "Back End URL: ${ink_yellow}${nonSSLURL}/wp-admin" + fi + nl + tinysay "Login Credentials" + tinysay "Admin User Name: ${ink_yellow}${adminUserName}" + tinysay "Admin User Password: ${ink_yellow}${adminUserPass}" +} + +# Conditional Functions +add_missing_folders() { + if [[ "${blankInstall}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + mkdir wp-content/themes wp-content/plugins + say "Installing TwentyNinteent Theme to confirm site is setup." + if ! wp theme install twentynineteen --activate ; then + errsay "Error installing Twentynineteen theme. Contact script creator to correct the issue" && exit 0; + fi + fi +} + +create_pages() { + say "You can choose to create top level pages you know you'll need here, otherwise just hit enter to skip this." + say "Please separate page names with a semicolon (;) with no space after it. The ${VP_CYAN}Homepage${VP_WHITE} is already created." + say "${VP_CYAN}Example:${VP_WHITE} About Us;Contact Us;Blog ${VP_NONE}" + nl + read -r pageList +} + +loop_create_pages() { + + if [[ -n "${pageList}" || "${pageList}" != *"," ]] ; + then + say "Creating pages…" + IFS=";" + for i in ${pageList} + do + wp post create --post_title="${i}" --post_type=page --post_status="publish" + done + unset IFS + success "Pages created." + fi +} + +disable_comments() { + say "Disabling Comments…" + wp post list --format=ids | xargs wp post update --comment_status=closed + wp option update default_comment_status "closed" +} + +disable_tackbacks() { + say "Disabling Trackbacks…" + wp post list --format=ids | xargs wp post update --ping_status=closed + wp option update default_ping_status "closed" + wp option update default_pingback_flag 0 +} + +# MAIN +initiate_env_setup +cache_sudo_password +collect_environment_information +download_wordpress +create_wp_config +create_wp_database +build_wp_site +enable_tls_for_env +setup_complete \ No newline at end of file diff --git a/new_wp/tools_install.sh b/new_wp/tools_install.sh new file mode 100755 index 0000000..a184302 --- /dev/null +++ b/new_wp/tools_install.sh @@ -0,0 +1,368 @@ +#!/usr/bin/env bash + +# USAGE +usage() { echo -e " +USAGE: ${0} [OPTIONS]\\n +OPTIONS:\\n +-m (optional) Monochrome output colors +-q (optional) Suppress informational messages +-h Display this usage information\\n +"; } + +# OPTIONS +while getopts "mqh" opt ; do + case "${opt}" in + m) monochrome="yes" ;; + q) quiet="yes" ;; + h) usage ; exit 0 ;; + *) usage ; exit 1 ;; + esac +done + +# COMMON VARIABLES & FUNCTIONS +# colors +if [[ -n "${monochrome}" ]] ; then + ink_clear="\\x1b[0m" + ink_grey="\\x1b[38;5;244m" + ink_red="\\x1b[0m" + ink_green="\\x1b[0m" + ink_blue="\\x1b[0m" + ink_yellow="\\x1b[0m" + ink_purple="\\x1b[0m" +else + ink_clear="\\x1b[0m" + ink_grey="\\x1b[38;5;244m" + ink_red="\\x1b[38;5;204m" + ink_green="\\x1b[38;5;120m" + ink_blue="\\x1b[38;5;081m" + ink_yellow="\\x1b[38;5;228m" + ink_purple="\\x1b[38;5;207m" +fi + +# output +yes_no="${ink_blue}[${ink_clear} ${ink_green}yes${ink_clear} ${ink_blue}/${ink_clear} ${ink_red}no${ink_clear} ${ink_blue}]${ink_clear}" +mysql_maria="${ink_blue}[${ink_clear} ${ink_yellow}mysql${ink_clear} ${ink_blue}/${ink_clear} ${ink_purple}mariadb${ink_clear} ${ink_blue}]${ink_clear}" +latest="${ink_yellow}latest version" +yuicompressor="" +path="${HOME}" +sitepath="${HOME}/Sites" +phpmyadmin=https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-english.tar.gz +nl () { if [[ -z "${quiet}" ]]; then echo; fi; } +say () { if [[ -z "${quiet}" ]]; then echo -e "\\n${ink_grey}${1}${ink_clear}"; fi; } +success () { if [[ -z "${quiet}" ]] ; then echo -e "\\n${ink_green}${1}${ink_clear}" ; fi ; } +tinysay () { if [[ -z "${quiet}" ]] ; then echo -e "${ink_grey}${1}${ink_clear}" ; fi ; } +errsay () { echo -e "\\n${ink_red}${1}. Script aborted!${ink_clear}"; } +sucsay () { echo -e "${ink_green}${1} successfully installed.${ink_clear}"; } +err () { echo -e "\\n${ink_red}${1}${ink_clear}"; } +ask () { echo -en "\\n${ink_grey}${1} ${ink_clear}"; } +askinfo () { echo -en "${ink_grey}${1} ${ink_clear}" ; read -r "${2}" ; } +saysitepath () { echo -en "${ink_grey}${1}: ${ink_clear}\\n${ink_blue}${path} ${ink_clear}" ; } + +# confirm +confirm() { + ask "${1}" + read -r INPUT + case "${INPUT}" in + [yY][eE][sS] | [yY]) ;; + [mM][yY][sS][qQ][lL] | [mM][aA][rR][iI][aA][dD][bB] | [mM][aA][rR][iI][aA]) ;; + [nN][oO] | [nN]) say "Script aborted.\\n" && exit 0 ;; + *) confirm "${1}" ;; + esac +} + +# Cache the sudo password +cache_sudo_password() { + + say "Please enter your local user password." + sudo -k + sudo -v && tinysay "${ink_blue}OK" +} + +# Gather all the Install Parameters +collect_install_parameters() { + + say "This script will install the basic tools used for local development." + nl + + confirm "Would you like to continue? ${yes_no}" + clear + + askinfo "Would you like to use MySQL or mariaDB? mariaDB runs SQL statements quicker and uses less resources compared to MySQL, though may eventually become uncompatible with MySQL: ${mysql_maria}" dbStructure + askinfo "${dbStructure} username (default: root):" dbUserName + askinfo "${dbStructure} password (default: root):" dbUserPass + nl + tinysay "What TLS would you like your sites to be served under? Default is ${ink_blue}test${ink_grey}" + askinfo "${ink_red}Note${ink_grey}: Using ${ink_blue}app${ink_grey} or ${ink_blue}dev${ink_grey} will require you to run ${ink_yellow}valet secure {folder_name}${ink_grey} before visiting the page:" getTLS + askinfo "Install phpmyadmin? ${yes_no}: " installPhpMyAdmin + askinfo "If using phpStorm, would you like to install yuicompressor for JavaScript and CSS minification watcher? ${yes_no}" getYUI + + # # setting defaults if values were omitted + if [[ -z "${dbStructure}" ]]; then dbStructure="mariadb"; fi + if [[ -z "${getTLS}" ]]; then getTLS="test"; fi + if [[ -z "${getYUI}" ]]; then getYUI="no"; fi + if [[ -z "${dbUserName}" ]] ; then dbUserName="root" ; fi + if [[ -z "${dbUserPass}" ]] ; then dbUserPass="root" ; fi + + say "This ${ink_yellow}computer${ink_grey} will have the following installed:" + nl + + say "${ink_green}PACKAGE MANAGER" + tinysay "${ink_blue}Homebrew${ink_grey} - A tool/repo installer similar to NPM" + tinysay "${ink_blue}Composer${ink_grey}: ${latest}" + tinysay "${ink_blue}Node/NPM${ink_grey}: ${latest}" + nl + + say "${ink_green}ENVIRONMENT" + tinysay "${ink_blue}Laravel Valet${ink_grey} - Local Dev Environment." + tinysay "${ink_blue}php${ink_grey}: ${ink_yellow}Latest Version of 7" + tinysay "${ink_blue}Database${ink_grey}: ${ink_yellow}${dbStructure}" + tinysay "${ink_blue}Database username${ink_grey}: ${ink_yellow}${dbUserName}" + tinysay "${ink_blue}Database password${ink_grey}: ${ink_yellow}${dbUserPass}" + + if [[ "${installPhpMyAdmin}" != n* ]]; then + tinysay "${ink_blue}phpMyAdmin${ink_grey}: ${latest}" + fi + tinysay "${ink_blue}Local site TLS${ink_grey}: ${ink_yellow}${getTLS}" + nl + + say "${ink_green}TOOLS" + tinysay "${ink_blue}Gulp${ink_grey} - Sage8 Projects: ${latest}" + tinysay "${ink_blue}WP-CLI${ink_grey}: ${latest}" + tinysay "${ink_blue}Yarn${ink_grey} (for Sage9 Projects): ${latest}" + if [[ "${getYUI}" != n* ]]; then + tinysay "${ink_blue}YUICompressor${ink_grey}: ${latest}" + fi + nl + + confirm "Would you like to continue? ${yes_no}" +} + +# Install homebrew +install_homebrew() { + if ! hash brew 2>/dev/null; then + say "Downloading and installing Homebrew. Please wait…" + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + say "Homebrew is installed. You can use it to install packages by calling to the command ${ink_blue}brew${ink_grey}" + confirm "Would you like to continue? ${yes_no}" + else + tinysay "Homebrew is already installed. You can call to it with the command ${ink_blue}brew${ink_grey}" + confirm "Would you like to continue? ${yes_no}" + fi +} + +# Install Composer, node, php, wget, SASS, yuicompressor, and database of choice +install_homebrew_packages() { + if ! type brew >/dev/null 2>&1; then + if [[ "${getYUI}" != n* ]] ; then + yuicompressor="yuicompressor" + fi + + tinysay "Installing ${ink_yellow} brew packages${ink_grey}. Please wait…" + brew install composer node php wget sass/sass/sass ${dbStructure} ${yuicompressor} + brew services start ${dbStructure} + tinysay "${ink_green}Install Complete!${ink_grey}" + fi +} + +# Check for any errors when installing brew packages +brew_error_checks() { + tinysay "Checking ${ink_blue}brew${ink_grey} for errors." + + if ! type composer >/dev/null 2>&1; then + errsay "There was an error installing Composer. Please review why and report back to the script creator." + else + sucsay composer + fi + + if ! type mysql >/dev/null 2>&1; then + errsay "There was an error installing ${dbStructure}. Please review why and report back to the script creator." + else + sucsay ${dbStructure} + fi + + if ! type node >/dev/null 2>&1; then + errsay "There was an error installing Node. Please review why and report back to the script creator." + else + sucsay node + fi + + if ! type php >/dev/null 2>&1; then + errsay "There was an error installing php. Please review why and report back to the script creator." + else + sucsay php + fi + + if ! type sass >/dev/null 2>&1; then + errsay "There was an error installing sass. Please review why and report back to the script creator." + else + sucsay sass + fi + + if ! type wget >/dev/null 2>&1; then + errsay "There was an error installing wget. Please review why and report back to the script creator." + else + sucsay wget + fi + + if [[ "${getYUI}" != n* ]] ; then + if ! type yuicompressor >/dev/null 2>&1; then + errsay "There was an error installing yuicompressor. Please review why and report back to the script creator." + else + sucsay yuicompressor + fi + fi +} + +# Writes exports to ./bash_profile +bash_profile_write() { + if [[ ! -e "${HOME}"/.bash_profile ]]; then + tinysay "Creating a .bash_profile file at ${HOME}" + fi + + if ! grep -q "export PATH" "${HOME}"/.bash_profile; then + tinysay "Adding export PATH to ~/.bash_profile" + echo "export PATH" >> "${HOME}"/.bash_profile + fi + + if ! grep -q "export PATH=\"$PATH:${HOME}/npm/bin\"" "${HOME}"/.bash_profile; then + tinysay "Adding NPM to your \$PATH" + echo "export PATH=\"$PATH:${HOME}/npm/bin\"" >> "${HOME}"/.bash_profile + fi + + if ! grep -q "export PATH=\"/usr/local/bin:$PATH\"" "${HOME}"/.bash_profile; then + tinysay "Adding bin to your \$Path" + echo "export PATH=\"/usr/local/bin:$PATH\"" >> "${HOME}"/.bash_profile + fi + + if ! grep -q "export PATH=\"/usr/local/sbin:$PATH\"" "${HOME}"/.bash_profile; then + tinysay "Adding sbin to your \$Path" + echo "export PATH=\"/usr/local/sbin:$PATH\"" >> "${HOME}"/.bash_profile + fi + + if ! grep -q "export PATH=\"$PATH:${HOME}/.composer/vendor/bin\"" "${HOME}"/.bash_profile; then + tinysay "Adding Composer to ~/.bash_profile" + echo "export PATH=\"$PATH:${HOME}/.composer/vendor/bin\"" >> "${HOME}"/.bash_profile + fi + + # Make an SSH Alias file + mkdir "${HOME}"/.custom_bash_files + cd "${HOME}"/.custom_bash_files || exit + cat > .alias_ssh.sh + echo "# This file can be used to set aliases for utiliing ssh for servers" > .alias_ssh.sh + echo "# Example: alias sitessh=\"ssh root@test.sandbox6.cliquedomains.com\" would create a quick tab completeion to ssh into the Sandbox 6 Digital Ocean Server." >> .alias_ssh.sh + nl + cat > .alias_commands.sh + echo "# This file can be used to set up various alias' needed to make development easier." > .alias_commands.sh + + source "${HOME}"/.bash_profile + tinysay "Reloaded your ${ink_yellow}.bash_proflie${ink_grey}" + +} + +# Installs npm packages +install_npm_packages() { + if type npm >/dev/null 2>&1; then + if ! type yarn >/dev/null 2>&1; then + tinysay "Installing ${ink_blue}yarn${ink_grey}" + npm install -g yarn + if ! yarn -v; then + errsay "There was an error installing yarn. Please review why and report back to the script creator." ; exit 1 + fi + sucsay "yarn" + fi + if ! type gulp >/dev/null 2>&1; then + tinysay "Installing ${ink_blue}gulp${ink_grey}" + npm install -g gulp + if ! gulp -v; then + errsay "There was an error installing gulp. Please review why and report back to the script creator." ; exit 1 + fi + sucsay "Gulp" + fi + fi +} + +# Installs WP-CLI and wp-completion.bash +install_wpcli() { + + if ! type wp >/dev/null 2>&1; then + curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar + if php wp-cli.phar --info ; then + chmod +x wp-cli.phar + sudo mv wp-cli.phar /usr/local/bin/wp + else + errsay "WP-CLI didn't install correctly, please see why." + fi + fi + + if type wp >/dev/null 2>&1; then + cd "${HOME}" || exit + mkdir .bash_completions + cd .bash_completions || exit + if [[ -e "${HOME}"/.bash_completions/wp-completion.bash ]]; then + curl -O https://raw.githubusercontent.com/wp-cli/wp-cli/v1.5.1/utils/wp-completion.bash + echo "source \"${HOME}\"/.bash_completions/wp-completion.bash" >> "${HOME}"/.bash_profile + fi + fi + + + tinysay "Installing Blade Plugin for ${ink_yellow}WP-CLI${ink_grey}" + tinysay "This will allow you to compile, wipe, or clear the blade cache files used in Sage 9." + php -d memory_limit=-1 "$(which wp)" package install git@github.com:alwaysblank/blade-generate.git + + source "${HOME}"/.bash_profile + +} + +# Sets up MySQL/MariaDB +setup_mysql() { + tinysay "${ink_yellow}Opening up MySQL portion of install, this will require user interaction. Enter in a password, then just hit enter.${ink_clear}" + secs=$((10)) + while [ $secs -gt 0 ]; do + tinysay "${secs}…" + sleep 1 + : $((secs--)) + done + mysql_secure_installation --user=${dbUserName} --password=${dbUserPass} +} + +# Installs valet +install_valet() { + if ! type composer >/dev/null 2>&1; then + tinysay "Beginning the installation of ${ink_yellow}laravel/valet${ink_grey}, your dev env." + composer global require laravel/valet + if ! type valet >/dev/null 2>&1; then + tinysay "Valet's downloaded, let's install it." + valet install + sudo valet trust + valet domain "${getTLS}" + cd "${path}" || exit + if [[ ! -d ${sitepath} ]]; then + mkdir Sites + fi + cd "${sitepath}" || exit + valet park + sucsay "You now have a Sites directory located at ${sitepath}. You can create new folders within here, and valet will serve them in your browser using the ${getTLS} as your TLS." + fi + fi +} + +# Installs phpmyadmin and adds a syslink to the Sites directory +install_phpmyadmin() { + cd "${sitepath}" || exit + brew install phpmyadmin + ln -s /usr/local/share/phpmyadmin . + valet secure phpmyadmin +} + +# Main Script Start +cache_sudo_password +collect_install_parameters +install_homebrew +install_homebrew_packages +brew_error_checks +bash_profile_write +install_npm_packages +install_wpcli +setup_mysql +install_valet +install_phpmyadmin \ No newline at end of file diff --git a/wp_install.sh b/wp_install.sh new file mode 100755 index 0000000..2d1b12f --- /dev/null +++ b/wp_install.sh @@ -0,0 +1,303 @@ +#!/usr/bin/env bash + +# change to script directory +#cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1 + +# USAGE +usage () { echo -e " +USAGE: ${0} [OPTIONS]\\n +OPTIONS:\\n +-m (optional) Monochrome output colors +-q (optional) Suppress informational messages +-h Display this usage information\\n +" ; } + +# OPTIONS +while getopts "mqh" opt ; do + case "${opt}" in + m) monochrome="yes" ;; + q) quiet="yes" ;; + h) usage ; exit 0 ;; + *) usage ; exit 1 ;; + esac +done + +# COMMON VARIABLES & FUNCTIONS +# colors +if [[ -n "${monochrome}" ]] ; then + ink_clear="\\x1b[0m" + ink_gray="\\x1b[38;5;244m" + ink_red="\\x1b[0m" + ink_green="\\x1b[0m" + ink_blue="\\x1b[0m" + ink_yellow="\\x1b[0m" + ink_purple="\\x1b[0m" +else + ink_clear="\\x1b[0m" + ink_gray="\\x1b[38;5;244m" + ink_red="\\x1b[38;5;204m" + ink_green="\\x1b[38;5;120m" + ink_blue="\\x1b[38;5;081m" + ink_yellow="\\x1b[38;5;228m" + ink_purple="\\x1b[38;5;207m" +fi + +# output +yes_no="${ink_blue}[${ink_clear} ${ink_green}yes${ink_clear} ${ink_blue}/${ink_clear} ${ink_red}no${ink_clear} ${ink_blue}]${ink_clear}" +nl () { if [[ -z "${quiet}" ]] ; then echo ; fi ; } +say () { if [[ -z "${quiet}" ]] ; then echo -e "\\n${ink_gray}${1}${ink_clear}" ; fi ; } +tinysay () { if [[ -z "${quiet}" ]] ; then echo -e "${ink_gray}${1}${ink_clear}" ; fi ; } +errsay () { echo -e "\\n${ink_red}${1}. Script aborted!${ink_clear}" ; } +err () { echo -e "\\n${ink_red}${1}${ink_clear}" ; } +tinyerr () { echo -e "${ink_red}${1}${ink_clear}" ; } +ask () { echo -en "\\n${ink_gray}${1} ${ink_clear}" ; } +askinfo () { echo -en "${ink_gray}${1} ${ink_clear}" ; read -r "${2}" ; } + +# confirm +confirm () { + ask "${1}" + read -r INPUT + case "${INPUT}" in + [yY][eE][sS] | [yY]) ;; + [nN][oO] | [nN]) say "Script aborted.\\n" && exit 0 ;; + *) confirm "${1}" ;; + esac +} + +# PRE-FLIGHT CHECKS +#if [[ ! -d ./.git ]] ; then errsay "No cloned repository found" ; exit 1 ; fi + +# VARIABLES +dirName=${PWD##*/} + +# FUNCTIONS +initiate_env_setup () { + + if ! type wp >/dev/null 2>&1 && ! type valet >/dev/null 2>&1; then + err "${ink_red}This script requires the installation of wp-cli and valet or valet plus" + tinyerr "You can install ${ink_blue}wp-cli${ink_red} using Homebrew or by visiting ${ink_purple}https://wp-cli.org" + tinyerr "You can install ${ink_blue}valet${ink_red} from ${ink_purple}https://laravel.com/docs/master/valet" + tinyerr "OR" + tinyerr "You can install ${ink_blue}valet-plus${ink_red} from ${ink_purple}https://github.com/weprovide/valet-plus" + say "Exiting script\\n" && exit 0 + fi + + say "This script is under the assumption that you're using ${ink_blue}valet-plus${ink_gray} to setup this WordPress environment." + confirm "Would you like to continue? ${yes_no}" + clear + tinysay "Starting new WordPress environment setup ..." + +} + +cache_sudo_password () { + + say "Please enter your local user password." + sudo -k ; sudo -v && tinysay "${ink_blue}OK" + +} + +collect_environment_information () { + + say "Please provide the necessary information for the new environment:" + nl + askinfo "Site name:" siteName + askinfo "Enter your TLS: " domainTLS + askinfo "Install SSL (default: yes): ${yes_no}" addSSL + askinfo "WordPress version (default: latest):" wpVersion + askinfo "Database name (wp_ will be prefixed):" dbName + askinfo "Database user name (default: root):" dbUserName + askinfo "Database user pass (default: root):" dbUserPass + askinfo "Admin user name:" adminUserName + askinfo "Admin user pass:" adminUserPass + askinfo "Admin user email:" adminUserEmail + askinfo "Install Blank Site (default: no): ${yes_no}" blankInstall + askinfo "Disable Comments (default: no): ${yes_no}" disableComments + askinfo "Disable Trackbacks (default: no): ${yes_no}" disableTrackbacks + askinfo "Create additional pages? ${yes_no}" createPages + + sslURL="https://${PWD##*/}.${domainTLS}" + nonSSLURL="http://${PWD##*/}.${domainTLS}" + + # setting defaults if values were omitted + if [[ -z "${domainTLS}" ]] ; then tinysay "You must enter a TLS. Exiting script\\n" && exit 0 ; fi + if [[ -z "${addSSL}" ]] ; then addSSL="yes" ; fi + if [[ -z "${wpVersion}" ]] ; then wpVersion="latest" ; fi + if [[ -z "${dbUserName}" ]] ; then dbUserName="root" ; fi + if [[ -z "${dbUserPass}" ]] ; then dbUserPass="root" ; fi + if [[ -z "${disableComments}" ]] ; then disableComments="no" ; fi + if [[ -z "${disableTrackbacks}" ]] ; then disableTrackbacks="no" ; fi + if [[ -z "${blankInstall}" ]] ; then blankInstall="no" ; fi + if [[ "${createPages}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then create_pages ; fi + + say "The ${ink_yellow}new environment${ink_gray} will be created with the following information:" + nl + tinysay "Site name: ${ink_yellow}${siteName}" + if [[ "${addSSL}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + tinysay "URL: ${ink_yellow}${sslURL}" + else + tinysay "URL: ${ink_yellow}${nonSSLURL}" + fi + tinysay "WordPress version: ${ink_yellow}${wpVersion}" + tinysay "Database name: ${ink_yellow}wp_${dbName}" + tinysay "Database user name: ${ink_yellow}${dbUserName}" + tinysay "Database user pass: ${ink_yellow}${dbUserPass}" + tinysay "Admin user name: ${ink_yellow}${adminUserName}" + tinysay "Admin user pass: ${ink_yellow}${adminUserPass}" + tinysay "Admin user email: ${ink_yellow}${adminUserEmail}" + if [[ "${createPages}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + tinysay "Creating pages: ${ink_yellow}${pageList}" + fi + + confirm "Would you like to continue? ${yes_no}" + +} + +download_wordpress () { + + say "Downloading WordPress ..." + if [[ "${wpVersion}" == "latest" ]] ; then + if [[ "${blankInstall}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + if ! wp core download --skip-content ; then + errsay "Error during WordPress download" ; exit 1 + fi + else + if ! wp core download ; then + errsay "Error during WordPress download" ; exit 1 + fi + fi + else + if [[ "${blankInstall}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + if ! wp core download --version="${wpVersion}" --skip-content; then + errsay "Error during WordPress download" ; exit 1 + fi + else + if ! wp core download --version="${wpVersion}" ; then + errsay "Error during WordPress download" ; exit 1 + fi + fi + fi + +} + +create_wp_config () { + + say "Creating WordPress configuration file (wp-config.php) ..." + rm -rf wp-config.php + if ! wp config create --dbname=wp_"${dbName}" --dbuser="${dbUserName}" --dbpass="${dbUserPass}" + then errsay "Error during creation of wp-config.php" ; exit 1 ; fi + +} + +create_wp_database () { + + say "Creating WordPress database ..." + if ! wp db create ; then + errsay "Error during database creation" ; exit 1 + fi + +} + +build_wp_site () { + + say "Building WordPress site ..." + if ! wp core install --url="${dirName}.app" --title="${siteName}" --admin_user="${adminUserName}" --admin_password="${adminUserPass}" --admin_email="${adminUserEmail}" ; then + errsay "Error during building of site" ; exit 1 + fi + + tinysay "Changing ${ink_yellow}\"Sampe Page\"${ink_gray} to ${ink_yellow}\"Home\"${ink_gray}" + wp post update 2 --post_title=Home --post_name=home --post_type=page --post_status=publish --post_content= --post_excerpt= + + tinysay "Setting \"Home\" as the Front Page" + wp option update show_on_front 'page' + wp option update page_on_front 2 + + tinysay "Changing timezone to Chicago" + wp option update timezone_string "America/Chicago" + + if [[ "${disableComments}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then disable_comments ; fi + if [[ "${disableTrackbacks}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then disable_tackbacks ; fi + if [[ "${createPages}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then loop_create_pages ; fi + + tinysay "Flushing permalinks" + wp cache flush + wp rewrite structure /%postname%/ + wp rewrite flush + +} + + +enable_tls_for_env () { + + if [[ "${addSSL}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + say "Enabling TLS for site ..." + if ! valet secure "${dirName}" ; then + errsay "Error while securing site" + fi + fi + +} + +setup_complete() { + say "Environment sucessfully setup." + tinysay "You may now sign in to your website." + nl + if [[ "${addSSL}" =~ ^([yY][eE][sS]|[yY])+ ]] ; then + tinysay "Front End URL: ${ink_yellow}${sslURL}" + tinysay "Back End URL: ${ink_yellow}${sslURL}/wp-admin" + else + tinysay "Front End URL: ${ink_yellow}${nonSSLURL}" + tinysay "Back End URL: ${ink_yellow}${nonSSLURL}/wp-admin" + fi + nl + tinysay "Login Credentials" + tinysay "Admin User Name: ${ink_yellow}${adminUserName}" + tinysay "Admin User Password: ${ink_yellow}${adminUserPass}" +} + +# Conditional Functions +create_pages() { + say "You can choose to create top level pages you know you'll need here, otherwise just hit enter to skip this." + say "Please separate page names with a semicolon (;) with no space after it. The ${VP_CYAN}Homepage${VP_WHITE} is already created." + say "${VP_CYAN}Example:${VP_WHITE} About Us;Contact Us;Blog ${VP_NONE}" + nl + read -r pageList +} + +loop_create_pages() { + + if [[ -n "${pageList}" || "${pageList}" != *"," ]] ; + then + tinysay "Creating pages…" + IFS=";" + for i in ${pageList} + do + wp post create --post_title="${i}" --post_type=page --post_status="publish" + done + unset IFS + tinysay "Pages created." + fi +} + +disable_comments() { + tinysay "Disabling Comments…" + wp post list --format=ids | xargs wp post update --comment_status=closed + wp option update default_comment_status "closed" +} + +disable_tackbacks() { + tinysay "Disabling Trackbacks…" + wp post list --format=ids | xargs wp post update --ping_status=closed + wp option update default_ping_status "closed" + wp option update default_pingback_flag 0 +} + +# MAIN +initiate_env_setup +cache_sudo_password +collect_environment_information +download_wordpress +create_wp_config +create_wp_database +build_wp_site +enable_tls_for_env +setup_complete \ No newline at end of file