Skip to content

Commit fce3f88

Browse files
committed
add plugin and theme lists. improve color. remove funding messages
1 parent 4e2919d commit fce3f88

File tree

1 file changed

+81
-41
lines changed

1 file changed

+81
-41
lines changed

setup-wordpress.sh

+81-41
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ trap '_es=${?};
2424

2525
# shellcheck disable=SC1091
2626
source .env
27+
28+
# https://en.wikipedia.org/wiki/ANSI_escape_code
29+
E0="$(printf "\033[0m")" # reset
30+
E1="$(printf "\033[1m")" # bold
31+
E7="$(printf "\033[7m")" # invert
32+
E30="$(printf "\033[30m")" # black foreground
33+
E31="$(printf "\033[31m")" # red foreground
34+
E33="$(printf "\033[33m")" # yellow foreground
35+
E36="$(printf "\033[36m")" # cyan foreground
36+
E90="$(printf "\033[90m")" # bright black (gray) foreground
37+
E97="$(printf "\033[97m")" # bright white foreground
38+
E100="$(printf "\033[100m")" # bright black (gray) background
39+
E107="$(printf "\033[107m")" # bright white background
2740
OPT_DATE_FORMAT=Y-m-d
2841
OPT_TIME_FORMAT='H:i'
2942
OPT_DEFAULT_COMMENT_STATUS=closed
@@ -49,10 +62,22 @@ WEB_WP_URL=http://localhost:8080
4962

5063
#### FUNCTIONS ################################################################
5164

65+
format_list() {
66+
local _header_match _header_replace
67+
_h="${E97}${E100}"
68+
_header_match='(^name *) (status *) (update *) (version)'
69+
_header_replace="${_h}\1${E0} ${_h}\2${E0} ${_h}\3${E0} ${_h}\4${E0}"
70+
sed -u -E \
71+
-e"s/${_header_match}/${_header_replace}/" \
72+
-e"s/(^.* inactive .*$)/${E90}\1${E0}/" \
73+
-e"s/( active .*)( available )/\1${E33}\2${E0}/" \
74+
-e"s/( active .*)( none )/\1${E90}\2${E0}/"
75+
}
76+
5277

5378
activate_plugins() {
54-
local _plugin
55-
header 'Activate WordPress plugins'
79+
local _bold _plugin _reset
80+
header 'Activate plugins'
5681
for _plugin in ${PLUGINS_ACTIVATE}
5782
do
5883
if wpcli --no-color --quiet plugin is-active "${_plugin}" &> /dev/null
@@ -62,13 +87,16 @@ activate_plugins() {
6287
wpcli plugin activate "${_plugin}"
6388
fi
6489
done
90+
wpcli plugin list --format=csv \
91+
| column -s',' -t \
92+
| format_list
6593
echo
6694
}
6795

6896

6997
activate_themes() {
7098
local _theme
71-
header 'Activate WordPress themes'
99+
header 'Activate themes'
72100
for _theme in ${THEMES_ACTIVATE}
73101
do
74102
if wpcli --no-color --quiet theme is-active "${_theme}" &> /dev/null
@@ -78,13 +106,20 @@ activate_themes() {
78106
wpcli theme activate "${_theme}"
79107
fi
80108
done
109+
wpcli theme list --format=csv \
110+
| column -s',' -t \
111+
| format_list
81112
echo
82113
}
83114

84115

85116
composer_install() {
86117
header 'Composer install'
87-
docker compose run --rm composer install 2>/dev/null
118+
docker compose run --rm composer install --ansi 2>&1 \
119+
| sed \
120+
-e'/Container.*Running$/d' \
121+
-e'/is looking for funding./d' \
122+
-e'/Use the `composer fund` command/d'
88123
echo
89124
}
90125

@@ -94,21 +129,21 @@ container_info() {
94129
header 'Container info'
95130

96131
# composer
97-
printf "\033[1m%s\033[0m container - %s\n" \
132+
printf "${E1}%s${E0} container - %s\n" \
98133
'composer' 'A Dependency Manager for PHP'
99134
container_print 'Composer version' "$(docker compose run --rm composer \
100135
--no-ansi --version 2>/dev/null | sed -e's/^Composer version //')"
101136
echo
102137

103138
# web
104-
printf "\033[1m%s\033[0m container - %s\n" 'web' 'WordPress'
139+
printf "${E1}%s${E0} container - %s\n" 'web' 'WordPress'
105140
print_var WEB_WP_URL
106141
print_var WEB_WP_DIR
107142
container_print 'WordPress version:' "$(wpcli core version)"
108143
echo
109144

110145
# wordpress-cli
111-
printf "\033[1m%s\033[0m container - %s\n" \
146+
printf "${E1}%s${E0} container - %s\n" \
112147
'wordpress-cli' 'The command line interface for WordPress'
113148
IFS=$'\n'
114149
for _line in $(wpcli --info | sort)
@@ -125,7 +160,34 @@ container_info() {
125160

126161

127162
container_print() {
128-
printf "\033[36m%19s\033[0m %s\n" "${1}" "${2}"
163+
printf "${E36}%19s${E0} %s\n" "${1}" "${2}"
164+
}
165+
166+
167+
database_check() {
168+
header 'Check database'
169+
wpcli db check --color \
170+
| sed -e'/^wordpress[.]wp_.*OK$/d'
171+
echo
172+
}
173+
174+
175+
database_optimize() {
176+
header 'Optimize database'
177+
# Only show errors and summary
178+
wpcli db optimize --color \
179+
| sed \
180+
-e'/^wordpress[.]wp_/d' \
181+
-e'/Table does not support optimize/d' \
182+
-e'/^status : OK/d'
183+
echo
184+
}
185+
186+
187+
database_update() {
188+
header 'Update database'
189+
wpcli core update-db
190+
echo
129191
}
130192

131193

@@ -144,14 +206,14 @@ enable_permalinks() {
144206

145207
error_exit() {
146208
# Echo error message and exit with error
147-
echo -e "\033[31mERROR:\033[0m ${*}" 1>&2
209+
echo -e "${E31}ERROR:${E0} ${*}" 1>&2
148210
exit 1
149211
}
150212

151213

152214
header() {
153215
# Print 80 character wide black on white heading with time
154-
printf "\033[1m\033[7m %-71s$(date '+%T') \033[0m\n" "${@}"
216+
printf "${E30}${E107} %-71s$(date '+%T') ${E0}\n" "${@}"
155217
}
156218

157219

@@ -187,26 +249,18 @@ install_wordpress() {
187249

188250
no_op() {
189251
# Print no-op message"
190-
printf "\033[1m\033[30mno-op: %s\033[0m\n" "${@}"
191-
}
192-
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
252+
printf "${E90}no-op: %s${E0}\n" "${@}"
199253
}
200254

201255

202256
print_var() {
203-
printf "\033[36m%19s\033[0m %s\n" "${1}:" "${!1}"
257+
printf "${E36}%19s${E0} %s\n" "${1}:" "${!1}"
204258
}
205259

206260

207261
remove_themes() {
208262
local _theme
209-
header 'Remove extraneous WordPress themes'
263+
header 'Remove extraneous themes'
210264
for _theme in ${THEMES_REMOVE}
211265
do
212266
if ! wpcli --no-color --quiet theme is-installed "${_theme}" \
@@ -221,9 +275,9 @@ remove_themes() {
221275
}
222276

223277

224-
update_wordpress_options() {
278+
update_options() {
225279
local _date_format _default_comment_status _noop _time_format
226-
header 'Update WordPress options'
280+
header 'Update options'
227281

228282
_date_format=$(wpcli option get date_format)
229283
if [[ "${OPT_DATE_FORMAT}" != "${_date_format}" ]]
@@ -258,20 +312,6 @@ update_wordpress_options() {
258312
}
259313

260314

261-
wordpress_update_db() {
262-
header 'Update WordPress database'
263-
wpcli core update-db
264-
echo
265-
}
266-
267-
268-
wordpress_db_check() {
269-
header 'Check WordPress database'
270-
wpcli db check
271-
echo
272-
}
273-
274-
275315
wordpress_status() {
276316
header 'Show maintenance mode status to expose any PHP Warnings'
277317
wpcli maintenance-mode status
@@ -296,12 +336,12 @@ wpcli() {
296336
container_info
297337
composer_install
298338
install_wordpress
299-
update_wordpress_options
339+
update_options
300340
remove_themes
301341
activate_plugins
302342
activate_themes
303343
enable_permalinks
304-
wordpress_update_db
305-
optimize_tables
306-
wordpress_db_check
344+
database_update
345+
database_optimize
346+
database_check
307347
wordpress_status

0 commit comments

Comments
 (0)