Merge pull request #135 from itoffshore/alpine

* fix service command for cron jobs
* install to /usr/local/sbin by default
This commit is contained in:
Stuart Cardall 2018-02-08 10:12:33 +00:00 committed by GitHub
commit baa6b3cb4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 20 deletions

View file

@ -23,18 +23,18 @@
### You can also now use a setup script contributed by Stuart Cardall to automatically insert the includes for you ### You can also now use a setup script contributed by Stuart Cardall to automatically insert the includes for you
### See - https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/setup-ngxblocker ### See - https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/setup-ngxblocker
# Save this file as /usr/sbin/install-ngxblocker # Save this file as /usr/local/sbin/install-ngxblocker
# 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/install-ngxblocker -O /usr/local/sbin/install-ngxblocker
# Make it Executable: # Make it Executable:
# chmod 700 /usr/sbin/install-ngxblocker # chmod 700 /usr/local/sbin/install-ngxblocker
# Run it from the command line: # Run it from the command line:
# sudo /usr/sbin/install-ngxblocker [ -h ] # sudo /usr/local/sbin/install-ngxblocker [ -h ]
######## LETS INSTALL NOW ############################### ######## LETS INSTALL NOW ###############################
CONF_DIR=/etc/nginx/conf.d CONF_DIR=/etc/nginx/conf.d
BOTS_DIR=/etc/nginx/bots.d BOTS_DIR=/etc/nginx/bots.d
SCRIPT_DIR=/usr/sbin SCRIPT_DIR=/usr/local/sbin
REPO=https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master REPO=https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master
####### end user configuration ########################## ####### end user configuration ##########################

View file

@ -12,7 +12,7 @@ VHOST_DIR=/etc/nginx/sites-available
BOTS_DIR=/etc/nginx/bots.d BOTS_DIR=/etc/nginx/bots.d
CONF_DIR=/etc/nginx/conf.d CONF_DIR=/etc/nginx/conf.d
MAIN_CONF=/etc/nginx/nginx.conf MAIN_CONF=/etc/nginx/nginx.conf
INSTALLER=/usr/sbin/install-ngxblocker INSTALLER=/usr/local/sbin/install-ngxblocker
# setting Y / yes will whitelist only directories in $www # setting Y / yes will whitelist only directories in $www
# that look like domain.names # that look like domain.names
DOT_NAMES="Y" DOT_NAMES="Y"

View file

@ -20,10 +20,10 @@
# PLEASE READ UPDATED CONFIGURATION INSTRUCTIONS BEFORE USING THIS # PLEASE READ UPDATED CONFIGURATION INSTRUCTIONS BEFORE USING THIS
# Save this file as /usr/sbin/update-ngxblocker # Save this file as /usr/local/sbin/update-ngxblocker
# cd /usr/sbin # cd /usr/local/sbin
# sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/update-ngxblocker -O update-ngxblocker # sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/update-ngxblocker -O update-ngxblocker
# Make it Executable chmod 700 /usr/sbin/update-ngxblocker # Make it Executable chmod 700 /usr/local/sbin/update-ngxblocker
# RUN THE UPDATE # RUN THE UPDATE
# Here our script runs, pulls the latest update, reloads nginx and emails you a notification # Here our script runs, pulls the latest update, reloads nginx and emails you a notification
@ -32,7 +32,7 @@ EMAIL="me@myemail.com"
SEND_EMAIL="N" SEND_EMAIL="N"
CONF_DIR=/etc/nginx/conf.d CONF_DIR=/etc/nginx/conf.d
BOTS_DIR=/etc/nginx/bots.d BOTS_DIR=/etc/nginx/bots.d
INSTALLER=/usr/sbin/install-ngxblocker INSTALLER=/usr/local/sbin/install-ngxblocker
##### end user configuration ############################################################## ##### end user configuration ##############################################################
@ -140,15 +140,24 @@ update_paths() {
service_cmd() { service_cmd() {
# arch linux does not have a 'service' command # arch linux does not have a 'service' command
local svc= svc_list="service systemctl rc-service" local x= svc= svc_list="service systemctl rc-service"
for svc in $svc_list; do for x in $svc_list; do
svc=$(which $svc 2>/dev/null) svc=$(which $svc 2>/dev/null)
if [ -n "$svc" ]; then if [ -n "$svc" ]; then
echo $svc case "$x" in
exit 0 service) svc="$svc nginx reload";;
systemctl) svc="$svc reload nginx.service";;
rc-service) svc="$svc nginx reload";;
esac
break
else
# centos does not have 'which' by default
svc="/usr/sbin/service nginx reload"
fi fi
done done
echo $svc
} }
sanitize_path() { sanitize_path() {
@ -259,8 +268,7 @@ get_options() {
main() { main() {
local REPO=https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master local REPO=https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master
local file=globalblacklist.conf remote_dir=conf.d url= output= update= status= tmp= retval= local file=globalblacklist.conf remote_dir=conf.d url= output= update= status= tmp= retval=
# default to service (centos does not have 'which' by default) local reload_service=$(service_cmd)
local service=${service_cmd:-"service"}
# require root # require root
if [ "$(id -u)" != "0" ]; then if [ "$(id -u)" != "0" ]; then
@ -307,7 +315,7 @@ main() {
# re-read nginx configuration # re-read nginx configuration
if [ $retval = 0 ]; then if [ $retval = 0 ]; then
$service nginx reload 2>&1 >/dev/null $reload_service 2>&1 >/dev/null
if [ $? = 0 ]; then if [ $? = 0 ]; then
status="${BOLDGREEN}[OK]${RESET}" status="${BOLDGREEN}[OK]${RESET}"
print_message "\nReloading NGINX configuration...$status\n" print_message "\nReloading NGINX configuration...$status\n"
@ -351,13 +359,13 @@ exit $?
# Add this as a cron to run daily / weekly as you like # Add this as a cron to run daily / weekly as you like
# Here's a sample CRON entry to update every day at 10pm # Here's a sample CRON entry to update every day at 10pm
# 00 22 * * * sudo /usr/sbin/update-ngxblocker -q # 00 22 * * * sudo /usr/local/sbin/update-ngxblocker -q
# Here's another example to run it daily at midday using a command line switch to set the email address for the notification # Here's another example to run it daily at midday using a command line switch to set the email address for the notification
# 00 12 * * * sudo /usr/sbin/update-ngxblocker -e yourname@youremailprovider.com # 00 12 * * * sudo /usr/local/sbin/update-ngxblocker -e yourname@youremailprovider.com
# Less verbose logging to a system alias mail address (root crontab) # Less verbose logging to a system alias mail address (root crontab)
# 00 12 * * * /usr/sbin/update-ngxblocker -q -m webmaster # 00 12 * * * /usr/local/sbin/update-ngxblocker -q -m webmaster
# better logging for cron jobs: # better logging for cron jobs:
# https://serverfault.com/questions/137468/better-logging-for-cronjobs-send-cron-output-to-syslog # https://serverfault.com/questions/137468/better-logging-for-cronjobs-send-cron-output-to-syslog