-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vp
executable file
·272 lines (249 loc) · 8.19 KB
/
vp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/bin/bash
# Debug - usage > DEBUG=1 vp <command>
if [[ "${DEBUG}" ]]; then
export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] '
set -x
fi
version="2022.4.27.6"
# Added for debugging
set -euo pipefail
IFS=$'\n\t'
# Colors
NORMAL=$(tput sgr0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2; tput bold)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
function red() {
echo -e "$RED$*$NORMAL"
}
function green() {
echo -e "$GREEN$*$NORMAL"
}
function yellow() {
echo -e "$YELLOW$*$NORMAL"
}
function blue() {
echo -e "$BLUE$*$NORMAL"
}
function magenta() {
echo -e "$MAGENTA$*$NORMAL"
}
function cyan() {
echo -e "$CYAN$*$NORMAL"
}
function white() {
echo -e "$WHITE$*$NORMAL"
}
# 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."
$php $wpcli core install --url="$project_name"."$valet_domain" --title="$project_name"."$valet_domain" --admin_user="$wp_admin_user" --admin_password="$wp_admin_password" --admin_email="$wp_admin_email" --quiet
green "WordPress has been installed."
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
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 " "
}
# Plugin add/remove function
plugin_activation () {
# Detect if plugins should be added
if [ ! -z "$plugins_add" -a "$plugins_add" != " " ]; then
green "Installing plugins."
echo $plugins_add | xargs $php $wpcli plugin install --quiet
yellow "$plugins_add added to install."
fi
# Detect if plugins should be removed
if [ ! -z "$plugins_remove" -a "$plugins_remove" != " " ]; then
red "Removing plugins."
echo $plugins_remove | xargs $php $wpcli plugin delete --quiet
red "$plugins_remove removed from install"
fi
# Activate all installed plugins
$php $wpcli plugin activate --all --quiet
green "Plugins have been activated."
}
# Get ValetPress install directory
vp_path="$(cd "$(dirname "$0")" && pwd)"
# Get config variables
wp_admin_user=$(cat $vp_path/config.json|jq -r .wp_admin_user)
wp_admin_email=$(cat $vp_path/config.json|jq -r .wp_admin_email)
wp_admin_password=$(cat $vp_path/config.json|jq -r .wp_admin_password)
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
if [ $# -lt 1 ] || [ "$1" = "help" ] || [ "$1" = "-h" ] || [ -z "$1" ];then
clear
white "ValetPress $version - Created by Shelby DeNike"
cyan " vp create - Create fresh WordPress install. "
cyan " vp delete - Delete an existing WordPress project. "
cyan " vp help - Display ValetPress help screen. "
echo " "
exit 1;
else
# ValetPress create option
if [ "$1" = "create" ] || [ "$1" = "-c" ]; then
white "Please enter the name of your project."
read -p ": " -r project_name
while [[ -z "$project_name" ]]; do
white "You must specify a name for the project."
read -p ": " -r project_name
done
cd "$sites_folder"
# Delete existing project if detected
if [ -d "$project_name" ]; then
cd "$project_name"
$php $wpcli db drop --yes
cd ..
rm -rf "$project_name"
red "Previous Project Deleted: $project_name"
fi
# Create new project folder
mkdir "$project_name"
cd "$project_name"
# Select install method
white "How do you wish to install WordPress? "
cyan " 1.) Default WordPress Install "
cyan " 2.) WordPress with WooCommerce "
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
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
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
ssl_check
wordpress_login_info
fi
fi
# ValetPress delete option
if [ "$1" = "delete" ] || [ "$1" = "-d" ]; then
if [ "$(ls -A "$sites_folder")" ]; then
cd "$sites_folder"
red "ValetPress, delete a project "
ls -d */ | cut -f1 -d'/'
cyan "Project that you wish to delete"
read -r project_name
red "Are you sure you want to delete $project_name ? (y/N)"
read -r delete_confirm
delete_confirm_converted=$( echo "$delete_confirm" | tr "[:upper:]" "[:lower:]" )
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 ..
rm -rf "$project_name"
red "Project files deleted."
green "Success: $project_name deleted"
fi
else
magenta "No WordPress installs detected. "
fi
fi
fi