Skip to content

Commit

Permalink
Multiple changes, and fixes. Please see CHANGELOG.md
Browse files Browse the repository at this point in the history
  • Loading branch information
sdenike committed Apr 27, 2022
1 parent fea5e59 commit a1f73a0
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 50 deletions.
3 changes: 3 additions & 0 deletions config.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
"open_browser": "1",
"browser": "Safari",
"valet_domain": "test",
"secure_domain": "1",
"plugins_add": "hide-admin-bar wordpress-seo",
"plugins_remove": "akismet hello",
"auto_update": "0",
"php": "/bin/php",
"valet": "/bin/valet",
"wpcli": "/bin/wp"
}
24 changes: 14 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# ValetPress

ValetPress allows for the quick installation and configuration of WordPress install for local development and testing. The idea of this script was inspired from the script that @AaronRutley originally created (https://github.com/AaronRutley/valetpress), but has been written from the ground up to provide cleaner code, as well as adding/removing features that I felt were or were not necessary for my daily usage.
ValetPress allows for the quick installation and configuration of WordPress install for local development and testing. The idea of this script was inspired by the script that [@AaronRutley](https://twitter.com/AaronRutley) originally created (https://github.com/AaronRutley/valetpress) but has been written from the ground up to provide cleaner code, as well as adding/removing features that I felt were or were not necessary for my daily usage.

## What?

The script itself uses Laravel Valet and WP-CLI to speed up the creation of a WordPress install on your local system. Before @AaronRutley demoed his script to me I was using MAMP, and/or manually setting up installs on my computer which was far more time consuming than his script was.
The script itself uses Laravel Valet and WP-CLI to speed up the creation of a WordPress install on your local system. Before @AaronRutley demoed his script to me I was using MAMP, and/or manually setting up installs on my computer which was far more time-consuming than his script was.

## Why?

Expand All @@ -14,14 +14,14 @@ While the original script works great… I got bored and decided to rewrite it f

- Create a fresh WordPress site in a few seconds
- Download, Install and activate WordPress
- Auto login to the new WordPress install
- Auto-login to the new WordPress install
- Easily delete the WordPress install(s)

## To install
1. Setup Laravel Valet / MySQL [Instructions](https://laravel.com/docs/5.6/valet#installation)
2. Download / Clone this repo into a directory such as `~/Scripts/valetpress`
3. Include the `vp` script in your `.bash_profile` or `.zshrc` file
4. A Brewfile is included to help with the dependancies that are needed. `brew bundle`
4. A Brewfile is included to help with the dependencies that are needed. `brew bundle`
5. Update the `config.json` file to reflect your needed settings. (see the 'Config Explained' section below)

## Available Commands:
Expand All @@ -37,7 +37,7 @@ While the original script works great… I got bored and decided to rewrite it f

- Lists all ValetPress installations
- Will ask for the name of the project you would like to delete
- Ask you to confim that you wish to delete the project
- Ask you to confirm that you wish to delete the project
- Deletes the database for that project
- Deletes the directory for that project

Expand All @@ -47,18 +47,22 @@ While the original script works great… I got bored and decided to rewrite it f

## Config Explained
- `wp_admin_email` is used as the admin email address for new WP installs.
- `wp_admin_user` is used as the username for new WP installs. [If changed you must update the username in the auto-login plugin](https://github.com/sdenike/valetpress/blob/master/plugins/auto-login/auto-login.php#L18)
- `wp_admin_password` is used as the password for new WP installs. [If changed you must update the password in the auto-login plugin](https://github.com/sdenike/valetpress/blob/master/plugins/auto-login/auto-login.php#L19)
- `wp_admin_user` is used as the username for new WP installs. [If changed you must update the username in the valetpress plugin](https://github.com/SystmWeb/valetpress/blob/master/plugins/valetpress/valetpress.php#L17)
- `wp_admin_password` is used as the password for new WP installs. [If changed you must update the password in the valetpress plugin](https://github.com/SystmWeb/valetpress/blob/master/plugins/valetpress/valetpress.php#L18)
- `sites_folder` is a directory that you've run `valet park` in to serve sites.
- `open_browser` if set to `1` a browser will auto open after the install completes, `0` will make so that it doesn't
- `browser` you can set the default browser such as Safari, or Google Chrome, etc
- `open_browser` if set to `1` a browser will auto-open after the install completes, `0` will make so that it doesn't
- `browser` you can set the default browser such as Safari, Google Chrome, etc
- `valet_domain` Default is set to `test` but you can change this to whatever you use for Valet, this can be adjusted by using `valet domain TLDTOUSE`
- `plugins_add` Plugins that you wish to install/activate on each new install
- `plugins_remove` Plugins that you wish to remove from the default installs
- `auto_update` Enabled auto-updates to core, plugin and theme. 0 = Disabled, 1 = Enabled
- `php` Specify the location of PHP
- `valet` Specify the location of Laravel Valet
- `wpcli` Specify the location of WP-CLI

## Requirements

Below you will find a list of all required system files in order for ValetPress to proper work.
Below you will find a list of all required system files in order for ValetPress to properly work.

- [Valet](https://laravel.com/docs/5.2/valet) - With out this sites will not load
- MySQL or MariaDB - Needed for WordPress
Expand Down
136 changes: 96 additions & 40 deletions vp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [[ "${DEBUG}" ]]; then
set -x
fi

version="2022.3.2.1"
version="2022.4.27.5"

# Added for debugging
set -euo pipefail
Expand Down Expand Up @@ -46,12 +46,32 @@ function white() {

# Core WordPress install function
wordpress_installer () {
# Check if SSL shoud be enabled
if [ "$secure_domain" = 1 ]; then
$php $wpcli core config --dbname="$project_name" --dbuser=root --dbhost=localhost --quiet --extra-php <<PHP
define( 'FS_METHOD', 'direct' );
define( 'WP_ENVIRONMENT_TYPE', 'development' );
define( 'WP_SITEURL', 'https://$project_name.$valet_domain/' );
define( 'WP_HOME', 'https://$project_name.$valet_domain/' );
PHP
green "SSL has been enabled."
else
$php $wpcli core config --dbname="$project_name" --dbuser=root --dbhost=localhost --quiet --extra-php <<PHP
define( 'FS_METHOD', 'direct' );
define( 'WP_ENVIRONMENT_TYPE', 'development' );
define( 'WP_SITEURL', 'http://$project_name.$valet_domain/' );
define( 'WP_HOME', 'http://$project_name.$valet_domain/' );
PHP
red "SSL has not been enabled."
fi

# Enable autoupdate of core, plugins and themes
if [ "$auto_update" = 1 ]; then
wp config set WP_AUTO_UPDATE_CORE true --quiet
wp config set auto_update_plugin __return_false --quiet
wp config set auto_update_theme __return_false --quiet
green "Auto updates have been enabled for core, plugins and themes."
fi
green "wp-config.php has been generated."
$php $wpcli db create --quiet
green "Database created."
Expand All @@ -60,15 +80,35 @@ PHP
cd "$sites_folder"/"$project_name"/
}

# Domain SSL check
ssl_check () {
if [ "$secure_domain" = 1 ]; then
cd $sites_folder/$project_name
sudo $valet secure
green "SSL have been activated."
else
yellow "SSL is NOT activated."
fi
}

# Output WordPress login info
wordpress_login_info () {
white "==================================================================="
if [ "$secure_domain" = "1" ]; then
green "Project Created: https://$project_name.$valet_domain/"
cyan "Login: https://$project_name.$valet_domain/wp-login.php"
else
green "Project Created: http://$project_name.$valet_domain/"
cyan "Login: http://$project_name.$valet_domain/wp-login.php"
fi
cyan "Username: $wp_admin_user"
cyan "Password: $wp_admin_password"
if [ "$open_browser" = 1 ]; then
open -a "$browser" -g http://$project_name.$valet_domain/wp-login.php
if [ "$secure_domain" = "1" ]; then
open -a "$browser" -g https://$project_name.$valet_domain/wp-login.php
else
open -a "$browser" -g http://$project_name.$valet_domain/wp-login.php
fi
fi
echo " "
}
Expand Down Expand Up @@ -103,9 +143,12 @@ sites_folder=$(cat $vp_path/config.json|jq -r .sites_folder)
open_browser=$(cat $vp_path/config.json|jq -r .open_browser)
browser=$(cat $vp_path/config.json|jq -r .browser)
valet_domain=$(cat $vp_path/config.json|jq -r .valet_domain)
secure_domain=$(cat $vp_path/config.json|jq -r .secure_domain)
plugins_add=$(cat $vp_path/config.json|jq -r .plugins_add)
plugins_remove=$(cat $vp_path/config.json|jq -r .plugins_remove)
auto_update=$(cat $vp_path/config.json|jq -r .auto_update)
php=$(cat $vp_path/config.json|jq -r .php)
valet=$(cat $vp_path/config.json|jq -r .valet)
wpcli=$(cat $vp_path/config.json|jq -r .wpcli)

# ValetPress Commands
Expand All @@ -119,7 +162,7 @@ if [ $# -lt 1 ] || [ "$1" = "help" ] || [ "$1" = "-h" ] || [ -z "$1" ];then
exit 1;
else
# ValetPress create option
if [ "$1" = "create" ]; then
if [ "$1" = "create" ] || [ "$1" = "-c" ]; then
white "Please enter the name of your project."
read -p ": " -r project_name
while [[ -z "$project_name" ]]; do
Expand Down Expand Up @@ -148,48 +191,51 @@ else
cyan " 3.) WordPress with specific theme "
read -p "Choice: " -r create_choice

# Default WordPress Install
if [ "$create_choice" = 1 ]; then
yellow "Downloading WordPress."
$php $wpcli core download --quiet
green "WordPress have been downloaded."
wordpress_installer
cp -R $vp_path/plugins/ $sites_folder/$project_name/wp-content/plugins/
plugin_activation
wordpress_login_info
fi
# Default WordPress Install
if [ "$create_choice" = 1 ]; then
yellow "Downloading WordPress."
$php $wpcli core download --quiet
green "WordPress have been downloaded."
wordpress_installer
cp -R $vp_path/plugins/ $sites_folder/$project_name/wp-content/plugins/
plugin_activation
ssl_check
wordpress_login_info
fi

# WordPress with WooCommerce
if [ "$create_choice" = 2 ]; then
yellow "Downloading WordPress."
$php $wpcli core download --quiet
green "WordPress has been downloaded."
wordpress_installer
$php $wpcli plugin install woocommerce --activate
green "WooCommerce has been installed."
cp -R $vp_path/plugins/ $sites_folder/$project_name/wp-content/plugins/
plugin_activation
wordpress_login_info
fi
# WordPress with WooCommerce
if [ "$create_choice" = 2 ]; then
yellow "Downloading WordPress."
$php $wpcli core download --quiet
green "WordPress has been downloaded."
wordpress_installer
$php $wpcli plugin install woocommerce --activate
green "WooCommerce has been installed."
cp -R $vp_path/plugins/ $sites_folder/$project_name/wp-content/plugins/
plugin_activation
ssl_check
wordpress_login_info
fi

# WordPress install with specific theme
if [ "$create_choice" = 3 ]; then
yellow "Theme Location eg ~/Downloads/theme.zip "
read -r theme_location
yellow "Downloading WordPress."
$php $wpcli core download --skip-content --quiet
green "WordPress has been downloaded."
mkdir $sites_folder/"$project_name"/wp-content/plugins/
wordpress_installer
$php $wpcli theme install $theme_location --activate
cp -R $vp_path/plugins/ $sites_folder/$project_name/wp-content/plugins/
plugin_activation
wordpress_login_info
fi
# WordPress install with specific theme
if [ "$create_choice" = 3 ]; then
yellow "Theme Location eg ~/Downloads/theme.zip "
read -r theme_location
yellow "Downloading WordPress."
$php $wpcli core download --skip-content --quiet
green "WordPress has been downloaded."
mkdir $sites_folder/"$project_name"/wp-content/plugins/
wordpress_installer
$php $wpcli theme install $theme_location --activate
cp -R $vp_path/plugins/ $sites_folder/$project_name/wp-content/plugins/
plugin_activation
ssl_check
wordpress_login_info
fi
fi

# ValetPress delete option
if [ "$1" = "delete" ]; then
if [ "$1" = "delete" ] || [ "$1" = "-d" ]; then
if [ "$(ls -A "$sites_folder")" ]; then
cd "$sites_folder"
red "ValetPress, delete a project "
Expand All @@ -202,6 +248,16 @@ else

if [ "$delete_confirm_converted" = "y" ]; then
cd "$project_name"

# Detect and remove SSL
if $($valet secured | grep -q $project_name)
then
red "SSL detected, removing certificate.";
sudo $valet unsecure --quiet $project_name
else
yellow "SSL not-detected.";
fi

$php $wpcli db drop --yes --quiet
red "Database has been dropped."
cd ..
Expand Down

0 comments on commit a1f73a0

Please sign in to comment.