Files
shell_sequencer/seqs/librenms.sh

145 lines
4.5 KiB
Bash
Executable File

#!/bin/bash
#
## Installation and maintenance for LibreNMS
## Using buster repositories for php 7.3 installation
toolName="LibreNMS"
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"
step_1_info() { echo "Updating apt"; }
step_1_alias() { ALIAS="install"; }
step_1() {
exe apt update
}
step_2_info() { echo -e "Installing $toolname dependencies: $librePackages"; }
step_2() {
exe apt install $librePackages
saveReturn $?
endReturn
}
step_3_info() { echo -e "Installing -t buster PHP related packages:\n $librePhpDeps"; }
step_3() {
exe apt -t buster install $librePhpDeps
saveReturn $?
endReturn
}
step_4_info() { echo "Adding $toolName user (librenms:librenms)"; }
step_4() {
exe useradd librenms -d /opt/librenms -M -r
saveReturn $?
exe usermod -a -G librenms www-data
saveReturn $?
endReturn
}
step_5_info() { echo "Installing $toolName using composer"; }
step_5() {
cd /opt
exe composer create-project --no-dev --keep-vcs librenms/librenms librenms dev-master
saveReturn $?
endReturn
}
step_10_info() { echo "Create mysql database for $toolName"; }
step_10() {
local mysqlDatabase
local mysqlUser
local mysqlPass
echo "Existing mysql databases:"
exe mysql -u root -e 'SHOW DATABASES;'
echo -en "Enter database name: "
read mysqlDatabase
endCheckEmpty mysqlDatabase "database name"
exe mysql -u root -e 'CREATE DATABASE '$mysqlDatabase' CHARACTER SET utf8 COLLATE utf8_unicode_ci;'
saveReturn $?
endReturn
echo "Existing mysql user:"
exe mysql -u root -e 'SELECT User, Host FROM mysql.user;'
echo -en "Enter mysql user name: "
read mysqlUser
endCheckEmpty mysqlDatabase "user name"
echo -en "Enter mysql user password: "
read mysqlPass
endCheckEmpty mysqlPass "password"
exe mysql -u root -e 'CREATE USER '"'"$mysqlUser"'"'@'"'"'localhost'"'"' IDENTIFIED BY '"'"$mysqlPass"'"';'
saveReturn $?
endReturn
exe mysql -u root -e 'GRANT ALL PRIVILEGES ON '$mysqlDatabase'.* TO '"'"$mysqlUser"'"'@'"'"'localhost'"'"';'
saveReturn $?
endReturn
exe mysql -u root -e 'FLUSH PRIVILEGES;'
}
step_11_info() { echo "MariaDB configuration"; }
step_11() {
echo
echo "Edit or create /etc/mysql/mariadb.conf.d/90-myconfig.cnf and add:"
echo
echo "------------------------"
echo "[mysqld]"
echo "innodb_file_per_table=1"
echo "lower_case_table_names=0"
echo "------------------------"
echo
echo "Restart mysql afterwards:"
echo "service mysql restart"
}
step_12_info() { echo "PHP fpm/cli configuration"; }
step_12() {
echo
echo "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\"."
echo
echo "vi /etc/php/7.3/fpm/conf.d/90-custom_pi.ini"
echo "vi /etc/php/7.3/cli/conf.d/90-custom_pi.ini"
echo
echo "-------------------------------------------"
echo "date.timezone = Europe/Berlin"
echo "-------------------------------------------"
echo
echo "Restart php-fpm afterwards:"
echo "service php7.3-fpm restart"
}
step_40_info() { echo "Switch $toolName installation to monthly stable"; }
step_40() {
echo
echo "Add following to /opt/librenms/config.php"
echo
echo "--------------------------------------"
echo "\$config['update_channel'] = 'release';"
echo "--------------------------------------"
echo
echo "Execute following command afterwards:"
echo "cd /opt/librenms && git fetch --tags && git checkout \$(git describe --tags \$(git rev-list --tags --max-count=1))"
}
step_42_info() { echo "Fix librenms permission"; }
step_42_alias() { ALIAS="repair"; }
step_42() {
exe chown -R librenms:librenms /opt/librenms
exe setfacl -d -m g::rwx /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd
exe chmod -R ug=rwX /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd
}
# Sequence Revision
VERSION_SEQREV=2
# Workaround when called from different directory
# Not needed when path to sequencer is absolut
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
# Path to sequencer
. ${DIR}/../sequencer/sequencer.sh