From a2f70b4facb1b018292b810f73f023f70dd19340 Mon Sep 17 00:00:00 2001 From: borekon Date: Tue, 19 Oct 2021 12:04:02 +0200 Subject: [PATCH] modif --- awk | 3 +++ blocklist.sh | 26 ++++++++++++++----------- blocklist-update.sh => old-blocklist.sh | 0 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 awk mode change 100644 => 100755 blocklist.sh rename blocklist-update.sh => old-blocklist.sh (100%) diff --git a/awk b/awk new file mode 100644 index 0000000..aac1f4f --- /dev/null +++ b/awk @@ -0,0 +1,3 @@ +iptables: /usr/sbin/iptables /sbin/iptables /usr/share/iptables /usr/share/man/man8/iptables.8.gz +{print: +}: diff --git a/blocklist.sh b/blocklist.sh old mode 100644 new mode 100755 index 6f93375..677a8f5 --- a/blocklist.sh +++ b/blocklist.sh @@ -1,19 +1,23 @@ #!/bin/bash - -IPTABLES_PATH="/sbin/iptables" -IPSET_PATH="/sbin/ipset" -SORT_PATH="/usr/bin/sort" -GREP_PATH="/bin/grep" +if [ "$(whoami)" == "root" ]; then echo "root ok"; else echo "run as root!"; exit 1; fi; +#IPTABLES_PATH=$(whereis iptables | awk '{print $2}') +#IPSET_PATH=$(whereis ipset | awk '{print $2}') +#SORT_PATH=$(whereis sort | awk '{print $2}') +#GREP_PATH=$(whereis grep | awk '{print $2}') BLOCKLISTDE="https://lists.blocklist.de/lists/all.txt" CRWALERS="https://isc.sans.edu/api/threatcategory/research?json" -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 $GREP_PATH ]; then echo "Cannot find [ grep ]. Is it installed? Exiting"; exit 1; fi; +#if [ -f $IPTABLES_PATH ]; then echo "iptables OK"; else echo "Cannot find [ iptables ]. Is it installed? Exiting"; exit 1; fi; +if ! command -v iptables >/dev/null; then echo "I require iptables but it's not installed."; apt install -y iptables; else echo "iptables OK"; fi; +#if [ -f $IPSET_PATH ]; then echo "ipset OK"; else echo "Cannot find [ ipset ]. Is it installed? Exiting"; exit 1; fi; +if ! command -v ipset >/dev/null; then echo "I require ipset but it's not installed."; apt install -y ipset; else echo "iptables OK"; fi; +#if [ -f $SORT_PATH ]; then echo "sort OK"; else echo "Cannot find [ sort ]. Is it installed? Exiting"; exit 1; fi; +if ! command -v sort >/dev/null; then echo "I require sort but it's not installed."; else echo "sort OK"; fi; +#if [ -x $JQ_PATH ]; then echo "jq OK"; else echo "jq not installed, installing"; apt install -y jq; fi; +if ! command -v jq >/dev/null; then echo "I require jq but it's not installed."; apt install -y jq; fi; +#if [ ! -f $GREP_PATH ]; then echo "Cannot find [ grep ]. Is it installed? Exiting"; exit 1; fi; +if ! command -v grep >/dev/null; then echo "I require grep but it's not installed."; apt install -y grep; else echo "grep OK"; fi; echo "Downloading the most recent IP list from $BLOCKLISTDE ... and adding them to ipset blocklistde" ipset create blocklistde hash:ip diff --git a/blocklist-update.sh b/old-blocklist.sh similarity index 100% rename from blocklist-update.sh rename to old-blocklist.sh