New step for distribution detection
Adapt echo to echoseq
This commit is contained in:
75
seqs/snmp.sh
75
seqs/snmp.sh
@@ -28,17 +28,17 @@ step_2() {
|
|||||||
## Create authentication entry
|
## Create authentication entry
|
||||||
exep "cat \"$v3AuthLoc\" | grep -e '^\s*usmUser'"
|
exep "cat \"$v3AuthLoc\" | grep -e '^\s*usmUser'"
|
||||||
if [ "$?" == "0" ]; then
|
if [ "$?" == "0" ]; then
|
||||||
echo
|
echoseq
|
||||||
|
|
||||||
exe read -p "User entry found. Continue: y/n(default)? " answer
|
exe read -p "User entry found. Continue: y/n(default)? " answer
|
||||||
case $answer in
|
case $answer in
|
||||||
[yY])
|
[yY])
|
||||||
echo
|
echoseq
|
||||||
echo Continuing installation...
|
echoseq "Continuing installation..."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo
|
echoseq
|
||||||
echo Installation aborted
|
echoseq "Installation aborted"
|
||||||
return 1;
|
return 1;
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -46,14 +46,14 @@ step_2() {
|
|||||||
|
|
||||||
read -p "SNMPv3 Username: " v3User
|
read -p "SNMPv3 Username: " v3User
|
||||||
read -p "SNMPv3 Password: " v3Pass
|
read -p "SNMPv3 Password: " v3Pass
|
||||||
echo
|
echoseq
|
||||||
read -p "Repeat Password: " v3Pass2
|
read -p "Repeat Password: " v3Pass2
|
||||||
|
|
||||||
if [ "$v3Pass" != "$v3Pass2" ] ; then
|
if [ "$v3Pass" != "$v3Pass2" ] ; then
|
||||||
echoerr " [E] Password mismatch"
|
echoerr " [E] Password mismatch"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
echo
|
echoseq
|
||||||
|
|
||||||
exe service snmpd stop
|
exe service snmpd stop
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ step_2() {
|
|||||||
|
|
||||||
shift
|
shift
|
||||||
if [ ! -z $1 ] && [ "$1" == "-s" ] ; then
|
if [ ! -z $1 ] && [ "$1" == "-s" ] ; then
|
||||||
echo " [I] Stop after creating authentication config"
|
echoseq " [I] Stop after creating authentication config"
|
||||||
exe service snmpd start
|
exe service snmpd start
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@@ -152,9 +152,9 @@ step_25() {
|
|||||||
fi
|
fi
|
||||||
case $answer in
|
case $answer in
|
||||||
[yY])
|
[yY])
|
||||||
echo " [I] Opening interactive shell. Type \"exit\" to return to this script."
|
echoseq " [I] Opening interactive shell. Type \"exit\" to return to this script."
|
||||||
exe bash -i
|
exe bash -i
|
||||||
echo " [I] Interactive shell ended. Continuing with $0."
|
echoseq " [I] Interactive shell ended. Continuing with $0."
|
||||||
exe nginx -t
|
exe nginx -t
|
||||||
endReturn -o $? "Nginx configuration error"
|
endReturn -o $? "Nginx configuration error"
|
||||||
|
|
||||||
@@ -211,9 +211,9 @@ phpfpmExtendLoc="${toolConfigLoc}/phpfpmsp"
|
|||||||
step_29_info() { echo "Prepare nginx to provide status to $toolName"; }
|
step_29_info() { echo "Prepare nginx to provide status to $toolName"; }
|
||||||
step_29_alias() { ALIAS="nginx"; }
|
step_29_alias() { ALIAS="nginx"; }
|
||||||
step_29() {
|
step_29() {
|
||||||
echo -e "\n [!] Please add the following to your default server:\n"
|
echoseq -e "\n [!] Please add the following to your default server:\n"
|
||||||
echo "$nginxStatus"
|
echoseq "$nginxStatus"
|
||||||
echo
|
echoseq
|
||||||
if [ $QUIET -ne 0 ] ; then
|
if [ $QUIET -ne 0 ] ; then
|
||||||
answer=n
|
answer=n
|
||||||
else
|
else
|
||||||
@@ -221,9 +221,9 @@ step_29() {
|
|||||||
fi
|
fi
|
||||||
case $answer in
|
case $answer in
|
||||||
[yY])
|
[yY])
|
||||||
echo " [I] Opening interactive shell. Type \"exit\" to return to this script."
|
echoseq " [I] Opening interactive shell. Type \"exit\" to return to this script."
|
||||||
exe bash -i
|
exe bash -i
|
||||||
echo " [I] Interactive shell ended. Continuing with $0."
|
echoseq " [I] Interactive shell ended. Continuing with $0."
|
||||||
exe nginx -t
|
exe nginx -t
|
||||||
endReturn -o $? "Nginx configuration error"
|
endReturn -o $? "Nginx configuration error"
|
||||||
|
|
||||||
@@ -287,11 +287,11 @@ step_33() {
|
|||||||
exe chown root:$toolSysUser "$postfixCacheLoc"
|
exe chown root:$toolSysUser "$postfixCacheLoc"
|
||||||
exe chmod 770 "$postfixCacheLoc"
|
exe chmod 770 "$postfixCacheLoc"
|
||||||
|
|
||||||
echo " [I] Create symlink /var/log/maillog which is used by postfixdetailed"
|
echoseq " [I] Create symlink /var/log/maillog which is used by postfixdetailed"
|
||||||
exe ln -fs /var/log/mail.log /var/log/maillog
|
exe ln -fs /var/log/mail.log /var/log/maillog
|
||||||
|
|
||||||
echo " [I] Run /etc/snmp/postfixdetailed to create the initial cache file"
|
echoseq " [I] Run /etc/snmp/postfixdetailed to create the initial cache file"
|
||||||
echo " so you don't end up with some crazy initial starting value."
|
echoseq " so you don't end up with some crazy initial starting value."
|
||||||
exe sudo -u $toolSysUser "$postfixScript"
|
exe sudo -u $toolSysUser "$postfixScript"
|
||||||
}
|
}
|
||||||
postfixCacheLoc="/var/cache/postfixdetailed"
|
postfixCacheLoc="/var/cache/postfixdetailed"
|
||||||
@@ -301,9 +301,9 @@ postfixQueuesExtendLoc="${toolConfigLoc}/postfix-queues"
|
|||||||
step_34_info() { echo "Create sudoers file for postfix scripts"; }
|
step_34_info() { echo "Create sudoers file for postfix scripts"; }
|
||||||
step_34() {
|
step_34() {
|
||||||
addConf -s "$postfixSudoersContent" "$postfixSudoersLoc"
|
addConf -s "$postfixSudoersContent" "$postfixSudoersLoc"
|
||||||
echo " [I] Changing ${postfixQueuesExtendLoc} to add sudo for qshape"
|
echoseq " [I] Changing ${postfixQueuesExtendLoc} to add sudo for qshape"
|
||||||
exe sed -i -E "s/\`qshape/\`sudo qshape/" "${postfixQueuesExtendLoc}"
|
exe sed -i -E "s/\`qshape/\`sudo qshape/" "${postfixQueuesExtendLoc}"
|
||||||
echo " [W] Reboot may be required to make these changes active"
|
echoseq " [W] Reboot may be required to make these changes active"
|
||||||
}
|
}
|
||||||
postfixSudoersLoc="/etc/sudoers.d/snmppostfix"
|
postfixSudoersLoc="/etc/sudoers.d/snmppostfix"
|
||||||
postfixSudoersContent="${toolSysUser} ALL=(ALL) NOPASSWD: /usr/sbin/qshape"
|
postfixSudoersContent="${toolSysUser} ALL=(ALL) NOPASSWD: /usr/sbin/qshape"
|
||||||
@@ -312,12 +312,12 @@ step_35_info() { echo "Create postfix extends (postfixdetailed and postfix-queue
|
|||||||
step_35() {
|
step_35() {
|
||||||
checkExtend postfix-queues
|
checkExtend postfix-queues
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo " [I] Create postfix-queues extend"
|
echoseq " [I] Create postfix-queues extend"
|
||||||
addConf -a "extend mailq ${postfixQueuesExtendLoc}" "$toolConfig"
|
addConf -a "extend mailq ${postfixQueuesExtendLoc}" "$toolConfig"
|
||||||
fi
|
fi
|
||||||
checkExtend postfixdetailed
|
checkExtend postfixdetailed
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo " [I] Create postfixdetailed extend"
|
echoseq " [I] Create postfixdetailed extend"
|
||||||
addConf -a "extend postfixdetailed ${postfixScript}" "$toolConfig"
|
addConf -a "extend postfixdetailed ${postfixScript}" "$toolConfig"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -340,10 +340,8 @@ step_37(){
|
|||||||
|
|
||||||
checkExtend fail2ban
|
checkExtend fail2ban
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo " [I] Create fail2ban extend"
|
echoseq " [I] Create fail2ban extend"
|
||||||
addConf -a "extend fail2ban ${fail2banExtendLoc} -c" "$toolConfig"
|
addConf -a "extend fail2ban ${fail2banExtendLoc} -c" "$toolConfig"
|
||||||
else
|
|
||||||
echo " [W] Fail2ban extend already included"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exe apt install $fail2banDeps $aptOpt
|
exe apt install $fail2banDeps $aptOpt
|
||||||
@@ -359,21 +357,38 @@ fail2banCronLoc="/etc/cron.d/fail2banCache"
|
|||||||
fail2banCron="# Update cache for faster fail2ban polling
|
fail2banCron="# Update cache for faster fail2ban polling
|
||||||
*/3 * * * * root ${fail2banExtendLoc} -u"
|
*/3 * * * * root ${fail2banExtendLoc} -u"
|
||||||
|
|
||||||
|
step_40_info() { echo "Create linux distribution detection extend (distro)"; }
|
||||||
|
step_40_alias() { ALIAS="distro"; }
|
||||||
|
step_40() {
|
||||||
|
checkExtend distro
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
exe wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro -O "${distroExtendLoc}"
|
||||||
|
endReturn -o $? "Download distro detection script failed"
|
||||||
|
exe chmod +x "$distroExtendLoc"
|
||||||
|
|
||||||
|
echoseq " [I] Create distro extend"
|
||||||
|
addConf -a "extend distro ${distroExtendLoc}" "$toolConfig"
|
||||||
|
|
||||||
|
exe service snmpd restart
|
||||||
|
}
|
||||||
|
distroExtendLoc="${toolConfigLoc}/distro"
|
||||||
checkExtend() {
|
checkExtend() {
|
||||||
# adding dry run output for clarification
|
# adding dry run output for clarification
|
||||||
if [ "$DRY" != "0" ] ; then
|
if [ $DRY -ne 0 ] ; then
|
||||||
echo " [I] check if \"extend ${1}\" exists..dry-run"
|
echoseq " [I] check if \"extend ${1}\" exists..dry-run"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exep "cat \"$toolConfig\" | grep -e '^\s*extend\s\+${1}' >>/dev/null 2>&1"
|
exep "cat \"$toolConfig\" | grep -e '^\s*extend\s\+${1}' >>/dev/null 2>&1"
|
||||||
# Only warn if entry exists and dry-run is not seleted
|
# Only warn if entry exists and dry-run is not seleted
|
||||||
if [ "$?" == "0" ] && [ "$DRY" == "0" ] ; then
|
if [ $? -eq 0 ] && [ $DRY -eq 0 ] ; then
|
||||||
echoerr " [W] Extend for ${1} exists"
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
VERSION_SEQREV=11
|
VERSION_SEQREV=12
|
||||||
. /usr/local/bin/sequencer.sh
|
. /usr/local/bin/sequencer.sh
|
||||||
|
Reference in New Issue
Block a user