This repository has been archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomain-install.sh
executable file
·263 lines (209 loc) · 8.59 KB
/
domain-install.sh
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
#! /bin/bash
#
# Automatic Localhost Domain & WordPress Setup
#
# @cmd domain install domainname.extension
#
# @version 1.0.0
#
# @author Chris Winters https://github.com/ChrisWinters
#
# MIT License
# https://raw.githubusercontent.com/ChrisWinters/wp-cli-localhost/master/LICENSE
# Source Config File
source domain-config.sh
# Check If User Config Is Configured
function config_check() {
if [[ $DB_PASS == "PASSWORD" || $DB_PASS == "" ]]; then
echo "Error: MySQL and WordPress login details need to be set in the config.sh first."
return 1
exit 1
fi
}
# Download & unploack WordPress
function wp_core_download() {
printf "===> Downloading And Unpacking WordPress\n"
wp core download --path=${LOCAL_DOMAIN_PATH} --quiet
}
# Create Local Database
function mysql_create_database() {
printf "===> Creating Database: ${DB_NAME}\n"
mysql --login-path=local -e "CREATE DATABASE ${DB_NAME}"
}
# Setup wp-config.php file
function wp_core_config() {
printf "===> Creating Configuration File\n"
wp core config --path=${LOCAL_DOMAIN_PATH} --dbname=${DB_NAME} --dbuser=${DB_USER} --dbpass=${DB_PASS} --quiet --extra-php <<PHP
define('WP_MEMORY_LIMIT', '256M');
define('WP_HTTP_BLOCK_EXTERNAL', false);
define('WP_ACCESSIBLE_HOSTS', 'api.wordpress.org');
define('FS_METHOD', 'direct');
define('ALLOW_UNFILTERED_UPLOADS', true);
@ini_set( 'error_log', '${SITE_PATH}/error.log' );
require_once '${WP_CLI_LOCALHOST_PATH}/backtrace.php';
PHP
}
# Install WordPress & Setup Admin
function wp_core_install() {
printf "===> Installing WordPress; Please Wait...\n"
wp core install --path=${LOCAL_DOMAIN_PATH} --url=${LOCAL_DOMAIN_URL} --title=${DOMAIN} --admin_user=${ADMIN_USER} --admin_password=${ADMIN_PASS} --admin_email=${ADMIN_EMAIL} --skip-email --quiet
}
# Create .htacccess & php.ini file
function create_htaccess_php_ini() {
printf "===> Creating .htaccess And php.ini Files\n"
echo "# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress" >> ${LOCAL_DOMAIN_PATH}/.htaccess
# Limited For Dev
echo "upload_max_filesize = 12M
post_max_size = 13M
memory_limit = 15M" >> ${LOCAL_DOMAIN_PATH}/php.ini
}
# Install Helper Plugins
function wp_plugin_install() {
printf "===> Downloading And Unpacking Plugins; Please Wait...\n"
wp plugin install advanced-database-cleaner --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin install log-deprecated-notices --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin install wordpress-importer --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin install advanced-wp-reset --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin install debug-bar-cron --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin install query-monitor --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin install theme-check --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin install wp-crontrol --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin install rtl-tester --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin install debug-bar --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin install debug-bar-console --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin install debug-bar-extender --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin install classic-editor --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin install classic-editor-addon --path=${LOCAL_DOMAIN_PATH} --quiet
}
# Cleanup WordPress Install
function cleanup_wordpress() {
printf "===> Cleaning Up WordPress\n"
wp theme delete twentyseventeen --path=${LOCAL_DOMAIN_PATH} --quiet
wp theme delete twentyfifteen --path=${LOCAL_DOMAIN_PATH} --quiet
wp theme delete twentysixteen --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin delete akismet --path=${LOCAL_DOMAIN_PATH} --quiet
wp plugin delete hello --path=${LOCAL_DOMAIN_PATH} --quiet
rm ${LOCAL_DOMAIN_PATH}/wp-config-sample.php
rm ${LOCAL_DOMAIN_PATH}/readme.html
rm ${LOCAL_DOMAIN_PATH}/license.txt
}
# Setup WordPress
function setup_wordpress() {
printf "===> Setting Up WordPress; Please Wait...\n"
wp comment delete 1 --path=${LOCAL_DOMAIN_PATH} --force --quiet
wp post delete 1 --path=${LOCAL_DOMAIN_PATH} --force --quiet
wp post delete 2 --path=${LOCAL_DOMAIN_PATH} --force --quiet
wp post delete 3 --path=${LOCAL_DOMAIN_PATH} --force --quiet
wp option delete mailserver_login --path=${LOCAL_DOMAIN_PATH} --quiet
wp option delete mailserver_pass --path=${LOCAL_DOMAIN_PATH} --quiet
wp option delete mailserver_port --path=${LOCAL_DOMAIN_PATH} --quiet
wp option delete mailserver_url --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update gmt_offset $GMT_OFFSET --path=${LOCAL_DOMAIN_PATH} --quiet
wp term update category 1 --name=$CATEGORY_NAME --slug=$CATEGORY_SLUG --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update permalink_structure $PERMALINK --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update category_base $CATEGORY_BASE --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update tag_base $TAG_BASE --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update ping_sites "" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update avatar_default "blank" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update close_comments_days_old "365" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update close_comments_for_old_posts "1" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update comment_moderation "1" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update comment_registration "1" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update thread_comments "1" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update show_avatars "0" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update use_smilies "0" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update uploads_use_yearmonth_folders "0" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update thumbnail_crop "" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update thumbnail_size_h "0" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update thumbnail_size_w "0" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update large_size_h "0" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update large_size_w "0" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update medium_large_size_h "0" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update medium_large_size_w "0" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update medium_size_h "0" --path=${LOCAL_DOMAIN_PATH} --quiet
wp option update medium_size_w "0" --path=${LOCAL_DOMAIN_PATH} --quiet
wp transient delete --all --path=${LOCAL_DOMAIN_PATH} --quiet
}
# Update Local Hosts File
function update_hosts_file() {
if grep -q "${DOMAIN}" /etc/hosts; then
printf "===> Domain Found Within Hosts Entry\n"
else
printf "===> Adding Hosts Entry; You May Need To Enter Your Password\n"
sudo sh -c "echo ${HOSTS_ENTRY} >> /etc/hosts"
if grep -q "${DOMAIN}" /etc/hosts; then
printf "===> Domain Added To /etc/hosts\n"
else
printf "===> Manual Action Required: echo \"${HOSTS_ENTRY}\" | sudo sh -c tee -a /etc/hosts > /dev/null\n"
fi
fi
}
# Update Apache
function update_apache() {
printf "===> Adding Domain To Apache; You May Need To Enter Your Password\n"
sudo sh -c "echo '<VirtualHost *:80>
ServerName ${DOMAIN}
ServerAlias www.${DOMAIN}
DocumentRoot /var/www/html/${DOMAIN}
<Directory /var/www/html/${DOMAIN}/>
Options -Indexes +FollowSymLinks
AllowOverride All AuthConfig
Order allow,deny
allow from all
</Directory>
</VirtualHost>' >> /etc/apache2/sites-available/${DOMAIN}.conf"
sudo sh -c "ln -sfn ../sites-available/${DOMAIN}.conf /etc/apache2/sites-enabled/${DOMAIN}.conf"
printf "===> Restarting Apache\n"
sudo sh -c "apache2ctl -k graceful"
}
# Log Domain
function log_domain() {
echo ${DOMAIN} >> ${DOMAINS_LIST}
printf "===> Logged ${DOMAIN}\n"
}
# Run Install Domain
function install_domain() {
# Required
if [[ $1 == "" ]]; then
echo $0: "=domain=> usage example: domain install domainname.extension"
return 1
fi
# Check User Config Is Setup
if [[ $DB_PASS == "PASSWORD" || $DB_PASS == "" ]]; then
echo "=domain=> Add MySQL and WordPress login details to:"
echo " ${SITE_PATH}/config.sh"
return 1
fi
# Start Display
clear
printf "\n\n"
read -p "== Press [y] to setup ${LOCAL_DOMAIN_URL} " -n 1 -r
printf "\n\n"
if [[ $REPLY =~ ^[Yy]$ ]]; then
printf "=domain=> Working on ${DOMAIN}\n"
sleep 1
wp_core_download
mysql_create_database
wp_core_config
wp_core_install
create_htaccess_php_ini
wp_plugin_install
cleanup_wordpress
setup_wordpress
update_hosts_file
update_apache
log_domain
printf "=domain=> Ctrl+Click To Open: ${LOCAL_DOMAIN_URL}/wp-admin/\n"
printf " To Import Unit Data: domain import ${DOMAIN}\n\n"
fi
}
install_domain $@