diff --git a/blocklist-update.sh b/blocklist-update.sh index fe5e59e..824f5f9 100755 --- a/blocklist-update.sh +++ b/blocklist-update.sh @@ -11,20 +11,21 @@ IPSET_PATH="/sbin/ipset" SORT_PATH="/usr/bin/sort" MAIL_PATH="/usr/bin/mail" GREP_PATH="/bin/grep" +MAIL=1 if [ -f $IPTABLES_PATH ]; then echo "iptables OK"; else echo "Cannot find [ iptables ]. Is it installed? Exiting"; exit 1; fi; #hash iptables 2>/dev/null || { echo >&2 "I require iptables but it's not installed. Aborting."; exit 1; } #more in https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script if [ -f $IPSET_PATH ]; then echo "ipset OK"; else echo "Cannot find [ ipset ]. Is it installed? Exiting"; exit 1; fi; if [ -f $SORT_PATH ]; then echo "sort OK"; else echo "Cannot find [ sort ]. Is it installed? Exiting"; exit 1; fi; -if [ -f $MAIL_PATH ]; then echo "mail OK"; else echo "Cannot find [ mail ]. Is it installed? Try apt install bsd-mailx. Exiting"; exit 1; fi; +if [ -f $MAIL_PATH ]; then echo "mail OK"; else echo "Cannot find [ mail ]. Is it installed? No mail report will be sent"; MAIL=0; fi; if [ ! -f $GREP_PATH ]; then echo "Cannot find [ grep ]. Is it installed? Exiting"; exit 1; fi; # E-Mail variables MAILLOG="/var/log/blocklist-update.log" MAIL_SENDER=$(whoami) #this defines a system-user without a shell or password. It's used as the e-mail sender name. You can create one like this: useradd -M -N -s /usr/sbin/nologin myuser && passwd -d myuser MAIL_SUBJECT="ERROR - IP blocklist script failed to download the IP set" -read -t 15 -p "Insert a mail to send the log. Separate with space to send to multiple recipients: " MAIL_RECIPIENTS +if [ $MAIL" == 1 ]; then read -t 15 -p "Insert a mail to send the log. Separate with space to send to multiple recipients: " MAIL_RECIPIENTS; fi; if [ ! "$MAIL_RECIPIENTS" ]; then MAIL_RECIPIENTS="$(whoami)@$HOSTNAME"; else echo "Address: " $MAIL_RECIPIENTS; fi; BLOCKLIST_FILE="/tmp/ip-blocklist.txt" @@ -116,4 +117,4 @@ for i in $( cat $BLOCKLIST_FILE ); do $IPSET_PATH add $CHAINNAME $i >>$MAILLOG 2 echo "" >>$MAILLOG echo "Done." >>$MAILLOG -sudo -u $MAIL_SENDER $MAIL_PATH -s "SUCCESS - IP blocklist script has updated the IP set with the newest IP list" $MAIL_RECIPIENTS < $MAILLOG +if [ "$MAIL" == 1 ]; then sudo -u $MAIL_SENDER $MAIL_PATH -s "SUCCESS - IP blocklist script has updated the IP set with the newest IP list" $MAIL_RECIPIENTS < $MAILLOG; fi;