Suppress output of `popd` and implement the help text.

This commit is contained in:
Manuel Friedli 2020-07-23 21:12:48 +02:00
parent 9a929d440c
commit 9b82a8944d
1 changed files with 35 additions and 11 deletions

View File

@ -47,8 +47,42 @@ blue="\033[38;2;0;85;255m"
bold="\033[1m"
reset="\033[0m"
# Clean up when the script exits.
trap 'sudo -k; popd >/dev/null; rm -r ${tmpdir}' EXIT
# Create a temp directory, chdir into it and create the (initially empty)
# banlist file.
tmpdir=$(mktemp -d)
# Suppress output of dir stack.
pushd "${tmpdir}" > /dev/null
touch "${banlist}"
function printHelp() {
echo "Help ... to be written."
cat <<ENDOFHELP
Usage: $(basename $0) [OPTION...]
-a, --auto[=LIMIT] Enable the autopilot for automatically banning chinese IP
addresses (whois output must contain "source: APNIC" and
"country: CN").
When LIMIT is given, only auto-ban IP addresses with at
least LIMIT current connections.
When LIMIT is omitted, assume LIMIT=1.
-n, --netmask=SIZE SIZE defines the subnet size in bytes to be analyzed.
Valid values are:
- 1 or 8 for class A networks (X.0.0.0/8)
- 2 or 16 for class B networks (X.X.0.0/16)
- 3 or 24 for class C networks (X.X.X.0/24)
- 4 or 32 for class D networks (X.X.X.X/32)
-h, --help Show this help message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
When invoked without options, the autopilot is disabled and the netmask SIZE is
inquired interactively.
ENDOFHELP
}
function parseCommandline() {
@ -117,16 +151,6 @@ function parseCommandline() {
done
}
# Clean up when the script exits.
trap 'sudo -k; popd; rm -r ${tmpdir}' EXIT
# Create a temp directory, chdir into it and create the (initially empty)
# banlist file.
tmpdir=$(mktemp -d)
# Suppress output of dir stack.
pushd "${tmpdir}" > /dev/null
touch "${banlist}"
# Parse the command line options
autopilot=0
netmask=0