22# Travis CI Bash Script for Installing Nginx on Travis CI and Testing Configurations
33# https://github.com/mitchellkrogza
44
5- set -e
65set -x
76
8- DIR=$( realpath $( dirname " $0 " ) )
9- USER=$( whoami)
10- PHP_VERSION=$( phpenv version-name)
11- ROOT=$( realpath " $DIR /.." )
12- PORT=9000
13- SERVER=" /tmp/php.sock"
14-
15- function tpl {
16- sed \
17- -e " s|{DIR}|$DIR |g" \
18- -e " s|{USER}|$USER |g" \
19- -e " s|{PHP_VERSION}|$PHP_VERSION |g" \
20- -e " s|{ROOT}|$ROOT |g" \
21- -e " s|{PORT}|$PORT |g" \
22- -e " s|{SERVER}|$SERVER |g" \
23- < $1 > $2
24- }
25-
26- # Make some working directories.
27- mkdir " $DIR /nginx"
28- mkdir " $DIR /nginx/sites-enabled"
29- mkdir " $DIR /var"
30-
31- # Configure the PHP handler.
32- if [ " $PHP_VERSION " = ' hhvm' ] || [ " $PHP_VERSION " = ' hhvm-nightly' ]
33- then
34- HHVM_CONF=" $DIR /nginx/hhvm.ini"
35-
36- tpl " $DIR /hhvm.tpl" " $HHVM_CONF "
37-
38- cat " $HHVM_CONF "
39-
40- hhvm \
41- --mode=daemon \
42- --config=" $HHVM_CONF "
43- else
44- PHP_FPM_BIN=" $HOME /.phpenv/versions/$PHP_VERSION /sbin/php-fpm"
45- PHP_FPM_CONF=" $DIR /nginx/php-fpm.conf"
46-
47- # Build the php-fpm.conf.
48- tpl " $DIR /php-fpm.tpl" " $PHP_FPM_CONF "
49-
50- # Start php-fpm
51- " $PHP_FPM_BIN " --fpm-config " $PHP_FPM_CONF "
52- fi
53-
54- # Build the default nginx config files.
55- tpl " $DIR /nginx.tpl" " $DIR /nginx/nginx.conf"
56- tpl " $DIR /fastcgi.tpl" " $DIR /nginx/fastcgi.conf"
57- tpl " $DIR /defaultsite.tpl" " $DIR /nginx/sites-enabled/defaultsite.conf"
58-
59- # Start nginx.
60- nginx -c " $DIR /nginx/nginx.conf"
7+ # Check Date - I only used this for testing to make sure I had set timezone correctly
8+ # See .travis.yml file in the before_install section on how to set your timezone on TravisCI
9+ # date
10+
11+ # Start Getting Nginx Ready for Testing the Nginx Bad Bot Blocker
12+
13+ # Delete default site created by Nginx Installation
14+ sudo rm /etc/nginx/sites-available/default
15+
16+ # Download the Nginx Bad Bot Blocker files from the Live Repository
17+ sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/install-ngxblocker -O /usr/sbin/install-ngxblocker
18+ sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/setup-ngxblocker -O /usr/sbin/setup-ngxblocker
19+ sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/update-ngxblocker -O /usr/sbin/update-ngxblocker
20+
21+ # Set our install and setup scripts to be executable
22+ sudo chmod +x /usr/sbin/install-ngxblocker
23+ sudo chmod +x /usr/sbin/setup-ngxblocker
24+ sudo chmod +x /usr/sbin/update-ngxblocker
25+
26+ # Run Install-NgxBlocker
27+ cd /usr/sbin
28+ sudo ./install-ngxblocker -x
29+
30+ # Copy our default.vhost file into Nginx /sites-available/
31+ sudo cp $TRAVIS_BUILD_DIR /travis-ci/default.vhost /etc/nginx/sites-available/default.vhost
32+
33+ # Link the vhost file into Nginx /sites-enabled/ and reload nginx
34+ sudo ln -s /etc/nginx/sites-available/default.vhost /etc/nginx/sites-enabled/default.vhost
35+ # sudo service nginx reload
36+
37+ # Run setup-ngxblocker
38+ cd /usr/sbin
39+ sudo ./setup-ngxblocker -x
40+
41+ # NOTE: for Verbose Testing of any shell scripts use below format adding sh -x before running the script
42+ # this helps a lot inside the TravisCI environment to see where a shell script may be failing
43+ # sudo sh -x ./setup-ngxblocker -x
44+
45+ # Load our Nginx.conf file and reload Nginx
46+ sudo nginx -c /etc/nginx/nginx.conf
47+ # sudo service nginx reload
48+
49+ # Copy our index.php file into the default site's root folder
50+ sudo cp $TRAVIS_BUILD_DIR /www/index.php /var/www/html/index.php
51+
52+ # Run update-ngxblocker test
53+ cd /usr/sbin
54+ sudo ./update-ngxblocker
55+
56+ # Reload nginx - no need to do this as update-ngxblocker does this for us
57+ # sudo service nginx reload
58+
59+ # Set all our other setup and deploy scripts to be executable
60+ sudo chmod +x $TRAVIS_BUILD_DIR /travis-ci/modify-globalblacklist.sh
61+ sudo chmod +x $TRAVIS_BUILD_DIR /travis-ci/deploy-package.sh
62+ sudo chmod +x $TRAVIS_BUILD_DIR /travis-ci/deploy-package.sh
63+ sudo chmod +x $TRAVIS_BUILD_DIR /travis-ci/change-file.sh
64+
65+ # Travis now goes into the rest of the tests in the script: section of .travis.yml
0 commit comments