From 8fa23d88efded4261575884061188b0e25bba3d1 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Tue, 21 May 2019 04:01:04 -0600 Subject: [PATCH] handle provided f2b config dir, check dir --- f2b-config.sh | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/f2b-config.sh b/f2b-config.sh index 5cb2a92..3ea49e8 100755 --- a/f2b-config.sh +++ b/f2b-config.sh @@ -55,8 +55,46 @@ fi ### default values for variables -F2B_DIR="$1" -echo "(testing: base-dir is: ${F2B_DIR})" +F2B_DIR="/etc/fail2ban" + + +### handle provided fail2ban configuration directory provided by user +if [ "$1" ]; then + # test if provided path actually exists + if [ ! -d "$1" ]; then + echo + echo -e "${err}Could not find the specified fail2ban configuration" \ + "directory." + echo -e "${lit}($1)" + echo -e "${err}Perhaps you mistyped it? Exiting.${normal}" + echo + exit 3 + elif [ ! -f "$1/fail2ban.conf" ]; then + echo + echo -e "${err}The specified fail2ban configuration directory does" \ + "not seem to contain" + echo -e "fail2ban configuration files. Perhaps you provided the" \ + "wrong directory?" + echo -e "${lit}($1)" + echo -e "${err}Exiting.${normal}" + echo + exit 4 + else + F2B_DIR="${1%/}" + fi +fi + + +### last check: is the directory writable +if [ ! -w "${F2B_DIR}" ]; then + echo + echo -e "${err}The specified fail2ban configuration directory is not" \ + "writable." + echo -e "${lit}(${F2B_DIR})" + echo -e "${err}Exiting.${normal}" + echo + exit 5 +fi ### user info preamble @@ -136,6 +174,8 @@ exit 0 # installed # 2: script not run as ROOT (needed to avoid any permissions issues) # 3: invalid fail2ban configuration directory provided by user +# 4: provided fail2ban configuration directory is missing fail2ban.conf +# 5: fail2ban configuration directory is not writable # 99: internal testing error code, should *not* appear in releases # 100: error copying files to fail2ban configuration directory and/or making # simultaneous backup copies of any exisitng files.