Compare commits

...

5 Commits

Author SHA1 Message Date
Asif Bacchus 73fff32758 added error code summary for reference 2019-05-21 03:29:22 -06:00
Asif Bacchus 00bf9379db fixed copyFailure notification text 2019-05-21 03:25:33 -06:00
Asif Bacchus 64644c5996 fix cp error check syntax 2019-05-21 03:23:53 -06:00
Asif Bacchus 67d75486e3 fixed dash line formatting 2019-05-21 03:21:16 -06:00
Asif Bacchus 16734d44f7 fix func name typo 2019-05-21 03:16:52 -06:00
1 changed files with 26 additions and 19 deletions

View File

@ -17,9 +17,10 @@ note="\e[95m"
### functions
function copyFailureure {
function copyFailure {
echo
echo -e "${err}There was a problem backing up your current configuration."
echo -e "${err}There was a problem backing-up/copying the configuration" \
"files."
echo -e "This suggests some kind of permissions error. Please remedy this" \
"and rerun"
echo -e "this script."
@ -60,8 +61,7 @@ echo "(testing: base-dir is: ${F2B_DIR})"
### user info preamble
echo
echo -e "${note}------------------------------------------------------------" \
"--------------------${normal}"
echo -e "${note}--------------------------------------------------------------------------------${normal}"
echo -e "${info}This script will copy customized configuration files to your" \
"fail2ban"
echo -e "configuration directory. It will backup any existing files with the" \
@ -73,37 +73,36 @@ echo -e "${info}Please ensure you have reviewed the ${note}README${info} in" \
echo -e "associated wiki or the blog post at${note}" \
"https://mytechiethoughts.com${info} to understand"
echo -e "how to customize these template files.${normal}"
echo -e "${note}------------------------------------------------------------" \
"--------------------${normal}"
echo -e "${note}--------------------------------------------------------------------------------${normal}"
echo
### copy template files
# note: prefixing cp with '\' to override any alias settings
# copy .local files
if [ "$(\cp --force --backup=simple --suffix=.original \
etc/fail2ban/*.local "${F2B_DIR}/")" -ne 0 ]; then
if [ ! "$(\cp --force --backup=simple --suffix=.original \
etc/fail2ban/*.local "${F2B_DIR}/")" ]; then
copyFailure 'general config files (.local)'
fi
echo -e "${info}Copy general configuration files${normal} -- ${ok}[OK]${normal}"
# copy action configuration files
if [ "$(\cp --force --backup=simple --suffix=.original \
etc/fail2ban/action.d/* "${F2B_DIR}/action.d/")" -ne 0 ]; then
if [ ! "$(\cp --force --backup=simple --suffix=.original \
etc/fail2ban/action.d/* "${F2B_DIR}/action.d/")" ]; then
copyFailure 'action files'
fi
echo -e "${info}Copy action configuration files${normal} -- ${ok}[OK]${normal}"
# copy filter configuration files
if [ "$(\cp --force --backup=simple --suffix=.original \
etc/fail2ban/filter.d/* "${F2B_DIR}/filter.d/")" -ne 0 ]; then
if [ ! "$(\cp --force --backup=simple --suffix=.original \
etc/fail2ban/filter.d/* "${F2B_DIR}/filter.d/")" ]; then
copyFailure 'filter files'
fi
echo -e "${info}Copy filter configuration files${normal} -- ${ok}[OK]${normal}"
# copy jail configuration files
if [ "$(\cp --force --backup=simple --suffix=.original \
etc/fail2ban/jail.d/* "${F2B_DIR}/jail.d/")" -ne 0 ]; then
if [ ! "$(\cp --force --backup=simple --suffix=.original \
etc/fail2ban/jail.d/* "${F2B_DIR}/jail.d/")" ]; then
copyFailure 'jail files'
fi
echo -e "${info}Copy jail configuration files${normal} -- ${ok}[OK]${normal}"
@ -111,8 +110,7 @@ echo -e "${info}Copy jail configuration files${normal} -- ${ok}[OK]${normal}"
### user post-amble
echo
echo -e "${note}------------------------------------------------------------" \
"--------------------${normal}"
echo -e "${note}--------------------------------------------------------------------------------${normal}"
echo -e "${ok}Script operations completed successfully!"
echo
echo -e "${info}You can now customize the template files if/as you desire." \
@ -125,10 +123,19 @@ echo
echo -e "${note}To revert your configuration, simply copy the ${lit}.original" \
"${note}files over the modified"
echo -e "files. For example, ${lit}cp jail.local.original jail.local${normal}"
echo -e "${note}--------------------------------Script--Complete------------" \
"--------------------${normal}"
echo -e "${note}--------------------------------Script--Complete--------------------------------${normal}"
echo
### exit gracefully
exit 0
exit 0
### error code summary
# 1: fail2ban executable file could not be found -- fail2ban likely not
# installed
# 2: script not run as ROOT (needed to avoid any permissions issues)
# 3: invalid fail2ban configuration directory provided by user
# 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.