librenms - updated and modernized seq

This commit is contained in:
2022-12-04 10:35:45 +01:00
parent 5279eb7032
commit 770d1dd63c

View File

@@ -3,35 +3,25 @@
#
## Installation and maintenance for LibreNMS
toolName="librenms"
toolUser="librenms"
readonly toolName="librenms"
readonly toolUser="librenms"
libreDeps='acl curl fping git graphviz imagemagick mtr-tiny nmap python3-dotenv python3-pymysql python3-redis python3-setuptools python3-systemd python3-pip rrdtool snmp snmpd whois'
librePhpDeps=(cli curl fpm gd gmp mbstring mysql snmp xml zip)
sq_aptOpt=
phpVersion=
libreDeps='acl curl composer fping git graphviz imagemagick mtr-tiny nmap rrdtool snmp snmpd whois python3-dotenv python3-pymysql python3-redis python3-setuptools'
librePhpDeps='php${phpVersion}-cli php${phpVersion}-curl php${phpVersion}-fpm php${phpVersion}-gd php${phpVersion}-json php${phpVersion}-mbstring php${phpVersion}-mysql php${phpVersion}-snmp php${phpVersion}-xml php${phpVersion}-zip'
#librePhpDeps="composer php-cli-prompt php-composer-ca-bundle php-composer-semver php-composer-spdx-licenses php-json-schema php-psr-log php-symfony-console php-symfony-filesystem php-symfony-finder php-symfony-polyfill-mbstring php-symfony-process"
#librePackages="fping git graphviz imagemagick mtr-tiny nmap python-memcache python-mysqldb rrdtool snmp snmpd whoisi nagios-plugins"
# Get script working directory
# (when called from a different directory)
WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd )"
CONFIG=0
SCRIPT_NAME=$(basename -- "$0")
SCRIPT_NAME=${SCRIPT_NAME%%.*}
CONFIG_FILE_NAME="${SCRIPT_NAME}.cfg"
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
seq_config() {
initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
if [ $? -eq 0 ] ; then
CONFIG=1
#initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
if initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?}" ; then
info " Install: $LNMS_DIR"
info " Backup: $LNMS_BU_DIR"
else
dry || return 1
fi
return 0
}
step_1_info() { echo "Updating apt"; }
@@ -45,18 +35,18 @@ step_2_info() {
echoinfo "$libreDeps"
}
step_2() {
exe apt install $libreDeps
exe apt install $libreDeps ${sq_aptOpt}
endReturn -o $? "Failed to install $toolName dependencies"
}
step_3_info() {
echo "Installing PHP related packages:"
fetchPhpVersion
echoinfo `eval echo "$librePhpDeps"`
echoinfo "${librePhpDeps[@]/#/php${phpVersion}-}"
}
step_3() {
fetchPhpVersion
exe apt install `eval echo "$librePhpDeps"`
exe apt install "${librePhpDeps[@]/#/php${phpVersion}-}" ${sq_aptOpt}
endReturn -o $? "Failed to install $toolName php dependencies"
}
@@ -64,8 +54,6 @@ step_4_info() { echo "Adding $toolName user ($toolUser)"; }
step_4() {
exe useradd $toolUser -d "$LNMS_DIR" -M -r -s "$(which bash)"
saveReturn $?
#exe usermod -a -G librenms www-data
#saveReturn $?
endReturn "Failed to create user $toolUser"
}
@@ -85,10 +73,10 @@ step_6() {
step_10_info() { echo "Create mysql database for $toolName"; }
step_10() {
local libreDbOpt=
if [ ! -z "$LNMS_DB_NAME" ] ; then
if [ -n "$LNMS_DB_NAME" ] ; then
libreDbOpt="-d $LNMS_DB_NAME"
fi
exe ${WDIR}/mysql.sh -q createdb --charset utf8 $libreDbOpt
exe "${seq_origin}"/mysql.sh ${sqr_args} createdb --charset utf8 "$libreDbOpt"
endReturn -o $? "Failed to create mysql database $LNMS_DB_NAME"
}
@@ -113,12 +101,13 @@ SQLCONF_END
step_12_info() { echo "PHP fpm/cli timezone configuration"; }
step_12() {
color green
fetchPhpVersion
cat << PHPCONF_END
Ensure date.timezone is set in php.ini to your preferred time zone. See http://php.net/manual/en/timezones.php for a list of supported timezones. Valid examples are: "America/New_York", "Europe/Berlin", "Etc/UTC".
vi /etc/php/7.3/fpm/conf.d/90-custom_pi.ini
vi /etc/php/7.3/cli/conf.d/90-custom_pi.ini
vi /etc/php/${phpVersion}/fpm/conf.d/90-custom_pi.ini
vi /etc/php/${phpVersion}/cli/conf.d/90-custom_pi.ini
-------------------------------------------
date.timezone = Europe/Berlin
@@ -134,8 +123,8 @@ step_13() {
color green
cat << FPMCONF_END
cp /etc/php/7.3/fpm/pool.d/www.conf /etc/php/7.3/fpm/pool.d/librenms.conf
vi /etc/php/7.3/fpm/pool.d/librenms.conf
cp /etc/php/${phpVersion}/fpm/pool.d/www.conf /etc/php/${phpVersion}/fpm/pool.d/librenms.conf
vi /etc/php/${phpVersion}/fpm/pool.d/librenms.conf
# Change [www] to [librenms]:
@@ -184,27 +173,27 @@ NGINXCONF_END
step_20_info() { echo "Create $toolName cron job"; }
step_20_alias() { echo "cron"; }
step_20() {
sqr::echo -n " [I] Creating $lnmsCronLoc ... "
exe cp "${LNMS_DIR}/librenms.nonroot.cron" "$lnmsCronLoc" && sqr::echo "Ok" || sqr::echo "Nok"
local lnmsCronLoc="/etc/cron.d/librenms"
info -n "Creating $lnmsCronLoc ... "
exe cp "${LNMS_DIR}/librenms.nonroot.cron" "$lnmsCronLoc" && info -d "Ok" || info -d "Nok"
}
lnmsCronLoc="/etc/cron.d/librenms"
step_22_info() { echo "Enable lnms command completion"; }
step_22_alias() { echo "cmdcompletion"; }
step_22() {
exep 'echo -e "#!/bin/bash\nsudo -u '$toolUser' \"'$LNMS_DIR'/lnms\" \"\$@\"" > '"$lnmsLocalBin"
local lnmsLocalBin="/usr/local/bin/lnms"
exep echo -e '"#!/usr/bin/env bash\nsudo -u '$toolUser' \"'$LNMS_DIR'/lnms\" \"\$@\""' \> "$lnmsLocalBin"
exe chmod 744 "$lnmsLocalBin"
exe cp "${LNMS_DIR}/misc/lnms-completion.bash" /etc/bash_completion.d/
}
lnmsLocalBin="/usr/local/bin/lnms"
step_24_info() { echo "Copy logrotate config"; }
step_24_alias() { echo "logrotate"; }
step_24() {
sqr::echo -n " [I] Creating $lnmsLogrotLoc ... "
exe cp "${LNMS_DIR}/misc/librenms.logrotate" "$lnmsLogrotLoc" && sqr::echo "Ok" || sqr::echo "Nok"
local lnmsLogrotLoc="/etc/logrotate.d/librenms"
info -n "Creating $lnmsLogrotLoc ... "
exe cp "${LNMS_DIR}/misc/librenms.logrotate" "$lnmsLogrotLoc" && info -d "Ok" || info -d "Nok"
}
lnmsLogrotLoc="/etc/logrotate.d/librenms"
step_26_info() { echo "Install nagios plugin to enable services"; }
step_26_alias() { echo "services"; }
@@ -212,10 +201,10 @@ step_26() {
exe apt install monitoring-plugins
info
info " [$LNMS_DIR/config.php]"
info "\$config['show_services'] = 1;"
info
info " [/etc/cron.d/librenms]"
info " */5 * * * * librenms /opt/librenms/services-wrapper.py 1"
info -a " \$config['show_services'] = 1;"
info -a
info -a " [/etc/cron.d/librenms]"
info -a " */5 * * * * librenms /opt/librenms/services-wrapper.py 1"
}
step_30_info() { echo "Backup ${toolName} web direcotry"; }
@@ -223,21 +212,21 @@ step_30_alias() { echo "backup"; }
step_30() {
info "Backup install directory to ${LNMS_BU_DIR}"
exe mkdir -p "$LNMS_BU_DIR"
exep "cd \"${LNMS_DIR}\"/.. && tar czf \"${LNMS_BU_DIR}/\`date +%Y%m%d\`_${toolName}_web.tar.gz\" \"$(basename "$LNMS_DIR")\""
exep cd "${LNMS_DIR}"/.. "&&" tar czf "${LNMS_BU_DIR}/$(date +%Y%m%d)_${toolName}_web.tar.gz" "$(basename "$LNMS_DIR")"
}
step_31_info() { echo "Backup ${toolName} database [daily|monthly(default)]"; }
step_31_info() { echoinfoArgs "[daily|monthly(default)]"; echo "Backup ${toolName} database"; }
step_31_alias() { echo "backupdb"; }
step_31() {
case "$2" in
daily|Daily|DAILY)
case "${2:-}" in
daily | Daily | DAILY)
info "Daily backup..."
exep "mysqldump --single-transaction -u root ${LNMS_DB_NAME} | bzip2 -c > \"${LNMS_BU_DIR}/${toolName}_daily.sql.bz2\""
exep mysqldump --single-transaction -u root "${LNMS_DB_NAME}" \| bzip2 -c \> "${LNMS_BU_DIR}/${toolName}_daily.sql.bz2"
;;
*)
exe mkdir -p "$LNMS_BU_DIR/monthly"
info "Monthly backup..."
exep "mysqldump --single-transaction -u root ${LNMS_DB_NAME} | bzip2 -c > \"${LNMS_BU_DIR}/monthly/\`date +%Y%m%d\`_${toolName}.sql.bz2\""
exep mysqldump --single-transaction -u root "${LNMS_DB_NAME}" \| bzip2 -c \> "${LNMS_BU_DIR}/monthly/$(date +%Y%m%d)_${toolName}.sql.bz2"
;;
esac
}
@@ -267,13 +256,14 @@ step_42() {
}
fetchPhpVersion() {
if [ ! -z $phpVersion ] ; then
if [ -n "${phpVersion}" ] ; then
return 0
fi
phpVersion="$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')"
}
# Sequence Revision
# shellcheck disable=SC2034 # Appears unused
readonly sqr_minVersion=16
# shellcheck disable=SC1091 # Don't follow this source
. /usr/local/bin/sequencer.sh