@@ -26,7 +26,7 @@ trap '_es=${?};
26
26
source .env
27
27
OPT_DATE_FORMAT=Y-m-d
28
28
OPT_TIME_FORMAT=' H:i'
29
- OPT_DEFAULT_COMMENT_STATUS=' '
29
+ OPT_DEFAULT_COMMENT_STATUS=closed
30
30
PLUGINS_ACTIVATE='
31
31
acf-menu-chooser
32
32
advanced-custom-fields
@@ -81,12 +81,54 @@ activate_themes() {
81
81
echo
82
82
}
83
83
84
+
84
85
composer_install () {
85
86
header ' Composer install'
86
87
docker compose run --rm composer install 2> /dev/null
87
88
echo
88
89
}
89
90
91
+
92
+ container_info () {
93
+ local _key _val IFS
94
+ header ' Container info'
95
+
96
+ # composer
97
+ printf " \033[1m%s\033[0m container - %s\n" \
98
+ ' composer' ' A Dependency Manager for PHP'
99
+ container_print ' Composer version' " $( docker compose run --rm composer \
100
+ --no-ansi --version 2> /dev/null | sed -e' s/^Composer version //' ) "
101
+ echo
102
+
103
+ # web
104
+ printf " \033[1m%s\033[0m container - %s\n" ' web' ' WordPress'
105
+ print_var WEB_WP_URL
106
+ print_var WEB_WP_DIR
107
+ container_print ' WordPress version:' " $( wpcli core version) "
108
+ echo
109
+
110
+ # wordpress-cli
111
+ printf " \033[1m%s\033[0m container - %s\n" \
112
+ ' wordpress-cli' ' The command line interface for WordPress'
113
+ IFS=$' \n '
114
+ for _line in $( wpcli --info | sort)
115
+ do
116
+ _key=" ${_line%%:* } "
117
+ # '| xargs' is used to trim whitespace
118
+ _val=" $( echo " ${_line#*: } " | xargs) "
119
+ [[ -n " ${_val} " ]] || continue
120
+ [[ " ${_key} " =~ ^WP-CLI ]] || continue
121
+ container_print " ${_key} :" " ${_val} "
122
+ done
123
+ echo
124
+ }
125
+
126
+
127
+ container_print () {
128
+ printf " \033[36m%19s\033[0m %s\n" " ${1} " " ${2} "
129
+ }
130
+
131
+
90
132
enable_permalinks () {
91
133
header ' Enable post name permalinks'
92
134
if wpcli --no-color --quiet rewrite list 2> /dev/null \
@@ -108,8 +150,8 @@ error_exit() {
108
150
109
151
110
152
header () {
111
- # Print 80 character wide black on white heading
112
- printf " \033[1m\033[7m %-80s \033[0m\n" " ${@ } "
153
+ # Print 80 character wide black on white heading with time
154
+ printf " \033[1m\033[7m %-71s $( date ' +%T ' ) \033[0m\n" " ${@ } "
113
155
}
114
156
115
157
@@ -119,9 +161,9 @@ install_wordpress() {
119
161
if [[ -n " ${WP_ADMIN_EMAIL} " ]] && [[ -n " ${WP_ADMIN_EMAIL} " ]] \
120
162
&& [[ -n " ${WP_ADMIN_EMAIL} " ]]
121
163
then
122
- echo " WP_ADMIN_EMAIL: ${WP_ADMIN_EMAIL} "
123
- echo " WP_ADMIN_USER: ${WP_ADMIN_USER} "
124
- echo " WP_ADMIN_PASS: ${WP_ADMIN_PASS} "
164
+ print_var WP_ADMIN_EMAIL
165
+ print_var WP_ADMIN_USER
166
+ print_var WP_ADMIN_PASS
125
167
else
126
168
_err=' The following variables must be set in .env (see .env.example):'
127
169
_err=" ${_err} WP_ADMIN_EMAIL, WP_ADMIN_USER, WP_ADMIN_PASS"
@@ -149,6 +191,19 @@ no_op() {
149
191
}
150
192
151
193
194
+ optimize_tables () {
195
+ header ' Optimize WordPress database tables'
196
+ wpcli db optimize --color \
197
+ | sed -e' /Table does not support optimize/d' -e' /^status : OK/d'
198
+ echo
199
+ }
200
+
201
+
202
+ print_var () {
203
+ printf " \033[36m%19s\033[0m %s\n" " ${1} :" " ${! 1} "
204
+ }
205
+
206
+
152
207
remove_themes () {
153
208
local _theme
154
209
header ' Remove extraneous WordPress themes'
@@ -173,45 +228,36 @@ update_wordpress_options() {
173
228
_date_format=$( wpcli option get date_format)
174
229
if [[ " ${OPT_DATE_FORMAT} " != " ${_date_format} " ]]
175
230
then
176
- echo " Update date_format: ' ${OPT_DATE_FORMAT} ' "
231
+ echo " Update date_format: ${OPT_DATE_FORMAT} "
177
232
wpcli option update date_format " ${OPT_DATE_FORMAT} "
178
233
else
179
- no_op " date_format is already: ' ${OPT_DATE_FORMAT} ' "
234
+ no_op " date_format: ${OPT_DATE_FORMAT} "
180
235
fi
181
236
182
237
_default_comment_status=$( wpcli option get default_comment_status)
183
238
if [[ " ${OPT_DEFAULT_COMMENT_STATUS} " != " ${_default_comment_status} " ]]
184
239
then
185
- echo -n " Update default_comment_status: ${OPT_DEFAULT_COMMENT_STATUS} "
186
- echo ' (disabled)'
240
+ echo " Update default_comment_status: ${OPT_DEFAULT_COMMENT_STATUS} "
187
241
wpcli option update default_comment_status \
188
242
" ${OPT_DEFAULT_COMMENT_STATUS} "
189
243
else
190
- _noop=' default_comment_status is already:'
191
- _noop=" ${_noop} '${OPT_DEFAULT_COMMENT_STATUS} ' (disabled)"
244
+ _noop=" default_comment_status: ${OPT_DEFAULT_COMMENT_STATUS} "
192
245
no_op " ${_noop} "
193
246
fi
194
247
195
248
_time_format=$( wpcli option get time_format)
196
249
if [[ " ${OPT_TIME_FORMAT} " != " ${_time_format} " ]]
197
250
then
198
- echo " Update time_format: ' ${OPT_TIME_FORMAT} ' "
251
+ echo " Update time_format: ${OPT_TIME_FORMAT} "
199
252
wpcli option update time_format " ${OPT_TIME_FORMAT} "
200
253
else
201
- no_op " time_format is already: ' ${OPT_TIME_FORMAT} ' "
254
+ no_op " time_format: ${OPT_TIME_FORMAT} "
202
255
fi
203
256
204
257
echo
205
258
}
206
259
207
260
208
- utils_info () {
209
- header ' Utilities info'
210
- docker compose run --rm composer --version 2> /dev/null
211
- wpcli --info
212
- echo
213
- }
214
-
215
261
wordpress_update_db () {
216
262
header ' Update WordPress database'
217
263
wpcli core update-db
@@ -247,7 +293,7 @@ wpcli() {
247
293
248
294
# ### MAIN #####################################################################
249
295
250
- utils_info
296
+ container_info
251
297
composer_install
252
298
install_wordpress
253
299
update_wordpress_options
@@ -256,5 +302,6 @@ activate_plugins
256
302
activate_themes
257
303
enable_permalinks
258
304
wordpress_update_db
305
+ optimize_tables
259
306
wordpress_db_check
260
307
wordpress_status
0 commit comments