mirror of
https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker.git
synced 2025-09-02 10:40:36 +00:00
UPDATE Install Nginx 1 [MASTER]
This commit is contained in:
parent
4c75649c77
commit
c2ca4b1421
1 changed files with 103 additions and 161 deletions
|
@ -16,21 +16,22 @@
|
|||
# #
|
||||
##############################################################################
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# MIT License
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2017 Mitchell Krog - mitchellkrog@gmail.com
|
||||
# https://github.com/mitchellkrogza
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -38,10 +39,11 @@
|
|||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# ************************
|
||||
# ------------------------
|
||||
# Set Terminal Font Colors
|
||||
# ************************
|
||||
# ------------------------
|
||||
|
||||
bold=$(tput bold)
|
||||
red=$(tput setaf 1)
|
||||
|
@ -53,32 +55,36 @@ cyan=$(tput setaf 6)
|
|||
white=$(tput setaf 7)
|
||||
defaultcolor=$(tput setaf default)
|
||||
|
||||
# ***************************************************************
|
||||
# Start Getting Nginx Ready for Testing the Nginx Bad Bot Blocker
|
||||
# ***************************************************************
|
||||
# ---------
|
||||
# FUNCTIONS
|
||||
# ---------
|
||||
|
||||
printf "\n"
|
||||
echo "${bold}${green}------------------"
|
||||
echo "${bold}${green}Start Nginx Test 1"
|
||||
echo "${bold}${green}------------------"
|
||||
printf "\n"
|
||||
reloadNginX () {
|
||||
echo "${bold}${green}---------------"
|
||||
echo "${bold}${green}Reloading Nginx"
|
||||
echo "${bold}${green}---------------"
|
||||
printf "\n\n"
|
||||
sudo nginx -t && sudo nginx -s reload
|
||||
}
|
||||
|
||||
# ******************************************************
|
||||
# Make a backup of the clean and default nginx.conf file
|
||||
# Needed to run Nginx test 3
|
||||
# ******************************************************
|
||||
waitforReload () {
|
||||
echo "${bold}${yellow}-----------------------------------------------------------------------"
|
||||
echo "${bold}${yellow}Sleeping for 10 seconds to allow Nginx to Properly Reload inside Travis"
|
||||
echo "${bold}${yellow}-----------------------------------------------------------------------"
|
||||
printf "\n\n"
|
||||
sleep 10s
|
||||
}
|
||||
|
||||
backupNginxConf () {
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}---------------------------"
|
||||
echo "${bold}${yellow}Making backup of nginx.conf"
|
||||
echo "${bold}${yellow}---------------------------"
|
||||
printf "\n"
|
||||
sudo cp /etc/nginx/nginx.conf ${TRAVIS_BUILD_DIR}/.dev-tools/_nginx_conf_backup/nginx.conf
|
||||
}
|
||||
|
||||
# *************************************************
|
||||
# Delete default site created by Nginx Installation
|
||||
# *************************************************
|
||||
|
||||
prepareVhost () {
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}-------------------------------------------"
|
||||
echo "${bold}${yellow}Delete any default files installed by Nginx"
|
||||
|
@ -87,47 +93,33 @@ printf "\n"
|
|||
sudo rm /etc/nginx/sites-available/default
|
||||
sudo rm /etc/nginx/sites-enabled/default
|
||||
sudo rm /var/www/html/*
|
||||
|
||||
# ********************************************************
|
||||
# Copy our default.vhost file into Nginx /sites-available/
|
||||
# ********************************************************
|
||||
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}---------------------"
|
||||
echo "${bold}${yellow}Setup Vhost for Nginx"
|
||||
echo "${bold}${yellow}---------------------"
|
||||
printf "\n"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/default.vhost /etc/nginx/sites-available/default.vhost
|
||||
|
||||
# **********************************************
|
||||
# Link the vhost file into Nginx /sites-enabled/
|
||||
# **********************************************
|
||||
|
||||
sudo ln -s /etc/nginx/sites-available/default.vhost /etc/nginx/sites-enabled/default.vhost
|
||||
|
||||
# ***********************************************************
|
||||
# Copy our index.php file into the default site's root folder
|
||||
# ***********************************************************
|
||||
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/index.html /var/www/html/index.html
|
||||
}
|
||||
|
||||
# ***********************************************
|
||||
# Fetch our install-ngxblocker file from the repo
|
||||
# ***********************************************
|
||||
makeScriptsExecutable () {
|
||||
sudo chmod +x /usr/sbin/install-ngxblocker
|
||||
sudo chmod +x /usr/sbin/setup-ngxblocker
|
||||
sudo chmod +x /usr/sbin/update-ngxblocker
|
||||
}
|
||||
|
||||
getinstallngxblocker () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}--------------------------------------"
|
||||
echo "${bold}${magenta}Fetch install-ngxblocker from the repo"
|
||||
echo "${bold}${magenta}--------------------------------------"
|
||||
printf "\n"
|
||||
|
||||
sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/install-ngxblocker -O /usr/sbin/install-ngxblocker
|
||||
sudo chmod +x /usr/sbin/install-ngxblocker
|
||||
}
|
||||
|
||||
# **********************
|
||||
# Run Install-NgxBlocker
|
||||
# **********************
|
||||
|
||||
runinstallngxblocker () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}--------------------------"
|
||||
echo "${bold}${magenta}Execute install-ngxblocker"
|
||||
|
@ -135,19 +127,9 @@ echo "${bold}${magenta}--------------------------"
|
|||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./install-ngxblocker -s /usr/sbin/ -x
|
||||
}
|
||||
|
||||
# **************************************************
|
||||
# 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
|
||||
|
||||
# ********************
|
||||
# Run setup-ngxblocker
|
||||
# ********************
|
||||
|
||||
runsetupngxblocker1 () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
echo "${bold}${magenta}Execute setup-ngxblocker"
|
||||
|
@ -155,51 +137,32 @@ echo "${bold}${magenta}------------------------"
|
|||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./setup-ngxblocker -i /usr/sbin/install-ngxblocker -x
|
||||
}
|
||||
|
||||
# ************************
|
||||
# Load our Nginx.conf file
|
||||
# ************************
|
||||
runsetupngxblocker2 () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
echo "${bold}${magenta}Execute setup-ngxblocker"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./setup-ngxblocker -x
|
||||
}
|
||||
|
||||
loadNginxConf () {
|
||||
sudo nginx -c /etc/nginx/nginx.conf
|
||||
}
|
||||
|
||||
# ****************************************************************************************
|
||||
# Copy a dummy version of globalblacklist.conf with an older version number to test update
|
||||
# ****************************************************************************************
|
||||
|
||||
forceUpdateTest1 () {
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}----------------------------------------------------"
|
||||
echo "${bold}${yellow}Copy older globalblacklist.conf file to force update"
|
||||
echo "${bold}${yellow}----------------------------------------------------"
|
||||
printf "\n"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/globalblacklist-dummy.conf /etc/nginx/conf.d/globalblacklist.conf
|
||||
}
|
||||
|
||||
# ****************************************************************************************
|
||||
# Run update-ngxblocker test which downloads latest globalblacklist.conf and reloads Nginx
|
||||
# ****************************************************************************************
|
||||
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
echo "${bold}${magenta}Execute update-ngxblocker"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./update-ngxblocker -n
|
||||
|
||||
# *********************
|
||||
# Force reload of Nginx
|
||||
# *********************
|
||||
|
||||
printf "\n"
|
||||
echo "${bold}${green}------------"
|
||||
echo "${bold}${green}Reload Nginx"
|
||||
echo "${bold}${green}------------"
|
||||
printf "\n"
|
||||
sudo nginx -t && sudo nginx -s reload
|
||||
|
||||
# *******************************************************************************************
|
||||
# Test that update-ngxblocker can install all missing required files by deleting some of them
|
||||
# *******************************************************************************************
|
||||
|
||||
forceUpdateTest2 () {
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}--------------------------------------"
|
||||
echo "${bold}${yellow}Delete Files to test update-ngxblocker"
|
||||
|
@ -209,34 +172,18 @@ sudo rm /etc/nginx/conf.d/*.conf
|
|||
sudo rm /etc/nginx/bots.d/*.conf
|
||||
ls -la /etc/nginx/conf.d/
|
||||
ls -la /etc/nginx/bots.d/
|
||||
}
|
||||
|
||||
# *********************************************************************************************************
|
||||
# Run update-ngxblocker to test for missing files and download latest globalblacklist.conf and reload Nginx
|
||||
# *********************************************************************************************************
|
||||
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
echo "${bold}${magenta}Execute update-ngxblocker"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./update-ngxblocker -n
|
||||
|
||||
# ****************************************************************************************
|
||||
# Copy a dummy version of globalblacklist.conf with an older version number to test update
|
||||
# ****************************************************************************************
|
||||
|
||||
forceUpdateTest3 () {
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}----------------------------------------------------"
|
||||
echo "${bold}${yellow}Copy older globalblacklist.conf file to force update"
|
||||
echo "${bold}${yellow}----------------------------------------------------"
|
||||
printf "\n"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/globalblacklist-dummy.conf /etc/nginx/conf.d/globalblacklist.conf
|
||||
}
|
||||
|
||||
# *********************************************************************************************************
|
||||
# Run update-ngxblocker to test for missing files and download latest globalblacklist.conf and reload Nginx
|
||||
# *********************************************************************************************************
|
||||
|
||||
runupdatengxblocker () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
echo "${bold}${magenta}Execute update-ngxblocker"
|
||||
|
@ -244,56 +191,18 @@ echo "${bold}${magenta}-------------------------"
|
|||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./update-ngxblocker -n
|
||||
}
|
||||
|
||||
# **************************
|
||||
# Run setup-ngxblocker again
|
||||
# **************************
|
||||
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
echo "${bold}${magenta}Execute setup-ngxblocker"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./setup-ngxblocker -x
|
||||
|
||||
# *********************
|
||||
# Force reload of Nginx
|
||||
# *********************
|
||||
|
||||
printf "\n"
|
||||
echo "${bold}${green}------------"
|
||||
echo "${bold}${green}Reload Nginx"
|
||||
echo "${bold}${green}------------"
|
||||
printf "\n"
|
||||
sudo nginx -t && sudo nginx -s reload
|
||||
|
||||
# *******************************************************
|
||||
# Make sure we test latest generated globalblacklist.conf
|
||||
# *******************************************************
|
||||
|
||||
activateLatestBlacklist () {
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}------------------------------------------------------------"
|
||||
echo "${bold}${yellow}Make sure we test with latest generated globalblacklist.conf"
|
||||
echo "${bold}${yellow}------------------------------------------------------------"
|
||||
printf "\n"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/conf.d/globalblacklist.conf /etc/nginx/conf.d/globalblacklist.conf
|
||||
}
|
||||
|
||||
# *********************
|
||||
# Force reload of Nginx
|
||||
# *********************
|
||||
|
||||
printf "\n"
|
||||
echo "${bold}${green}------------"
|
||||
echo "${bold}${green}Reload Nginx"
|
||||
echo "${bold}${green}------------"
|
||||
printf "\n"
|
||||
sudo nginx -t && sudo nginx -s reload
|
||||
|
||||
# ************************************************************
|
||||
# Copy all .conf files used in Test 1 to a folder for checking
|
||||
# ************************************************************
|
||||
|
||||
backupConfFiles () {
|
||||
printf "\n"
|
||||
echo "${bold}${green}------------------------------------------------------------"
|
||||
echo "${bold}${green}Make Backup all conf files and folders used during this test"
|
||||
|
@ -303,29 +212,61 @@ sudo cp /etc/nginx/bots.d/* ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test1/bot
|
|||
sudo cp /etc/nginx/conf.d/* ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test1/conf.d/
|
||||
sudo cp /etc/nginx/sites-available/default.vhost ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test1/default.vhost
|
||||
sudo cp /etc/nginx/nginx.conf ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test1/nginx.conf
|
||||
}
|
||||
|
||||
# **********************
|
||||
# ------------------
|
||||
# Start Installation
|
||||
# ------------------
|
||||
|
||||
printf "\n"
|
||||
echo "${bold}${green}------------------"
|
||||
echo "${bold}${green}Start Nginx Test 1"
|
||||
echo "${bold}${green}------------------"
|
||||
printf "\n"
|
||||
|
||||
backupNginxConf
|
||||
prepareVhost
|
||||
getinstallngxblocker
|
||||
runinstallngxblocker
|
||||
makeScriptsExecutable
|
||||
runsetupngxblocker1
|
||||
loadNginxConf
|
||||
forceUpdateTest1
|
||||
runupdatengxblocker
|
||||
reloadNginX
|
||||
waitforReload
|
||||
forceUpdateTest2
|
||||
runupdatengxblocker
|
||||
forceUpdateTest3
|
||||
runsetupngxblocker2
|
||||
reloadNginX
|
||||
waitforReload
|
||||
activateLatestBlacklist
|
||||
reloadNginX
|
||||
|
||||
|
||||
# ----------------------
|
||||
# Exit With Error Number
|
||||
# **********************
|
||||
# ----------------------
|
||||
|
||||
exit ${?}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# MIT License
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2017 Mitchell Krog - mitchellkrog@gmail.com
|
||||
# https://github.com/mitchellkrogza
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -333,3 +274,4 @@ exit ${?}
|
|||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Reference in a new issue