Skip to content

Commit cd80f8b

Browse files
committed
No tput
1 parent 428275b commit cd80f8b

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

templates/install-wp-tests.sh

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# See https://raw.githubusercontent.com/wp-cli/scaffold-command/master/templates/install-wp-tests.sh
44

55
# 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)
6+
RED="\033[0;31m"
7+
GREEN="\033[0;32m"
8+
YELLOW="\033[0;33m"
9+
CYAN="\033[0;36m"
10+
RESET="\033[0m"
1111

1212
if [ $# -lt 3 ]; then
13-
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
13+
echo -e "${YELLOW}Usage:${RESET} $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
1414
exit 1
1515
fi
1616

@@ -34,7 +34,7 @@ download() {
3434
elif [ `which wget` ]; then
3535
wget -nv -O "$2" "$1"
3636
else
37-
echo "${RED}Error: Neither curl nor wget is installed.${RESET}"
37+
echo -e "${RED}Error: Neither curl nor wget is installed.${RESET}"
3838
exit 1
3939
fi
4040
}
@@ -46,7 +46,7 @@ check_for_updates() {
4646
download "$remote_url" "$tmp_script"
4747

4848
if [ ! -f "$tmp_script" ]; then
49-
echo "${YELLOW}Warning: Could not download the latest version of the script for update check.${RESET}"
49+
echo -e "${YELLOW}Warning: Could not download the latest version of the script for update check.${RESET}"
5050
return
5151
fi
5252

@@ -60,15 +60,15 @@ check_for_updates() {
6060
local_hash=$(sha256sum "$0" | awk '{print $1}')
6161
remote_hash=$(sha256sum "$tmp_script" | awk '{print $1}')
6262
else
63-
echo "${YELLOW}Warning: Could not find shasum or sha256sum to check for script updates.${RESET}"
63+
echo -e "${YELLOW}Warning: Could not find shasum or sha256sum to check for script updates.${RESET}"
6464
rm "$tmp_script"
6565
return
6666
fi
6767

6868
rm "$tmp_script"
6969

7070
if [ "$local_hash" != "$remote_hash" ]; then
71-
echo "${YELLOW}Warning: A newer version of this script is available at $remote_url${RESET}"
71+
echo -e "${YELLOW}Warning: A newer version of this script is available at $remote_url${RESET}"
7272
fi
7373
}
7474
check_for_updates
@@ -92,21 +92,20 @@ else
9292
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
9393
LATEST_VERSION=$(grep -oE '"version":"[^"]*' /tmp/wp-latest.json | head -n 1 | sed 's/"version":"//')
9494
if [[ -z "$LATEST_VERSION" ]]; then
95-
echo "${RED}Error: Latest WordPress version could not be found.${RESET}"
95+
echo -e "${RED}Error: Latest WordPress version could not be found.${RESET}"
9696
exit 1
9797
fi
9898
WP_TESTS_TAG="tags/$LATEST_VERSION"
9999
fi
100-
set -ex
101100

102101
install_wp() {
103102

104103
if [ -f $WP_CORE_FILE ]; then
105-
echo "${CYAN}WordPress is already installed.${RESET}"
104+
echo -e "${CYAN}WordPress is already installed.${RESET}"
106105
return;
107106
fi
108107

109-
echo "${CYAN}Installing WordPress...${RESET}"
108+
echo -e "${CYAN}Installing WordPress...${RESET}"
110109

111110
rm -rf $WP_CORE_DIR
112111
mkdir -p $WP_CORE_DIR
@@ -139,7 +138,7 @@ install_wp() {
139138
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz
140139
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
141140
fi
142-
echo "${GREEN}WordPress installed successfully.${RESET}"
141+
echo -e "${GREEN}WordPress installed successfully.${RESET}"
143142
}
144143

145144
install_test_suite() {
@@ -152,7 +151,7 @@ install_test_suite() {
152151

153152
# set up testing suite if it doesn't yet exist or only partially exists
154153
if [ ! -f $WP_TESTS_FILE ]; then
155-
echo "${CYAN}Installing test suite...${RESET}"
154+
echo -e "${CYAN}Installing test suite...${RESET}"
156155
# set up testing suite
157156
rm -rf $WP_TESTS_DIR
158157
mkdir -p $WP_TESTS_DIR
@@ -174,13 +173,13 @@ install_test_suite() {
174173
mv $TMPDIR/wordpress-develop-${ref}/tests/phpunit/data $WP_TESTS_DIR/
175174
rm -rf $TMPDIR/wordpress-develop-${ref}
176175
rm $TMPDIR/wordpress-develop.tar.gz
177-
echo "${GREEN}Test suite installed.${RESET}"
176+
echo -e "${GREEN}Test suite installed.${RESET}"
178177
else
179-
echo "${CYAN}Test suite is already installed.${RESET}"
178+
echo -e "${CYAN}Test suite is already installed.${RESET}"
180179
fi
181180

182181
if [ ! -f "$WP_TESTS_DIR"/wp-tests-config.php ]; then
183-
echo "${CYAN}Configuring test suite...${RESET}"
182+
echo -e "${CYAN}Configuring test suite...${RESET}"
184183
if [[ $WP_TESTS_TAG == 'trunk' ]]; then
185184
ref=master
186185
elif [[ $WP_TESTS_TAG == branches/* ]]; then
@@ -196,9 +195,9 @@ install_test_suite() {
196195
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
197196
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
198197
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
199-
echo "${GREEN}Test suite configured.${RESET}"
198+
echo -e "${GREEN}Test suite configured.${RESET}"
200199
else
201-
echo "${CYAN}Test suite is already configured.${RESET}"
200+
echo -e "${CYAN}Test suite is already configured.${RESET}"
202201
fi
203202

204203
}
@@ -207,16 +206,16 @@ recreate_db() {
207206
shopt -s nocasematch
208207
if [[ $1 =~ ^(y|yes)$ ]]
209208
then
210-
echo "${CYAN}Recreating the database ($DB_NAME)...${RESET}"
209+
echo -e "${CYAN}Recreating the database ($DB_NAME)...${RESET}"
211210
if [ `which mariadb-admin` ]; then
212211
mariadb-admin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA
213212
else
214213
mysqladmin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA
215214
fi
216215
create_db
217-
echo "${GREEN}Database ($DB_NAME) recreated.${RESET}"
216+
echo -e "${GREEN}Database ($DB_NAME) recreated.${RESET}"
218217
else
219-
echo "${YELLOW}Leaving the existing database ($DB_NAME) in place.${RESET}"
218+
echo -e "${YELLOW}Leaving the existing database ($DB_NAME) in place.${RESET}"
220219
fi
221220
shopt -u nocasematch
222221
}
@@ -232,7 +231,7 @@ create_db() {
232231
install_db() {
233232

234233
if [ ${SKIP_DB_CREATE} = "true" ]; then
235-
echo "${YELLOW}Skipping database creation.${RESET}"
234+
echo -e "${YELLOW}Skipping database creation.${RESET}"
236235
return 0
237236
fi
238237

@@ -260,17 +259,17 @@ install_db() {
260259
fi
261260
if [ $($DB_CLIENT --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute='show databases;' | grep ^$DB_NAME$) ]
262261
then
263-
echo "${YELLOW}Reinstalling will delete the existing test database ($DB_NAME)${RESET}"
262+
echo -e "${YELLOW}Reinstalling will delete the existing test database ($DB_NAME)${RESET}"
264263
read -p 'Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB
265264
recreate_db $DELETE_EXISTING_DB
266265
else
267-
echo "${CYAN}Creating database ($DB_NAME)...${RESET}"
266+
echo -e "${CYAN}Creating database ($DB_NAME)...${RESET}"
268267
create_db
269-
echo "${GREEN}Database ($DB_NAME) created.${RESET}"
268+
echo -e "${GREEN}Database ($DB_NAME) created.${RESET}"
270269
fi
271270
}
272271

273272
install_wp
274273
install_test_suite
275274
install_db
276-
echo "${GREEN}Done.${RESET}"
275+
echo -e "${GREEN}Done.${RESET}"

0 commit comments

Comments
 (0)