Skip to content

Commit cea5a89

Browse files
Tidy up install scripts and add commenting in all scripts. Final preps before this moves to the live repo of the Nginx Bad Bot Blocker
1 parent 957467c commit cea5a89

File tree

4 files changed

+60
-199
lines changed

4 files changed

+60
-199
lines changed

.travis.yml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,22 @@ addons:
2424
- realpath
2525
- mailutils
2626
before_install:
27-
#- echo 'Africa/Johannesburg' | sudo tee /etc/timezone
28-
#- sudo dpkg-reconfigure --frontend noninteractive tzdata
2927
- export TZ=Africa/Johannesburg
3028
install:
3129
- sudo add-apt-repository -y ppa:nginx/stable
3230
- sudo apt-get update
3331
- sudo apt-get install -y --force-yes nginx-extras
34-
#- travis-ci/install-nginx2.sh
3532
script:
3633
- travis-ci/install-nginx2.sh
3734
- curl -vsf 'http://localhost:9000/index.php' &> /dev/stdout
3835
- curl -A "googlebot" http://localhost:9000/index.php &> /dev/stdout
39-
#- cat /tmp/error.log
4036
- STATUSCODE=$(curl -A "80legs" http://localhost:9000/index.php &> /dev/stderr --write-out "%{http_code}") | if test $STATUSCODE 52; then exit 0; fi
4137
- STATUSCODE=$(curl -A "masscan" http://localhost:9000/index.php &> /dev/stderr --write-out "%{http_code}") | if test $STATUSCODE 52; then exit 0; fi
4238
- STATUSCODE=$(curl -I http://localhost:9000/index.php -e http://100dollars-seo.com &> /dev/stderr --write-out "%{http_code}") | if test $STATUSCODE 52; then exit 0; fi
4339
- STATUSCODE=$(curl -I http://localhost:9000/index.php -e http://zx6.ru &> /dev/stderr --write-out "%{http_code}") | if test $STATUSCODE 52; then exit 0; fi
4440
- travis-ci/changefile.sh
4541

4642
before_deploy:
47-
#- git remote -v
48-
#- git remote add origin https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git
49-
#- git config --global user.email "builds@travis-ci.com"
50-
#- git config --global user.name "Travis CI"
51-
#- git config --global user.email "${GIT_EMAIL}"
52-
#- git config --global user.name "${GIT_NAME}"
53-
#- git config --global push.default simple
54-
#- export GIT_TAG=v1.0.$TRAVIS_BUILD_NUMBER
55-
#- sudo $TRAVIS_BUILD_DIR/travis-ci/modify-globalblacklist.sh
56-
#- cat $TRAVIS_BUILD_DIR/globalblacklist.conf
57-
#- git commit -am "Travis Test Passed"
58-
#- git commit -a
59-
#- cd $TRAVIS_BUILD_DIR
60-
#- git add $TRAVIS_BUILD_DIR/globalblacklist.conf
61-
#- git commit -m "Build $TRAVIS_BUILD_NUMBER"
62-
#- git commit -am "Build $TRAVIS_BUILD_NUMBER"
63-
#- git tag $GIT_TAG -a -m "Tag Generated from TravisCI for build $TRAVIS_BUILD_NUMBER"
64-
#- git push origin master && git push origin master --tags
65-
#- git pull origin https://${GH_TOKEN}@github.com/mitchellkrogza/Travis-CI-Nginx-for-Testing-Nginx-Configuration
66-
#- git push https://${GH_TOKEN}@github.com/mitchellkrogza/Travis-CI-Nginx-for-Testing-Nginx-Configuration --all
67-
#- ls -aR
6843
- sh -x travis-ci/deploy2.sh
6944
deploy:
7045
provider: releases
@@ -78,7 +53,6 @@ deploy:
7853
on:
7954
repo: mitchellkrogza/Travis-CI-Nginx-for-Testing-Nginx-Configuration
8055
tags: false
81-
#all_branches: true
8256
branches:
8357
except:
8458
- "/^v[0-9]/"

travis-ci/changefile.sh

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,30 @@
22
YEAR=$(date +"%Y")
33
MONTH=$(date +"%m")
44
cd $TRAVIS_BUILD_DIR
5+
56
#Remove Remotes Added by TravisCI
67
git remote rm origin
8+
79
#Add Remote with Secure Key
810
git remote add origin https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git
11+
912
#List Remotes ONLY DURING testing - do not do this on live repo / possible key leak
1013
#git remote -v
11-
#ls -la $TRAVIS_BUILD_DIR
12-
#ls -la $TRAVIS_BUILD_DIR/.git
13-
#git fetch origin master
14-
#git pull origin master
15-
#ls -la $TRAVIS_BUILD_DIR/.git
16-
#echo "Check permissions on git HEAD / get dir listing of travis build dir"
14+
15+
# Set Git Variables
1716
git config --global user.email "${GIT_EMAIL}"
1817
git config --global user.name "${GIT_NAME}"
1918
git config --global push.default simple
19+
20+
# Make sure we have master branch checked out in Git
2021
git checkout master
21-
#export GIT_TAG=V2.$YEAR-$MONTH.$TRAVIS_BUILD_NUMBER
22-
#msg="Tag Generated from TravisCI for build $TRAVIS_BUILD_NUMBER"
23-
#echo "$msg" >> $TRAVIS_BUILD_DIR/build.txt
22+
23+
# Modify our file and make sure Travis is owner
2424
sudo $TRAVIS_BUILD_DIR/travis-ci/modify-globalblacklist.sh
2525
sudo chown travis:travis $TRAVIS_BUILD_DIR/globalblacklist.conf
26+
27+
# Add the modified file to the and commit it
2628
git add $TRAVIS_BUILD_DIR/globalblacklist.conf
2729
git commit -am "V3.$YEAR.$MONTH.$TRAVIS_BUILD_NUMBER [ci skip]"
28-
#git add -A .
29-
#git add $TRAVIS_BUILD_DIR/build.txt
30-
#git commit -m "Update build version file with $TRAVIS_BUILD_NUMBER"
31-
32-
#YEAR=$(date +"%Y")
33-
#MONTH=$(date +"%m")
34-
#sudo git remote -v
35-
#sudo git remote rm origin
36-
#sudo git config --global user.email "${GIT_EMAIL}"
37-
#sudo git config --global user.name "${GIT_NAME}"
38-
#sudo git config --global push.default simple
39-
#export GIT_TAG=v1.0.$TRAVIS_BUILD_NUMBER
40-
#msg="Tag Generated from TravisCI for build $TRAVIS_BUILD_NUMBER"
41-
#echo "$msg" >> $TRAVIS_BUILD_DIR/build.txt
42-
#git add $TRAVIS_BUILD_DIR/build.txt
43-
#sudo $TRAVIS_BUILD_DIR/travis-ci/modify-globalblacklist.sh
44-
#sudo git add $TRAVIS_BUILD_DIR/globalblacklist.conf
45-
#sudo git commit -m "Build $GIT_TAG"
30+
31+
# Travis now moves to the before_deploy: section of .travis.yml

travis-ci/deploy2.sh

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,20 @@
11
#!/bin/bash
22
YEAR=$(date +"%Y")
33
MONTH=$(date +"%m")
4+
5+
# Make Sure we are in the Build Directory
46
cd $TRAVIS_BUILD_DIR
5-
#git clone --depth=50 --branch=master https://github.com/mitchellkrogza/Travis-CI-Nginx-for-Testing-Nginx-Configuration.git mitchellkrogza/Travis-CI-Nginx-for-Testing-Nginx-Configuration
6-
#git reset --hard $sha1
7-
#git checkout master
8-
#git config --global user.email "${GIT_EMAIL}"
9-
#git config --global user.name "${GIT_NAME}"
10-
#git config --global push.default simple
11-
#git status
12-
#git fetch origin master
13-
#git diff origin/master
14-
#git branch
15-
#git checkout $TRAVIS_BRANCH
16-
#git branch
17-
#sudo git remote add origin https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git
18-
#git fetch --tags
19-
#msg="Tag $GIT_TAG Generated from TravisCI for build $TRAVIS_BUILD_NUMBER"
20-
#if git tag $GIT_TAG -a -m "$msg" 2>/dev/null; then
21-
#sudo $TRAVIS_BUILD_DIR/travis-ci/modify-globalblacklist.sh
22-
#sudo chown travis:travis $TRAVIS_BUILD_DIR/globalblacklist.conf
23-
#git add $TRAVIS_BUILD_DIR/globalblacklist.conf
24-
#git add .
25-
#git add $TRAVIS_BUILD_DIR/build.txt
7+
8+
# Create our Version Number
269
export GIT_TAG=V3.$YEAR-$MONTH.$TRAVIS_BUILD_NUMBER
27-
#git tag detached-commit -f
10+
11+
# Tag our release
2812
git tag $GIT_TAG -a -m "V3.$YEAR.$MONTH.$TRAVIS_BUILD_NUMBER"
29-
#git commit -am "Update build version file $GIT_TAG with $TRAVIS_BUILD_NUMBER"
13+
14+
# Push our commit and tags back to the repo
3015
sudo git push origin master && git push origin master --tags
31-
#git push https://${GH_TOKEN}@github.com/mitchellkrogza/Travis-CI-Nginx-for-Testing-Nginx-Configuration --all
32-
ls -aR
33-
#cat $TRAVIS_BUILD_DIR/globalblacklist.conf
34-
#ls -la $TRAVIS_BUILD_DIR
35-
#git branch -a
36-
#echo $TRAVIS_BRANCH
37-
#else echo Tag already exists!; fi
3816

39-
#YEAR=$(date +"%Y")
40-
#MONTH=$(date +"%m")
41-
#sudo git remote add origin https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git
42-
#sudo git config --global user.email "${GIT_EMAIL}"
43-
#sudo git config --global user.name "${GIT_NAME}"
44-
#sudo git config --global push.default simple
45-
#export GIT_TAG=V2.$YEAR-$MONTH.$TRAVIS_BUILD_NUMBER
46-
#export GIT_TAG=v1.0.$TRAVIS_BUILD_NUMBER
47-
#git fetch --tags
48-
#msg="Build $GIT_TAG"
49-
#if git tag $GIT_TAG -a -m "$msg" 2>/dev/null; then
50-
#sudo git tag $GIT_TAG -a -m "Build $GIT_TAG"
51-
#sudo git push origin master && git push origin master --tags
17+
# Uncomment to list all git folders and modified files etc
5218
#ls -aR
53-
#else echo Tag already exists!; fi
5419

55-
#- git remote -v
56-
#- git remote add origin https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git
57-
#- git config --global user.email "builds@travis-ci.com"
58-
#- git config --global user.name "Travis CI"
59-
#- git config --global user.email "${GIT_EMAIL}"
60-
#- git config --global user.name "${GIT_NAME}"
61-
#- git config --global push.default simple
62-
#- export GIT_TAG=v1.0.$TRAVIS_BUILD_NUMBER
63-
#- sudo $TRAVIS_BUILD_DIR/travis-ci/modify-globalblacklist.sh
64-
#- cat $TRAVIS_BUILD_DIR/globalblacklist.conf
65-
#- git commit -am "Travis Test Passed"
66-
#- git commit -a
67-
#- cd $TRAVIS_BUILD_DIR
68-
#- git add $TRAVIS_BUILD_DIR/globalblacklist.conf
69-
#- git commit -m "Build $TRAVIS_BUILD_NUMBER"
70-
#- git commit -am "Build $TRAVIS_BUILD_NUMBER"
71-
#- git tag $GIT_TAG -a -m "Tag Generated from TravisCI for build $TRAVIS_BUILD_NUMBER"
72-
#- git push origin master && git push origin master --tags
73-
#- git pull origin https://${GH_TOKEN}@github.com/mitchellkrogza/Travis-CI-Nginx-for-Testing-Nginx-Configuration
74-
#- git push https://${GH_TOKEN}@github.com/mitchellkrogza/Travis-CI-Nginx-for-Testing-Nginx-Configuration --all
75-
#- ls -aR
20+
# Now TravisCI moves into the deploy: section of TravisCI - see .travis.yml

travis-ci/install-nginx2.sh

Lines changed: 37 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,109 +2,65 @@
22
# Travis CI Bash Script for Installing Nginx on Travis CI and Testing Configurations
33
# https://github.com/mitchellkrogza
44

5-
#set -e
65
set -x
7-
#set -v
8-
9-
#DIR=$(realpath $(dirname "$0"))
10-
#USER=$(whoami)
11-
#PHP_VERSION=$(phpenv version-name)
12-
#ROOT=$(realpath "$DIR/..")
13-
#PORT=9000
14-
#SERVER="/tmp/php.sock"
15-
16-
#function tpl {
17-
# sed \
18-
# -e "s|{DIR}|$DIR|g" \
19-
# -e "s|{USER}|$USER|g" \
20-
# -e "s|{PHP_VERSION}|$PHP_VERSION|g" \
21-
# -e "s|{ROOT}|$ROOT|g" \
22-
# -e "s|{PORT}|$PORT|g" \
23-
# -e "s|{SERVER}|$SERVER|g" \
24-
# < $1 > $2
25-
#}
26-
27-
# Make some working directories.
28-
#mkdir "$DIR/nginx"
29-
#mkdir "$DIR/nginx/sites-enabled"
30-
#mkdir "$DIR/var"
31-
32-
# Configure the PHP handler.
33-
#if [ "$PHP_VERSION" = 'hhvm' ] || [ "$PHP_VERSION" = 'hhvm-nightly' ]
34-
#then
35-
# HHVM_CONF="$DIR/nginx/hhvm.ini"
36-
37-
# tpl "$DIR/hhvm.tpl" "$HHVM_CONF"
38-
39-
# cat "$HHVM_CONF"
40-
41-
# hhvm \
42-
# --mode=daemon \
43-
# --config="$HHVM_CONF"
44-
#else
45-
# PHP_FPM_BIN="$HOME/.phpenv/versions/$PHP_VERSION/sbin/php-fpm"
46-
# PHP_FPM_CONF="$DIR/nginx/php-fpm.conf"
47-
48-
# Build the php-fpm.conf.
49-
# tpl "$DIR/php-fpm.tpl" "$PHP_FPM_CONF"
50-
51-
# Start php-fpm
52-
# "$PHP_FPM_BIN" --fpm-config "$PHP_FPM_CONF"
53-
#fi
54-
55-
# Build the default nginx config files.
56-
#tpl "$DIR/nginx.tpl" "$DIR/nginx/nginx.conf"
57-
#tpl "$DIR/fastcgi.tpl" "$DIR/nginx/fastcgi.conf"
58-
#tpl "$DIR/defaultsite.tpl" "$DIR/nginx/sites-enabled/defaultsite.conf"
59-
60-
# Start nginx.
61-
#nginx -c "$DIR/nginx/nginx.conf"
62-
#echo $TRAVIS_BUILD_DIR
63-
# Check Date
64-
date
6+
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
6514
sudo rm /etc/nginx/sites-available/default
15+
16+
# Download the Nginx Bad Bot Blocker files from the Live Repository
6617
sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/install-ngxblocker -O /usr/sbin/install-ngxblocker
6718
sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/setup-ngxblocker -O /usr/sbin/setup-ngxblocker
6819
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
6922
sudo chmod +x /usr/sbin/install-ngxblocker
7023
sudo chmod +x /usr/sbin/setup-ngxblocker
7124
sudo chmod +x /usr/sbin/update-ngxblocker
25+
26+
# Run Install-NgxBlocker
7227
cd /usr/sbin
7328
sudo ./install-ngxblocker -x
29+
30+
# Copy our default.vhost file into Nginx /sites-available/
7431
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
7534
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
7638
cd /usr/sbin
77-
# Below for Verbose Testing of setup-ngxblocker
78-
#sudo sh -x ./setup-ngxblocker -x
7939
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
8046
sudo nginx -c /etc/nginx/nginx.conf
8147
sudo service nginx reload
82-
#sudo nginx -t &> /dev/stdout
83-
#cat /etc/nginx/nginx.conf
84-
#sudo nginx -V
85-
#sudo netstat -peanut
48+
49+
# Copy our index.php file into the default site's root folder
8650
sudo cp $TRAVIS_BUILD_DIR/www/index.php /var/www/html/index.php
51+
52+
# Run update-ngxblocker test
8753
cd /usr/sbin
8854
sudo ./update-ngxblocker
55+
56+
# Reload nginx
8957
sudo service nginx reload
58+
59+
# Set all our other setup and deploy scripts to be executable
9060
sudo chmod +x $TRAVIS_BUILD_DIR/travis-ci/modify-globalblacklist.sh
9161
sudo chmod +x $TRAVIS_BUILD_DIR/travis-ci/deploy.sh
9262
sudo chmod +x $TRAVIS_BUILD_DIR/travis-ci/before-deploy.sh
9363
sudo chmod +x $TRAVIS_BUILD_DIR/travis-ci/deploy2.sh
9464
sudo chmod +x $TRAVIS_BUILD_DIR/travis-ci/changefile.sh
95-
#sudo $TRAVIS_BUILD_DIR/travis-ci/modify-globalblacklist.sh
96-
#cd $TRAVIS_BUILD_DIR
97-
#sudo git remote -v
98-
#sudo git remote rm origin
99-
#cat $TRAVIS_BUILD_DIR/globalblacklist.conf
100-
#sudo git config --global user.email "${GIT_EMAIL}"
101-
#sudo git config --global user.name "${GIT_NAME}"
102-
#sudo git config --global push.default simple
103-
#sudo export GIT_TAG=v1.0.$TRAVIS_BUILD_NUMBER
104-
#msg="Build $TRAVIS_BUILD_NUMBER"
105-
#echo "$msg" >> $TRAVIS_BUILD_DIR/build.txt
106-
#sudo git add $TRAVIS_BUILD_DIR/globalblacklist.conf
107-
#sudo git commit -m "Build $TRAVIS_BUILD_NUMBER"
108-
109-
#sudo sed --version
110-
#sudo apt-cache policy dash
65+
66+
# Travis now goes into the rest of the tests in the script: section of .travis.yml

0 commit comments

Comments
 (0)