Bring New Travis CI Testing Online - Test 1

This commit is contained in:
Mitchell Krog 2017-06-01 16:26:24 +02:00
parent 0387e9ac7e
commit 556e1bdafa
24 changed files with 259 additions and 47 deletions

View file

@ -1,56 +1,64 @@
#!/bin/bash
# Travis CI Code to Configure Nginx
set -e
# Travis CI Testing for Nginx Ultimate Bad Bot Blocker
# https://github.com/mitchellkrogza
set -x
DIR=$(realpath $(dirname "$0"))
USER=$(whoami)
PHP_VERSION=$(phpenv version-name)
ROOT=$(realpath "$DIR/..")
PORT=9000
SERVER="/tmp/php.sock"
# Check Date - I only used this for testing to make sure I had set timezone correctly
# See .travis.yml file in the before_install section on how to set your timezone on TravisCI
#date
function tpl {
sed \
-e "s|{DIR}|$DIR|g" \
-e "s|{USER}|$USER|g" \
-e "s|{PHP_VERSION}|$PHP_VERSION|g" \
-e "s|{ROOT}|$ROOT|g" \
-e "s|{PORT}|$PORT|g" \
-e "s|{SERVER}|$SERVER|g" \
< $1 > $2
}
# Start Getting Nginx Ready for Testing the Nginx Bad Bot Blocker
# Make some working directories.
mkdir "$DIR/nginx"
mkdir "$DIR/nginx/sites-enabled"
mkdir "$DIR/nginx/bots.d"
mkdir "$DIR/var"
# Delete default site created by Nginx Installation
sudo rm /etc/nginx/sites-available/default
# Configure the PHP handler.
PHP_FPM_BIN="$HOME/.phpenv/versions/$PHP_VERSION/sbin/php-fpm"
PHP_FPM_CONF="$DIR/nginx/php-fpm.conf"
# Download the Nginx Bad Bot Blocker files from the Live Repository
sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/install-ngxblocker -O /usr/sbin/install-ngxblocker
sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/setup-ngxblocker -O /usr/sbin/setup-ngxblocker
sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/update-ngxblocker -O /usr/sbin/update-ngxblocker
# Build the php-fpm.conf.
tpl "$DIR/php-fpm.tpl.conf" "$PHP_FPM_CONF"
# Set our install and setup scripts to be executable
sudo chmod +x /usr/sbin/install-ngxblocker
sudo chmod +x /usr/sbin/setup-ngxblocker
sudo chmod +x /usr/sbin/update-ngxblocker
# Start php-fpm
"$PHP_FPM_BIN" --fpm-config "$PHP_FPM_CONF"
# Run Install-NgxBlocker
cd /usr/sbin
sudo ./install-ngxblocker -x
# Build the default nginx config files.
tpl "$DIR/nginx.tpl.conf" "$DIR/nginx/nginx.conf"
tpl "$DIR/fastcgi.tpl.conf" "$DIR/nginx/fastcgi.conf"
tpl "$DIR/ddos.tpl.conf" "$DIR/nginx/ddos.conf"
tpl "$DIR/blockbots.tpl.conf" "$DIR/nginx/blockbots.conf"
tpl "$DIR/whitelist-ips.tpl.conf" "$DIR/nginx/bots.d/whitelist-ips.conf"
tpl "$DIR/whitelist-domains.tpl.conf" "$DIR/nginx/bots.d/whitelist-domains.conf"
tpl "$DIR/blacklist-user-agents.tpl.conf" "$DIR/nginx/bots.d/blacklist-user-agents.conf"
tpl "$DIR/bad-referrer-words.tpl.conf" "$DIR/nginx/bots.d/bad-referrer-words.conf"
tpl "$DIR/custom-bad-referrers.tpl.conf" "$DIR/nginx/bots.d/custom-bad-referrers.conf"
tpl "$DIR/blacklist-ips.tpl.conf" "$DIR/nginx/bots.d/blacklist-ips.conf"
tpl "$DIR/botblocker-nginx-settings.tpl.conf" "$DIR/nginx/botblocker-nginx-settings.conf"
tpl "$DIR/globalblacklist.tpl.conf" "$DIR/nginx/globalblacklist.conf"
tpl "$DIR/default-site.tpl.conf" "$DIR/nginx/sites-enabled/default-site.conf"
# Copy our default.vhost file into Nginx /sites-available/
sudo cp $TRAVIS_BUILD_DIR/travis-ci/default.vhost /etc/nginx/sites-available/default.vhost
# Start nginx.
nginx -c "$DIR/nginx/nginx.conf"
# Link the vhost file into Nginx /sites-enabled/ and reload nginx
sudo ln -s /etc/nginx/sites-available/default.vhost /etc/nginx/sites-enabled/default.vhost
#sudo service nginx reload
# Run setup-ngxblocker
cd /usr/sbin
sudo ./setup-ngxblocker -x
# NOTE: for Verbose Testing of any shell scripts use below format adding sh -x before running the script
# this helps a lot inside the TravisCI environment to see where a shell script may be failing
#sudo sh -x ./setup-ngxblocker -x
# Load our Nginx.conf file and reload Nginx
sudo nginx -c /etc/nginx/nginx.conf
#sudo service nginx reload
# Copy our index.php file into the default site's root folder
sudo cp $TRAVIS_BUILD_DIR/travis-ci/index.php /var/www/html/index.php
# Run update-ngxblocker test
cd /usr/sbin
sudo ./update-ngxblocker
# Reload nginx - no need to do this as update-ngxblocker does this for us
#sudo service nginx reload
# Set all our other setup and deploy scripts to be executable
sudo chmod +x $TRAVIS_BUILD_DIR/travis-ci/modify-globalblacklist.sh
sudo chmod +x $TRAVIS_BUILD_DIR/travis-ci/deploy-package.sh
sudo chmod +x $TRAVIS_BUILD_DIR/travis-ci/change-file.sh
# Travis now goes into the rest of the tests in the script: section of .travis.yml