#!/bin/bash seqDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )" toolName="snmpd" toolConfigLoc="/etc/snmp" toolConfig="${toolConfigLoc}/snmpd.conf" step_1_info() { echo "Install packages for $toolName"; } step_1_alias() { ALIAS="install"; } step_1() { exe apt update if [ $QUIET != 0 ]; then exe apt-get -qq install $toolName else exe apt install $toolName fi endReturn -o $? "$toolName installation failed" } step_2_info() { echo "Setup snmp v3 access"; } step_2() { # ## Create authentication entry exep "cat \"$v3AuthLoc\" | grep -e '^\s*usmUser'" if [ "$?" == "0" ]; then echo exe read -p "User entry found. Continue: y/n(default)? " answer case $answer in [yY]) echo echo Continuing installation... ;; *) echo echo Installation aborted return 1; ;; esac fi read -p "SNMPv3 Username: " v3User read -s -p "SNMPv3 Password: " v3Pass echo exe service snmpd stop # this line will be replaced on start of snmpd with a line starting with: # usmUser v3AuthEntry="createUser ${v3User} SHA \"${v3Pass}\" DES" addConf -a "$v3AuthEntry" "$v3AuthLoc" # ## Add custom base configuration addConf -c "" "${toolConfig}" exe cp "${seqDir}/snmpd.conf" "${toolConfig}" # ## Add username as rouser exe sed -i "s/authOnlyUser/${v3User}/" "$toolConfig" # ## Write syslocation exe read -p "sysLocation: " v3Location exe read -p "sysContact (name ): " v3Contact exe sed -i "s/\(sysLocation\s*\).*/\1${v3Location}/" "$toolConfig" exe sed -i "s/\(sysContact\s*\).*/\1${v3Contact}/" "$toolConfig" exe service snmpd start } v3AuthLoc="/var/lib/snmp/snmpd.conf" step_20_info() { echo "Extend $toolName for Raspberry Pi"; } step_20_alias() { ALIAS="raspberry"; } step_20() { checkExtend raspberry if [ "$?" != "0" ]; then return 1 fi exe wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/raspberry.sh -O "${rpiExtendLoc}" endReturn -o $? "Download failed" exe chmod +x "$rpiExtendLoc" addConf -a "extend raspberry /etc/snmp/raspberry.sh" "$toolConfig" addConf -c "$rpiSudoersContent" "$rpiSudoersLoc" exe service snmpd restart } rpiExtendLoc="${toolConfigLoc}/raspberry.sh" rpiSudoersLoc="/etc/sudoers.d/snmprpi" rpiSudoersContent=" Debian-snmp ALL=(ALL) NOPASSWD: /etc/snmp/raspberry.sh, /usr/bin/vcgencmd*" step_22_info() { echo "Extend $toolName with OS update availablity"; } step_22_alias() { ALIAS="osupdate"; } step_22() { 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" exe chmod +x "$osUpdateExtendLoc" addConf -a "extend osupdate $osUpdateExtendLoc" "$toolConfig" exe service snmpd restart } osUpdateExtendLoc="${toolConfigLoc}/osupdate" step_23_info() { echo "Create cron job for periodical (every 8 hours) apt-get update"; } step_23() { addConf -s "$osUpdateCronContent" "$osUpdateCron" } osUpdateCron="/etc/cron.d/aptUpdate" osUpdateCronContent="22 */6 * * * root /usr/bin/apt-get -qq update" #fail2ban #exe wget https://github.com/librenms/librenms-agent/raw/master/snmp/fail2ban -O "${toolConfig}/fail2ban" # nginx #exe wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/nginx -O "${toolConfig}/nginx" # php-fpm #exe wget https://github.com/librenms/librenms-agent/raw/master/snmp/phpfpmsp -O "${toolConfig}/phpfpmsp" 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 [ "$?" == "0" ] && [ "$DRY" == "0" ] ; then echo "[WARN] Extend for ${1} exists" return 1 fi # adding dry run output for clarification if [ "$DRY" != "0" ] ; then echo "-- check if \"extend ${1}\" exists..dry-run" fi return 0 } VERSION_SEQREV=7 . sequencer.sh