Skip to content

Commit e4761da

Browse files
committed
add setup script
1 parent 697e254 commit e4761da

File tree

2 files changed

+158
-13
lines changed

2 files changed

+158
-13
lines changed

README.md

+3-13
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,11 @@ containers:
4141
docker compose up
4242
```
4343
5. Wait for build and initialization to complete
44-
6. Install WordPress initially through the GUI.
45-
- **TODO:** Script help here
46-
7. Install WordPress plugins/themes managed through Composer:
47-
```shell
48-
composer install
49-
```
50-
8. Activate all installed plugins, excluding `wordfence`
51-
```shell
52-
wp plugin activate --all --exclude=wordfence
53-
```
54-
9. Activate `vocabulary-theme`
44+
6. Setup WordPress:
5545
```shell
56-
wp theme activate vocabulary-theme
46+
./setup-wordpress.sh
5747
```
58-
10. Optionally: manually activate/configure `wordfence` in the GUI for now.
48+
7. Optionally: manually activate/configure `wordfence` in the GUI for now.
5949
- **TODO:** Script help here
6050
6151
[gh-cc-legal-tools-data]: https://github.com/creativecommons/cc-legal-tools-data

setup-wordpress.sh

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/bin/bash
2+
set -o errexit
3+
set -o errtrace
4+
set -o nounset
5+
6+
trap '_es=${?};
7+
printf "${0}: line ${LINENO}: \"${BASH_COMMAND}\"";
8+
printf " exited with a status of ${_es}\n";
9+
exit ${_es}' ERR
10+
11+
source .env
12+
ACTIVATE_PLUGINS='
13+
acf-menu-chooser
14+
advanced-custom-fields
15+
akismet
16+
classic-editor
17+
redirection
18+
tablepress
19+
'
20+
ACTIVATE_THEMES='
21+
vocabulary-theme
22+
'
23+
WEB_WP_DIR=/var/www/html
24+
WEB_WP_URL=http://127.0.0.1:8000
25+
26+
27+
#### FUNCTIONS ################################################################
28+
29+
30+
activate_plugins() {
31+
local _plugin
32+
header 'Activate WordPress plugins'
33+
for _plugin in ${ACTIVATE_PLUGINS}
34+
do
35+
if wpcli --no-color --quiet plugin is-active "${_plugin}" &> /dev/null
36+
then
37+
echo "no-op: ${_plugin} is already active"
38+
else
39+
wpcli plugin activate "${_plugin}"
40+
fi
41+
done
42+
echo
43+
}
44+
45+
46+
activate_themes() {
47+
local _theme
48+
header 'Activate WordPress themes'
49+
for _theme in ${ACTIVATE_THEMES}
50+
do
51+
if wpcli --no-color --quiet theme is-active "${_theme}" &> /dev/null
52+
then
53+
echo "no-op: ${_theme} is already active"
54+
else
55+
wpcli theme activate "${_theme}"
56+
fi
57+
done
58+
echo
59+
}
60+
61+
composer_install() {
62+
header 'Composer install'
63+
docker compose run --rm composer install
64+
echo
65+
}
66+
67+
enable_permalinks() {
68+
header 'Enable post name permalinks'
69+
if wpcli --no-color --quiet rewrite list 2> /dev/null \
70+
| grep -qF 'page/?([0-9]{1,})/?$'
71+
then
72+
echo 'no-op: rewrite rules exist'
73+
else
74+
wpcli rewrite structure --hard '/%postname%'
75+
fi
76+
echo
77+
}
78+
79+
80+
error_exit() {
81+
# Echo error message and exit with error
82+
echo -e "\033[31mERROR:\033[0m ${@}" 1>&2
83+
exit 1
84+
}
85+
86+
87+
header() {
88+
# Print 80 character wide black on white heading
89+
printf "\033[1m\033[7m %-80s\033[0m\n" "${@}"
90+
}
91+
92+
93+
install_wordpress() {
94+
local _err
95+
header 'Install WordPress'
96+
if [[ -n "${WP_ADMIN_EMAIL}" ]] && [[ -n "${WP_ADMIN_EMAIL}" ]] \
97+
&& [[ -n "${WP_ADMIN_EMAIL}" ]]
98+
then
99+
echo "WP_ADMIN_EMAIL: ${WP_ADMIN_EMAIL}"
100+
echo "WP_ADMIN_USER: ${WP_ADMIN_USER}"
101+
echo "WP_ADMIN_PASS: ${WP_ADMIN_PASS}"
102+
else
103+
_err='The following variables must be set in .env (see .env.example):'
104+
_err="${_err} WP_ADMIN_EMAIL, WP_ADMIN_USER, WP_ADMIN_PASS"
105+
error_exit "${_err}"
106+
fi
107+
echo
108+
if wpcli --no-color --quiet core is-installed &> /dev/null
109+
then
110+
echo 'no-op: already installed'
111+
else
112+
wpcli core install \
113+
--title='CreativeCommons.org Local Dev' \
114+
--admin_email="${WP_ADMIN_EMAIL}" \
115+
--admin_user="${WP_ADMIN_USER}" \
116+
--admin_password="${WP_ADMIN_PASS}" \
117+
--skip-email
118+
fi
119+
echo
120+
}
121+
122+
123+
utils_info() {
124+
header 'Utilities info'
125+
docker compose run --rm composer --version
126+
wpcli --info
127+
echo
128+
}
129+
130+
131+
wordpress_status() {
132+
header 'Show maintenance mode status to expose any PHP Warnings'
133+
wpcli maintenance-mode status
134+
}
135+
136+
137+
wpcli() {
138+
docker compose run --rm \
139+
--env WP_ADMIN_USER=${WP_ADMIN_USER} \
140+
--env WP_ADMIN_PASS=${WP_ADMIN_PASS} \
141+
--env WP_ADMIN_EMAIL=${WP_ADMIN_EMAIL} \
142+
wordpress-cli \
143+
/usr/local/bin/wp --path=${WEB_WP_DIR} --url=${WEB_WP_URL} "${@}"
144+
}
145+
146+
147+
#### MAIN #####################################################################
148+
149+
utils_info
150+
composer_install
151+
install_wordpress
152+
activate_plugins
153+
activate_themes
154+
enable_permalinks
155+
wordpress_status

0 commit comments

Comments
 (0)