11#! /usr/bin/env bash
22
33if [ $# -lt 3 ]; then
4- echo " usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
5- exit 1
4+ echo " usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
5+ exit 1
66fi
77
88DB_NAME=$1
99DB_USER=$2
1010DB_PASS=$3
1111DB_HOST=${4-localhost}
12- WP_VERSION=${5-master }
12+ WP_VERSION=${5-latest }
1313
1414WP_TESTS_DIR=${WP_TESTS_DIR-/ tmp/ wordpress-tests-lib}
15- WP_CORE_DIR=/tmp/wordpress/
15+ WP_CORE_DIR=${WP_CORE_DIR-/ tmp/ wordpress/ }
16+
17+ download () {
18+ if [ ` which curl` ]; then
19+ curl -s " $1 " > " $2 " ;
20+ elif [ ` which wget` ]; then
21+ wget -nv -O " $2 " " $1 "
22+ fi
23+ }
24+
25+ if [[ $WP_VERSION =~ [0-9]+\. [0-9]+ (\. [0-9]+)? ]]; then
26+ WP_TESTS_TAG=" tags/$WP_VERSION "
27+ else
28+ # http serves a single offer, whereas https serves multiple. we only want one
29+ download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
30+ grep ' [0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
31+ LATEST_VERSION=$( grep -o ' "version":"[^"]*' /tmp/wp-latest.json | sed ' s/"version":"//' )
32+ if [[ -z " $LATEST_VERSION " ]]; then
33+ echo " Latest WordPress version could not be found"
34+ exit 1
35+ fi
36+ WP_TESTS_TAG=" tags/$LATEST_VERSION "
37+ fi
1638
1739set -ex
1840
1941install_wp () {
20- mkdir -p $WP_CORE_DIR
2142
22- if [ $WP_VERSION == ' latest' ]; then
23- local ARCHIVE_NAME=' latest'
24- else
25- local ARCHIVE_NAME=" wordpress-$WP_VERSION "
26- fi
43+ if [ -d $WP_CORE_DIR ]; then
44+ return ;
45+ fi
46+
47+ mkdir -p $WP_CORE_DIR
48+
49+ if [ $WP_VERSION == ' latest' ]; then
50+ local ARCHIVE_NAME=' latest'
51+ else
52+ local ARCHIVE_NAME=" wordpress-$WP_VERSION "
53+ fi
2754
28- wget -nv -O /tmp/wordpress.tar.gz http ://wordpress.org/${ARCHIVE_NAME} .tar.gz
29- tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
55+ download https ://wordpress.org/${ARCHIVE_NAME} .tar.gz /tmp/wordpress .tar.gz
56+ tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
3057
31- wget -nv -O $WP_CORE_DIR /wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
58+ download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR /wp-content /db.php
3259}
3360
3461install_test_suite () {
35- # portable in-place argument for both GNU sed and Mac OSX sed
36- if [[ $( uname -s) == ' Darwin' ]]; then
37- local ioption=' -i ""'
38- else
39- local ioption=' -i'
40- fi
41-
42- # set up testing suite
43- mkdir -p $WP_TESTS_DIR
44- cd $WP_TESTS_DIR
45- svn co --quiet http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/
46-
47- wget -nv -O wp-tests-config.php http://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php
48- sed $ioption " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR ':" wp-tests-config.php
49- sed $ioption " s/youremptytestdbnamehere/$DB_NAME /" wp-tests-config.php
50- sed $ioption " s/yourusernamehere/$DB_USER /" wp-tests-config.php
51- sed $ioption " s/yourpasswordhere/$DB_PASS /" wp-tests-config.php
52- sed $ioption " s|localhost|${DB_HOST} |" wp-tests-config.php
62+ # portable in-place argument for both GNU sed and Mac OSX sed
63+ if [[ $( uname -s) == ' Darwin' ]]; then
64+ local ioption=' -i .bak'
65+ else
66+ local ioption=' -i'
67+ fi
68+
69+ # set up testing suite if it doesn't yet exist
70+ if [ ! -d $WP_TESTS_DIR ]; then
71+ # set up testing suite
72+ mkdir -p $WP_TESTS_DIR
73+ svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/includes/ $WP_TESTS_DIR /includes
74+ fi
75+
76+ cd $WP_TESTS_DIR
77+
78+ if [ ! -f wp-tests-config.php ]; then
79+ download https://develop.svn.wordpress.org/${WP_TESTS_TAG} /wp-tests-config-sample.php " $WP_TESTS_DIR " /wp-tests-config.php
80+ sed $ioption " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR ':" " $WP_TESTS_DIR " /wp-tests-config.php
81+ sed $ioption " s/youremptytestdbnamehere/$DB_NAME /" " $WP_TESTS_DIR " /wp-tests-config.php
82+ sed $ioption " s/yourusernamehere/$DB_USER /" " $WP_TESTS_DIR " /wp-tests-config.php
83+ sed $ioption " s/yourpasswordhere/$DB_PASS /" " $WP_TESTS_DIR " /wp-tests-config.php
84+ sed $ioption " s|localhost|${DB_HOST} |" " $WP_TESTS_DIR " /wp-tests-config.php
85+ fi
86+
5387}
5488
5589install_db () {
56- # parse DB_HOST for port or socket references
57- local PARTS=(${DB_HOST// \: / } )
58- local DB_HOSTNAME=${PARTS[0]} ;
59- local DB_SOCK_OR_PORT=${PARTS[1]} ;
60- local EXTRA=" "
61-
62- if ! [ -z $DB_HOSTNAME ] ; then
63- if [[ " $ DB_SOCK_OR_PORT" =~ ^[0-9]+$ ]] ; then
64- EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
65- elif ! [ -z $DB_SOCK_OR_PORT ] ; then
66- EXTRA=" --socket=$DB_SOCK_OR_PORT "
67- elif ! [ -z $DB_HOSTNAME ] ; then
68- EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
69- fi
70- fi
71-
72- # create database
73- mysqladmin create $DB_NAME --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
90+ # parse DB_HOST for port or socket references
91+ local PARTS=(${DB_HOST// \: / } )
92+ local DB_HOSTNAME=${PARTS[0]} ;
93+ local DB_SOCK_OR_PORT=${PARTS[1]} ;
94+ local EXTRA=" "
95+
96+ if ! [ -z $DB_HOSTNAME ] ; then
97+ if [ $( echo $ DB_SOCK_OR_PORT | grep -e ' ^[0-9]\{1,\}$ ' ) ] ; then
98+ EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
99+ elif ! [ -z $DB_SOCK_OR_PORT ] ; then
100+ EXTRA=" --socket=$DB_SOCK_OR_PORT "
101+ elif ! [ -z $DB_HOSTNAME ] ; then
102+ EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
103+ fi
104+ fi
105+
106+ # create database
107+ mysqladmin create $DB_NAME --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
74108}
75109
76110install_wp
77111install_test_suite
78- install_db
112+ install_db
0 commit comments