-
Notifications
You must be signed in to change notification settings - Fork 179
/
install-wordpress.sh
executable file
·246 lines (195 loc) · 9.95 KB
/
install-wordpress.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
#!/usr/bin/env bash
# Exit if any command fails.
set -e
# Common variables.
WP_DEBUG=${WP_DEBUG-true}
SCRIPT_DEBUG=${SCRIPT_DEBUG-true}
WEBSTORIES_DEV_MODE=${WEBSTORIES_DEV_MODE-true}
MEDIA_TRASH=${MEDIA_TRASH-false}
WP_VERSION=${WP_VERSION-"latest"}
# Include useful functions
. "$(dirname "$0")/includes.sh"
# Make sure Docker containers are running
dc up -d >/dev/null 2>&1
# Get the host port for the WordPress container.
HOST_PORT=$(dc port $CONTAINER 80 | awk -F : '{printf $2}')
# Wait until the WordPress site is responding to requests.
echo -en $(status_message "Attempting to connect to WordPress...")
until $(curl -L http://localhost:$HOST_PORT -so - 2>&1 | grep -q "WordPress"); do
echo -n '.'
sleep 5
done
echo ''
# Wait until the database container is ready.
echo -en $(status_message "Waiting for database connection...")
until $(container bash -c "echo -n > /dev/tcp/mysql/3306" >/dev/null 2>&1); do
echo -n '.'
sleep 5
done
echo ''
# Create the database if it doesn't exist.
echo -e $(status_message "Creating the database (if it does not exist)...")
mysql -e 'CREATE DATABASE IF NOT EXISTS wordpress;'
# If this is the test site, we reset the database so no posts/comments/etc.
# dirty up the tests.
if [ "$1" == '--reset-site' ]; then
echo -e $(status_message "Resetting test database...")
wp db reset --yes --quiet
fi
if [ ! -z "$WP_VERSION" ] && [ "$WP_VERSION" != "latest" ]; then
# Potentially downgrade WordPress
echo -e $(status_message "Downloading WordPress version $WP_VERSION...")
wp core download --version=${WP_VERSION} --force --quiet
fi
# Install WordPress.
echo -e $(status_message "Installing WordPress...")
wp core install --title="$SITE_TITLE" --admin_user=admin --admin_password=password --admin_email=test@test.com --skip-email --url=http://localhost:$HOST_PORT --quiet
# Potentially update WordPress
if [ "$WP_VERSION" == "latest" ]; then
echo -e $(status_message "Updating WordPress to the latest major")
wp core update --force --quiet
else
echo -e $(status_message "Updating WordPress to the latest minor")
wp core update --minor --force --quiet
fi
# Create additional users.
echo -e $(status_message "Creating additional users...")
if [[ $(wp user get editor --field=login 2>&1) != "editor" ]]; then
wp user create editor editor@example.com --role=editor --user_pass=password
echo -e $(status_message "Editor created! Username: editor Password: password")
else
echo -e $(status_message "Editor already exists, skipping...")
fi
if [[ $(wp user get author --field=login 2>&1) != "author" ]]; then
wp user create author author@example.com --role=author --user_pass=password --quiet
echo -e $(status_message "Author created! Username: author Password: password")
else
echo -e $(status_message "Author already exists, skipping...")
fi
if [[ $(wp user get contributor --field=login 2>&1) != "contributor" ]]; then
wp user create contributor contributor@example.com --role=contributor --user_pass=password --quiet
echo -e $(status_message "Contributor created! Username: contributor Password: password")
else
echo -e $(status_message "Contributor already exists, skipping...")
fi
if [[ $(wp user get subscriber --field=login 2>&1) != "subscriber" ]]; then
wp user create subscriber subscriber@example.com --role=subscriber --user_pass=password --quiet
echo -e $(status_message "Subscriber created! Username: subscriber Password: password")
else
echo -e $(status_message "Subscriber already exists, skipping...")
fi
# Make sure the uploads and upgrade folders exist and we have permissions to add files.
echo -e $(status_message "Ensuring that files can be uploaded...")
container mkdir -p \
/var/www/html/wp-content/uploads \
/var/www/html/wp-content/upgrade
container chmod 767 \
/var/www/html/wp-content \
/var/www/html/wp-content/plugins \
/var/www/html/wp-config.php \
/var/www/html/wp-settings.php \
/var/www/html/wp-content/uploads \
/var/www/html/wp-content/upgrade
CURRENT_WP_VERSION=$(wp core version | tr -d '\r')
echo -e $(status_message "Current WordPress version: $CURRENT_WP_VERSION...")
if [ "$WP_VERSION" == "latest" ]; then
# Check for WordPress updates, to make sure we're running the very latest version.
echo -e $(status_message "Updating WordPress to the latest version...")
wp core update --quiet
echo -e $(status_message "Updating The WordPress Database...")
wp core update-db --quiet
fi
# If the 'wordpress' volume wasn't during the down/up earlier, but the post port has changed, we need to update it.
echo -e $(status_message "Checking the site's url...")
CURRENT_URL=$(wp option get siteurl)
if [ "$CURRENT_URL" != "http://localhost:$HOST_PORT" ]; then
wp option update home "http://localhost:$HOST_PORT" --quiet
wp option update siteurl "http://localhost:$HOST_PORT" --quiet
fi
# Activate Web Stories plugin.
echo -e $(status_message "Activating Web Stories plugin...")
wp plugin activate web-stories --quiet
# Install & activate testing plugins.
# Only install Gutenberg on latest version of WordPress.
if [ "$WP_VERSION" == "latest" ]; then
echo -e $(status_message "Installing Gutenberg plugin...")
wp plugin install gutenberg --force --quiet
fi
echo -e $(status_message "Installing and activating RTL Tester plugin...")
wp plugin install rtl-tester --activate --force --quiet
echo -e $(status_message "Installing WordPress importer...")
wp plugin install wordpress-importer --activate --force --quiet
echo -e $(status_message "Installing WooCommerce plugin...")
wp plugin install woocommerce --activate --force --quiet
echo -e $(status_message "Installing AMP plugin...")
wp plugin install amp --force --quiet
echo -e $(status_message "Installing Classic editor plugin...")
wp plugin install classic-editor --force --quiet
echo -e $(status_message "Installing Classic Widgets plugin...")
wp plugin install classic-widgets --force --quiet
echo -e $(status_message "Activating Twenty Twenty theme...")
wp theme install twentytwenty --activate --force --quiet
echo -e $(status_message "Disable block directory and remote patterns...")
wp plugin activate web-stories-test-plugins/disable-block-directory --quiet
echo -e $(status_message "Disable Gravatar...")
wp plugin activate web-stories-test-plugins/disable-gravatar --quiet
# Set pretty permalinks.
echo -e $(status_message "Setting permalink structure...")
wp rewrite structure '%postname%' --hard --quiet
# Configure site constants.
echo -e $(status_message "Configuring site constants...")
WP_DEBUG_CURRENT=$(wp config get --type=constant --format=json WP_DEBUG | tr -d '\r')
if [[ "$WP_DEBUG" != $WP_DEBUG_CURRENT ]]; then
wp config set WP_DEBUG $WP_DEBUG --raw --type=constant --quiet --anchor="That's all, stop editing"
WP_DEBUG_RESULT=$(wp config get --type=constant --format=json WP_DEBUG | tr -d '\r')
echo -e $(status_message "WP_DEBUG: $WP_DEBUG_RESULT...")
fi
SCRIPT_DEBUG_CURRENT=$(wp config get --type=constant --format=json SCRIPT_DEBUG | tr -d '\r')
if [[ "$SCRIPT_DEBUG" != $SCRIPT_DEBUG_CURRENT ]]; then
wp config set SCRIPT_DEBUG $SCRIPT_DEBUG --raw --type=constant --quiet --anchor="That's all, stop editing"
SCRIPT_DEBUG_RESULT=$(wp config get --type=constant --format=json SCRIPT_DEBUG | tr -d '\r')
echo -e $(status_message "SCRIPT_DEBUG: $SCRIPT_DEBUG_RESULT...")
fi
WEBSTORIES_DEV_MODE_CURRENT=!$WEBSTORIES_DEV_MODE;
if [[ "$(wp config has --type=constant WEBSTORIES_DEV_MODE)" ]]; then
WEBSTORIES_DEV_MODE_CURRENT=$(wp config get --type=constant --format=json WEBSTORIES_DEV_MODE | tr -d '\r')
fi
if [[ "$WEBSTORIES_DEV_MODE" != $WEBSTORIES_DEV_MODE_CURRENT ]]; then
wp config set WEBSTORIES_DEV_MODE $WEBSTORIES_DEV_MODE --raw --type=constant --quiet --anchor="That's all, stop editing"
WEBSTORIES_DEV_MODE_RESULT=$(wp config get --type=constant --format=json WEBSTORIES_DEV_MODE | tr -d '\r')
echo -e $(status_message "WEBSTORIES_DEV_MODE: $WEBSTORIES_DEV_MODE_RESULT...")
fi
MEDIA_TRASH_CURRENT=!MEDIA_TRASH;
if [[ "$(wp config has --type=constant MEDIA_TRASH)" ]]; then
MEDIA_TRASH_CURRENT=$(wp config get --type=constant --format=json MEDIA_TRASH | tr -d '\r')
fi
if [[ "$MEDIA_TRASH" != $MEDIA_TRASH_CURRENT ]]; then
wp config set MEDIA_TRASH $MEDIA_TRASH --raw --type=constant --quiet --anchor="That's all, stop editing"
MEDIA_TRASH_RESULT=$(wp config get --type=constant --format=json MEDIA_TRASH | tr -d '\r')
echo -e $(status_message "MEDIA_TRASH: $MEDIA_TRASH_RESULT...")
fi
# Let's make sure we have some media in the media library to work with.
echo -e $(status_message "Import default set of media assets...")
# TODO: use glob pattern to import items. See https://developer.wordpress.org/cli/commands/media/import/.
WEBM_VIDEO_ID=$(wp media import /var/www/html/wp-content/e2e-assets/small-video.webm --porcelain)
WEBM_VIDEO_POSTER_ID=$(wp media import /var/www/html/wp-content/e2e-assets/small-video-poster.jpg --post_id=$WEBM_VIDEO_ID --featured_image --porcelain)
# So the poster is marked as such and hidden in the editor.
wp post term add $WEBM_VIDEO_POSTER_ID web_story_media_source "poster-generation" --quiet
wp post meta add $WEBM_VIDEO_ID web_stories_poster_id $WEBM_VIDEO_POSTER_ID --quiet
wp media import /var/www/html/wp-content/e2e-assets/example-1.jpg --quiet
wp media import /var/www/html/wp-content/e2e-assets/example-2.jpg --quiet
wp media import /var/www/html/wp-content/e2e-assets/example-3.png --quiet
# Ensures that the patch command below always works.
wp option update web_stories_experiments '{}' --format=json
wp option patch insert web_stories_experiments enableSVG 1
wp media import /var/www/html/wp-content/e2e-assets/video-play.svg
wp option patch insert web_stories_experiments enableSVG 0
wp user list --format=yaml
wp post list --post_type=attachment --format=yaml
wp plugin list --format=yaml
echo -e $(status_message "Import sample WooCommerce products...")
wp import /var/www/html/wp-content/plugins/woocommerce/sample-data/sample_products.xml --authors=skip --quiet
echo -e $(status_message "Deactivating WooCommerce again...")
wp plugin deactivate woocommerce
echo -e $(status_message "Deactivating WordPress importer again...")
wp plugin deactivate wordpress-importer --quiet