Guest User

Untitled

a guest
May 13th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. if [ $# -lt 3 ]; then
  4. echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
  5. exit 1
  6. fi
  7.  
  8. DB_NAME=$1
  9. DB_USER=$2
  10. DB_PASS=$3
  11. DB_HOST=${4-localhost}
  12. WP_VERSION=${5-latest}
  13.  
  14. WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
  15. WP_CORE_DIR=/tmp/wordpress/
  16.  
  17. set -ex
  18.  
  19. install_wp() {
  20. mkdir -p $WP_CORE_DIR
  21.  
  22. if [ $WP_VERSION == 'latest' ]; then
  23. local ARCHIVE_NAME='latest'
  24. else
  25. local ARCHIVE_NAME="wordpress-$WP_VERSION"
  26. fi
  27.  
  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
  30.  
  31. wget -nv -O $WP_CORE_DIR/wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
  32. }
  33.  
  34. install_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 .bak'
  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
  53. }
  54.  
  55. install_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
  74. }
  75.  
  76. install_wp
  77. install_test_suite
  78. install_db
Add Comment
Please, Sign In to add comment