22
33# See https://raw.githubusercontent.com/wp-cli/scaffold-command/master/templates/install-wp-tests.sh
44
5+ # Set up colors for output
6+ RED=$( tput setaf 1)
7+ GREEN=$( tput setaf 2)
8+ YELLOW=$( tput setaf 3)
9+ CYAN=$( tput setaf 6)
10+ RESET=$( tput sgr0)
11+
512if [ $# -lt 3 ]; then
613 echo " usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
714 exit 1
@@ -27,7 +34,7 @@ download() {
2734 elif [ ` which wget` ]; then
2835 wget -nv -O " $2 " " $1 "
2936 else
30- echo " Error: Neither curl nor wget is installed."
37+ echo " ${RED} Error: Neither curl nor wget is installed.${RESET} "
3138 exit 1
3239 fi
3340}
@@ -39,7 +46,7 @@ check_for_updates() {
3946 download " $remote_url " " $tmp_script "
4047
4148 if [ ! -f " $tmp_script " ]; then
42- echo " Warning: Could not download the latest version of the script for update check."
49+ echo " ${YELLOW} Warning: Could not download the latest version of the script for update check.${RESET} "
4350 return
4451 fi
4552
@@ -53,23 +60,22 @@ check_for_updates() {
5360 local_hash=$( sha256sum " $0 " | awk ' {print $1}' )
5461 remote_hash=$( sha256sum " $tmp_script " | awk ' {print $1}' )
5562 else
56- echo " Warning: Could not find shasum or sha256sum to check for script updates."
63+ echo " ${YELLOW} Warning: Could not find shasum or sha256sum to check for script updates.${RESET} "
5764 rm " $tmp_script "
5865 return
5966 fi
6067
6168 rm " $tmp_script "
6269
6370 if [ " $local_hash " != " $remote_hash " ]; then
64- echo " Warning: A newer version of this script is available at $remote_url "
71+ echo " ${YELLOW} Warning: A newer version of this script is available at $remote_url ${RESET} "
6572 fi
6673}
6774check_for_updates
6875
6976if [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+\- (beta| RC)[0-9]+$ ]]; then
7077 WP_BRANCH=${WP_VERSION% \- * }
7178 WP_TESTS_TAG=" branches/$WP_BRANCH "
72-
7379elif [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+$ ]]; then
7480 WP_TESTS_TAG=" branches/$WP_VERSION "
7581elif [[ $WP_VERSION =~ [0-9]+\. [0-9]+\. [0-9]+ ]]; then
@@ -84,10 +90,9 @@ elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
8490else
8591 # http serves a single offer, whereas https serves multiple. we only want one
8692 download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
87- grep ' [0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
88- LATEST_VERSION=$( grep -o ' "version":"[^"]*' /tmp/wp-latest.json | sed ' s/"version":"//' )
93+ LATEST_VERSION=$( grep -oE ' "version":"[^"]*' /tmp/wp-latest.json | head -n 1 | sed ' s/"version":"//' )
8994 if [[ -z " $LATEST_VERSION " ]]; then
90- echo " Latest WordPress version could not be found"
95+ echo " ${RED} Error: Latest WordPress version could not be found. ${RESET} "
9196 exit 1
9297 fi
9398 WP_TESTS_TAG=" tags/$LATEST_VERSION "
@@ -97,9 +102,12 @@ set -ex
97102install_wp () {
98103
99104 if [ -f $WP_CORE_FILE ]; then
105+ echo " ${CYAN} WordPress is already installed.${RESET} "
100106 return ;
101107 fi
102108
109+ echo " ${CYAN} Installing WordPress...${RESET} "
110+
103111 rm -rf $WP_CORE_DIR
104112 mkdir -p $WP_CORE_DIR
105113
@@ -131,6 +139,7 @@ install_wp() {
131139 download https://wordpress.org/${ARCHIVE_NAME} .tar.gz $TMPDIR /wordpress.tar.gz
132140 tar --strip-components=1 -zxmf $TMPDIR /wordpress.tar.gz -C $WP_CORE_DIR
133141 fi
142+ echo " ${GREEN} WordPress installed successfully.${RESET} "
134143}
135144
136145install_test_suite () {
@@ -143,6 +152,7 @@ install_test_suite() {
143152
144153 # set up testing suite if it doesn't yet exist or only partially exists
145154 if [ ! -f $WP_TESTS_FILE ]; then
155+ echo " ${CYAN} Installing test suite...${RESET} "
146156 # set up testing suite
147157 rm -rf $WP_TESTS_DIR
148158 mkdir -p $WP_TESTS_DIR
@@ -164,9 +174,13 @@ install_test_suite() {
164174 mv $TMPDIR /wordpress-develop-${ref} /tests/phpunit/data $WP_TESTS_DIR /
165175 rm -rf $TMPDIR /wordpress-develop-${ref}
166176 rm $TMPDIR /wordpress-develop.tar.gz
177+ echo " ${GREEN} Test suite installed.${RESET} "
178+ else
179+ echo " ${CYAN} Test suite is already installed.${RESET} "
167180 fi
168181
169182 if [ ! -f " $WP_TESTS_DIR " /wp-tests-config.php ]; then
183+ echo " ${CYAN} Configuring test suite...${RESET} "
170184 if [[ $WP_TESTS_TAG == ' trunk' ]]; then
171185 ref=master
172186 elif [[ $WP_TESTS_TAG == branches/* ]]; then
@@ -182,6 +196,9 @@ install_test_suite() {
182196 sed $ioption " s/yourusernamehere/$DB_USER /" " $WP_TESTS_DIR " /wp-tests-config.php
183197 sed $ioption " s/yourpasswordhere/$DB_PASS /" " $WP_TESTS_DIR " /wp-tests-config.php
184198 sed $ioption " s|localhost|${DB_HOST} |" " $WP_TESTS_DIR " /wp-tests-config.php
199+ echo " ${GREEN} Test suite configured.${RESET} "
200+ else
201+ echo " ${CYAN} Test suite is already configured.${RESET} "
185202 fi
186203
187204}
@@ -190,15 +207,16 @@ recreate_db() {
190207 shopt -s nocasematch
191208 if [[ $1 =~ ^(y| yes)$ ]]
192209 then
210+ echo " ${CYAN} Recreating the database ($DB_NAME )...${RESET} "
193211 if [ ` which mariadb-admin` ]; then
194212 mariadb-admin drop $DB_NAME -f --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
195213 else
196214 mysqladmin drop $DB_NAME -f --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
197215 fi
198216 create_db
199- echo " Recreated the database ($DB_NAME ). "
217+ echo " ${GREEN} Database ($DB_NAME ) recreated. ${RESET} "
200218 else
201- echo " Leaving the existing database ($DB_NAME ) in place."
219+ echo " ${YELLOW} Leaving the existing database ($DB_NAME ) in place.${RESET} "
202220 fi
203221 shopt -u nocasematch
204222}
@@ -214,6 +232,7 @@ create_db() {
214232install_db () {
215233
216234 if [ ${SKIP_DB_CREATE} = " true" ]; then
235+ echo " ${YELLOW} Skipping database creation.${RESET} "
217236 return 0
218237 fi
219238
@@ -241,14 +260,17 @@ install_db() {
241260 fi
242261 if [ $( $DB_CLIENT --user=" $DB_USER " --password=" $DB_PASS " $EXTRA --execute=' show databases;' | grep ^$DB_NAME $) ]
243262 then
244- echo " Reinstalling will delete the existing test database ($DB_NAME )"
263+ echo " ${YELLOW} Reinstalling will delete the existing test database ($DB_NAME )${RESET} "
245264 read -p ' Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB
246265 recreate_db $DELETE_EXISTING_DB
247266 else
267+ echo " ${CYAN} Creating database ($DB_NAME )...${RESET} "
248268 create_db
269+ echo " ${GREEN} Database ($DB_NAME ) created.${RESET} "
249270 fi
250271}
251272
252273install_wp
253274install_test_suite
254275install_db
276+ echo " ${GREEN} Done.${RESET} "
0 commit comments