refactoring changes from sequpgrade (endReturn, ...) and some modernizations

This commit is contained in:
2023-01-03 15:49:08 +01:00
parent 215135e8aa
commit 3c22d5729f
69 changed files with 553 additions and 654 deletions

View File

@@ -25,10 +25,10 @@ step_1() {
else
exe apt install $toolName
fi
endReturn -o $? "$toolName installation failed"
endReturn "$toolName installation failed"
}
step_2_info() {
step_2_info() {
echo "Setup snmp v3 access"
echoinfo " -s : Stop after creating authentication entry"
}
@@ -50,9 +50,9 @@ step_2() {
*)
info
info "Installation aborted"
return 1;
return 1;
;;
esac
esac
fi
read -p "SNMPv3 Username: " v3User
@@ -70,7 +70,7 @@ step_2() {
# this line will be replaced on start of snmpd with a line starting with:
# usmUser
v3AuthEntry="createUser ${v3User} SHA \"${v3Pass}\" DES"
v3AuthEntry="createUser ${v3User} SHA \"${v3Pass}\" DES"
addConf -a "$v3AuthEntry" "$v3AuthLoc"
shift
@@ -113,7 +113,7 @@ step_5() {
[ -n "${1:-}" ] && lInterface="$1"
# Check if interface exists
ip -br a | grep -E "^$lInterface" >>/dev/null 2>&1
endReturn -o $? "Interface $lInterface does not exist"
endReturn "Interface $lInterface does not exist"
exe ufw allow in on $lInterface to any port 161 proto udp comment "snmp"
}
@@ -127,7 +127,7 @@ step_20() {
fi
exe wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/raspberry.sh -O "${rpiExtendLoc}"
endReturn -o $? "Download failed"
endReturn "Download failed"
exe chmod +x "$rpiExtendLoc"
addConf -a "extend raspberry /etc/snmp/raspberry.sh" "$toolConfig"
@@ -146,13 +146,13 @@ rpiSudoersContent="${toolSysUser} ALL=(ALL) NOPASSWD: /etc/snmp/raspberry.sh, /u
step_22_info() { echo "Extend $toolName with OS update availablity"; }
step_22_alias() { echo "osupdate"; }
step_22() {
checkExtend osupdate
checkExtend osupdate
if [ "$?" != "0" ]; then
return 1
fi
exe wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/osupdate -O "${osUpdateExtendLoc}"
endReturn -o $? "Download failed"
endReturn "Download failed"
exe chmod +x "$osUpdateExtendLoc"
addConf -a "extend osupdate $osUpdateExtendLoc" "$toolConfig"
@@ -184,7 +184,7 @@ step_25() {
exe bash -i
info "Interactive shell ended. Continuing with $0."
exe nginx -t
endReturn -o $? "Nginx configuration error"
endReturn "Nginx configuration error"
exe service nginx restart
;;
@@ -211,7 +211,7 @@ step_26_alias() { echo "phpfpm_config"; }
step_26() {
exe sed -i "s/^;\(pm\.status_path\)/\1/" "$phpPoolConfigLoc"
exe php-fpm${phpVersionStr} -t
endReturn -o $? "Invalid php configuration"
endReturn "Invalid php configuration"
service php${phpVersionStr}-fpm restart
}
@@ -227,7 +227,7 @@ step_27() {
fi
exe wget https://github.com/librenms/librenms-agent/raw/master/snmp/phpfpmsp -O "${phpfpmExtendLoc}"
endReturn -o $? "Download failed"
endReturn "Download failed"
exe chmod +x "$phpfpmExtendLoc"
addConf -a "extend phpfpmsp ${phpfpmExtendLoc}" "$toolConfig"
@@ -253,7 +253,7 @@ step_29() {
exe bash -i
info "Interactive shell ended. Continuing with $0."
exe nginx -t
endReturn -o $? "Nginx configuration error"
endReturn "Nginx configuration error"
exe service nginx restart
;;
@@ -279,7 +279,7 @@ step_30() {
fi
exe wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/nginx -O "${nginxExtendLoc}"
endReturn -o $? "Download failed"
endReturn "Download failed"
exe chmod +x "$nginxExtendLoc"
addConf -a "extend nginx ${nginxExtendLoc}" "$toolConfig"
@@ -293,9 +293,9 @@ step_32_info() { echo "Extend for postfix detailed and queue"; }
step_32_alias() { echo "postfix"; }
step_32() {
exe wget https://github.com/librenms/librenms-agent/raw/master/snmp/postfix-queues -O "${postfixQueuesExtendLoc}"
endReturn -o $? "Download postfix-queues failed"
endReturn "Download postfix-queues failed"
exe wget https://github.com/librenms/librenms-agent/raw/master/snmp/postfixdetailed -O "${postfixScript}"
endReturn -o $? "Download postfixdetailed failed"
endReturn "Download postfixdetailed failed"
exe chmod +x "${postfixQueuesExtendLoc}"
exe chmod +x "${postfixScript}"
@@ -352,7 +352,7 @@ step_37_info() { echo "Extend for fail2ban jail information"; }
step_37_alias() { echo "fail2ban"; }
step_37(){
exe wget https://github.com/librenms/librenms-agent/raw/master/snmp/fail2ban -O "${fail2banExtendLoc}"
endReturn -o $? "Download postfix failed"
endReturn "Download postfix failed"
exe chmod +x "$fail2banExtendLoc"
@@ -384,7 +384,7 @@ step_40() {
fi
exe wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro -O "${distroExtendLoc}"
endReturn -o $? "Download distro detection script failed"
endReturn "Download distro detection script failed"
exe chmod +x "$distroExtendLoc"
info "Create distro extend"
@@ -395,7 +395,7 @@ step_40() {
distroExtendLoc="${toolConfigLoc}/distro"
step_42_info() {
step_42_info() {
echo "Gather dhcp information from a dhcpd lease file"
echoinfo "pi-hole lease file not supported"
}
@@ -409,10 +409,10 @@ step_42() {
[ $? -ne 0 ] && return 0
exe apt install dhcpd-pools ${sq_aptOpt}
endReturn -o $? "Install dhcpd-pools failed"
endReturn "Install dhcpd-pools failed"
exe wget $locExtUrl -O "${locExtLoc}"
endReturn -o $? "Download $locExtName script failed"
endReturn "Download $locExtName script failed"
exe chmod +x "$locExtLoc"
info "Create extend for $locExtName"
@@ -421,7 +421,7 @@ step_42() {
info "Create config for $locExtName"
addConf -s "$dhcpExtendConfig" "$dhcpExtendConfigLoc"
echo " [W] Adapt config $dhcpExtendConfigLoc manually and restart snmpd"
warning "Adapt config $dhcpExtendConfigLoc manually and restart snmpd"
}
dhcpExtendConfigLoc="${toolConfigLoc}/dhcp.json"
dhcpExtendConfig="{\"leasefile\": \"/var/lib/dhcp/dhcpd.leases\"
@@ -438,7 +438,7 @@ step_44() {
[ $? -ne 0 ] && return 0
exe wget $locExtUrl -O "${locExtLoc}"
endReturn -o $? "Download $locExtName script failed"
endReturn "Download $locExtName script failed"
exe chmod +x "$locExtLoc"
info "Create extend for $locExtName"
@@ -483,7 +483,7 @@ step_46() {
exe apt install $piholeDeps ${sq_aptOpt}
exe wget $locExtUrl -O "${locExtLoc}"
endReturn -o $? "Download $locExtName script failed"
endReturn "Download $locExtName script failed"
exe chmod +x "$locExtLoc"
info "Create extend for $locExtName"
@@ -493,7 +493,7 @@ step_46() {
color red
echo -e " [W] Check the following in the extend script and restart snmpd:\n"
else
echo " [I] Check the follwing in the extend script:"
info "Check the follwing in the extend script:"
fi
echo "(API_AUTH_KEY) Add your pi-hole API key"
echo " (API_URL) and check the API URL"
@@ -562,9 +562,9 @@ checkExtend() {
exep "cat \"$toolConfig\" | grep -e '^\s*extend\s\+${1}' >>/dev/null 2>&1"
# Only warn if entry exists and dry-run is not seleted
if [ $? -eq 0 ] && ! dry ; then
if [ $? -eq 0 ] && ! dry ; then
return 1
fi
fi
return 0
}