snmp - modernize code

This commit is contained in:
2022-12-22 11:52:57 +01:00
parent 4bfb47f490
commit e26611c8ad

View File

@@ -1,14 +1,15 @@
#!/bin/bash
seqDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
toolName="snmpd"
toolConfigLoc="/etc/snmp"
toolConfig="${toolConfigLoc}/snmpd.conf"
toolSysUser="Debian-snmp"
readonly toolName="snmpd"
readonly toolConfigLoc="/etc/snmp"
readonly toolConfig="${toolConfigLoc}/snmpd.conf"
readonly toolSysUser="Debian-snmp"
sq_aptOpt=
seq_config() {
## Apt cmdline option to suppress user interaction
quiet && APTOPT="-y"
interactive || sq_aptOpt="-y"
## Return of non zero value will abort the sequence
return 0
@@ -82,7 +83,7 @@ step_2() {
#
## Add custom base configuration
addConf -c "" "${toolConfig}"
exe cp "${seqDir}/snmpd.conf" "${toolConfig}"
exe cp "${seq_origin}/snmpd.conf" "${toolConfig}"
#
## Add username as rouser
@@ -239,7 +240,7 @@ step_29_info() { echo "Prepare nginx to provide status to $toolName"; }
step_29_alias() { echo "nginx"; }
step_29() {
info -e "\n [!] Please add the following to your default server:\n"
info "$nginxStatus"
sqr::echo "$nginxStatus"
info
if quiet ; then
answer=n
@@ -291,11 +292,6 @@ nginxExtendLoc="${toolConfigLoc}/nginx"
step_32_info() { echo "Extend for postfix detailed and queue"; }
step_32_alias() { echo "postfix"; }
step_32() {
local aptOpt=
if quiet;then
aptOpt="-y"
fi
exe wget https://github.com/librenms/librenms-agent/raw/master/snmp/postfix-queues -O "${postfixQueuesExtendLoc}"
endReturn -o $? "Download postfix-queues failed"
exe wget https://github.com/librenms/librenms-agent/raw/master/snmp/postfixdetailed -O "${postfixScript}"
@@ -304,7 +300,7 @@ step_32() {
exe chmod +x "${postfixQueuesExtendLoc}"
exe chmod +x "${postfixScript}"
exe apt install $postfixDeps $aptOpt
exe apt install $postfixDeps ${sq_aptOpt}
}
postfixDeps="pflogsumm"
@@ -355,11 +351,6 @@ step_35() {
step_37_info() { echo "Extend for fail2ban jail information"; }
step_37_alias() { echo "fail2ban"; }
step_37(){
local aptOpt=
if quiet;then
aptOpt="-y"
fi
exe wget https://github.com/librenms/librenms-agent/raw/master/snmp/fail2ban -O "${fail2banExtendLoc}"
endReturn -o $? "Download postfix failed"
@@ -371,7 +362,7 @@ step_37(){
addConf -a "extend fail2ban ${fail2banExtendLoc} -c" "$toolConfig"
fi
exe apt install $fail2banDeps $aptOpt
exe apt install $fail2banDeps ${sq_aptOpt}
}
fail2banDeps="libjson-perl"
fail2banExtendLoc="${toolConfigLoc}/fail2ban"
@@ -417,7 +408,7 @@ step_42() {
checkExtend $locExtName
[ $? -ne 0 ] && return 0
exe apt install dhcpd-pools
exe apt install dhcpd-pools ${sq_aptOpt}
endReturn -o $? "Install dhcpd-pools failed"
exe wget $locExtUrl -O "${locExtLoc}"
@@ -489,7 +480,7 @@ step_46() {
checkExtend $locExtName
[ $? -ne 0 ] && return 0
exe apt install $piHoleDeps $APTOPT
exe apt install $piholeDeps ${sq_aptOpt}
exe wget $locExtUrl -O "${locExtLoc}"
endReturn -o $? "Download $locExtName script failed"
@@ -578,5 +569,7 @@ checkExtend() {
return 0
}
# shellcheck disable=SC2034 # Appears unused
readonly sqr_minVersion=16
# shellcheck disable=SC1091 # Don't follow this source
. /usr/local/bin/sequencer.sh