1
1
#! /usr/bin/env bash
2
2
3
3
if [ $# -lt 3 ]; then
4
- echo " usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation] "
4
+ echo " usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
5
5
exit 1
6
6
fi
7
7
@@ -10,25 +10,36 @@ DB_USER=$2
10
10
DB_PASS=$3
11
11
DB_HOST=${4-localhost}
12
12
WP_VERSION=${5-latest}
13
- SKIP_DB_CREATE=${6-false}
14
13
15
14
WP_TESTS_DIR=${WP_TESTS_DIR-/ tmp/ wordpress-tests-lib}
16
15
WP_CORE_DIR=${WP_CORE_DIR-/ tmp/ wordpress/ }
17
-
18
- ELEMENTOR_PLUGIN_DIR =${ELEMENTOR_PLUGIN_DIR -/ tmp/ wordpress / wp-content / plugins }
16
+ ELEMENTOR_PLUGIN_DIR= ${ELEMENTOR_PLUGIN_DIR- / tmp}
17
+ HELLO_PLUS_PLUGIN_DIR =${HELLO_PLUS_PLUGIN_DIR -/ tmp}
19
18
20
19
download () {
20
+ local url=" $1 "
21
+ local output=" $2 "
22
+
21
23
if [ ` which curl` ]; then
22
- curl --location -s " $1 " > " $2 " ;
24
+ curl --location --fail --show-error --silent --output " $output " " $url "
25
+ local exit_code=$?
23
26
elif [ ` which wget` ]; then
24
- wget -nv -O " $2 " " $1 "
27
+ wget -nv -O " $output " " $url "
28
+ local exit_code=$?
29
+ else
30
+ echo " Error: Neither curl nor wget found. Please install one of them."
31
+ exit 1
32
+ fi
33
+
34
+ if [ $exit_code -ne 0 ]; then
35
+ echo " Error: Failed to download $url "
36
+ rm -f " $output "
37
+ exit 1
25
38
fi
26
39
}
27
40
28
41
if [[ $WP_VERSION =~ [0-9]+\. [0-9]+ (\. [0-9]+)? ]]; then
29
42
WP_TESTS_TAG=" tags/$WP_VERSION "
30
- elif [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
31
- WP_TESTS_TAG=" trunk"
32
43
else
33
44
# http serves a single offer, whereas https serves multiple. we only want one
34
45
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
@@ -49,7 +60,6 @@ install_wp() {
49
60
fi
50
61
51
62
mkdir -p $WP_CORE_DIR
52
-
53
63
if [[ $WP_VERSION == ' nightly' || $WP_VERSION == ' trunk' ]]; then
54
64
mkdir -p /tmp/wordpress-nightly
55
65
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
@@ -88,27 +98,21 @@ install_test_suite() {
88
98
# set up testing suite
89
99
mkdir -p $WP_TESTS_DIR
90
100
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/includes/ $WP_TESTS_DIR /includes
91
- svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/data/ $WP_TESTS_DIR /data
92
101
fi
93
102
103
+ cd $WP_TESTS_DIR
104
+
94
105
if [ ! -f wp-tests-config.php ]; then
95
106
download https://develop.svn.wordpress.org/${WP_TESTS_TAG} /wp-tests-config-sample.php " $WP_TESTS_DIR " /wp-tests-config.php
96
- # remove all forward slashes in the end
97
- WP_CORE_DIR=$( echo $WP_CORE_DIR | sed " s:/\+$::" )
98
- sed $ioption " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
107
+ sed $ioption " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR ':" " $WP_TESTS_DIR " /wp-tests-config.php
99
108
sed $ioption " s/youremptytestdbnamehere/$DB_NAME /" " $WP_TESTS_DIR " /wp-tests-config.php
100
109
sed $ioption " s/yourusernamehere/$DB_USER /" " $WP_TESTS_DIR " /wp-tests-config.php
101
110
sed $ioption " s/yourpasswordhere/$DB_PASS /" " $WP_TESTS_DIR " /wp-tests-config.php
102
111
sed $ioption " s|localhost|${DB_HOST} |" " $WP_TESTS_DIR " /wp-tests-config.php
103
112
fi
104
-
105
113
}
106
114
107
115
install_db () {
108
- if [ ${SKIP_DB_CREATE} = " true" ]; then
109
- return 0
110
- fi
111
-
112
116
# parse DB_HOST for port or socket references
113
117
local PARTS=(${DB_HOST// \: / } )
114
118
local DB_HOSTNAME=${PARTS[0]} ;
@@ -130,12 +134,73 @@ install_db() {
130
134
}
131
135
132
136
install_elementor_plugin () {
137
+ echo " Installing Elementor plugin..."
133
138
rm -rf ${ELEMENTOR_PLUGIN_DIR} /elementor
134
- download https://downloads.wordpress.org/plugin/elementor.latest-stable.zip /tmp/elementor.zip
135
- unzip -q /tmp/elementor.zip -d ${ELEMENTOR_PLUGIN_DIR}
139
+
140
+ # Download the plugin
141
+ local zip_file=" /tmp/elementor.zip"
142
+ rm -f " $zip_file "
143
+
144
+ echo " Downloading Elementor from WordPress.org..."
145
+ download https://downloads.wordpress.org/plugin/elementor.latest-stable.zip " $zip_file "
146
+
147
+ # Validate the downloaded file is a valid zip
148
+ if ! unzip -t " $zip_file " > /dev/null 2>&1 ; then
149
+ echo " Error: Downloaded file is not a valid zip archive"
150
+ echo " File size: $( ls -lh " $zip_file " 2> /dev/null | awk ' {print $5}' || echo ' File not found' ) "
151
+ echo " File type: $( file " $zip_file " 2> /dev/null || echo ' Cannot determine file type' ) "
152
+ rm -f " $zip_file "
153
+ exit 1
154
+ fi
155
+
156
+ # Extract the plugin
157
+ echo " Extracting Elementor plugin..."
158
+ if ! unzip -q " $zip_file " -d ${ELEMENTOR_PLUGIN_DIR} ; then
159
+ echo " Error: Failed to extract Elementor plugin"
160
+ rm -f " $zip_file "
161
+ exit 1
162
+ fi
163
+
164
+ # Clean up
165
+ rm -f " $zip_file "
166
+ echo " Elementor plugin installed successfully"
167
+ }
168
+
169
+ install_hello_plus_plugin () {
170
+ echo " Installing Hello Plus plugin..."
171
+ rm -rf ${HELLO_PLUS_PLUGIN_DIR} /hello-plus
172
+
173
+ # Download the plugin
174
+ local zip_file=" /tmp/hello-plus.zip"
175
+ rm -f " $zip_file "
176
+
177
+ echo " Downloading Hello Plus from WordPress.org..."
178
+ download https://downloads.wordpress.org/plugin/hello-plus.latest-stable.zip " $zip_file "
179
+
180
+ # Validate the downloaded file is a valid zip
181
+ if ! unzip -t " $zip_file " > /dev/null 2>&1 ; then
182
+ echo " Error: Downloaded file is not a valid zip archive"
183
+ echo " File size: $( ls -lh " $zip_file " 2> /dev/null | awk ' {print $5}' || echo ' File not found' ) "
184
+ echo " File type: $( file " $zip_file " 2> /dev/null || echo ' Cannot determine file type' ) "
185
+ rm -f " $zip_file "
186
+ exit 1
187
+ fi
188
+
189
+ # Extract the plugin
190
+ echo " Extracting Hello Plus plugin..."
191
+ if ! unzip -q " $zip_file " -d ${HELLO_PLUS_PLUGIN_DIR} ; then
192
+ echo " Error: Failed to extract Hello Plus plugin"
193
+ rm -f " $zip_file "
194
+ exit 1
195
+ fi
196
+
197
+ # Clean up
198
+ rm -f " $zip_file "
199
+ echo " Hello Plus plugin installed successfully"
136
200
}
137
201
138
202
install_wp
139
203
install_test_suite
140
204
install_db
141
205
install_elementor_plugin
206
+ install_hello_plus_plugin
0 commit comments