#!/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() { apt update } step_2_info() { echo -e "Installing $toolname dependencies: $librePackages\n"; } step_2() { apt install $librePackages saveReturn $? endReturn } step_3_info() { echo -e "Installing -t buster PHP related packages\n$librePhpDeps\n"; } step_3() { apt -t buster install $librePhpDeps saveReturn $? endReturn } step_4_info() { echo "Adding $toolName user (librenms:librenms)"; } step_4() { useradd librenms -d /opt/librenms -M -r saveReturn $? usermod -a -G librenms www-data saveReturn $? endReturn } step_5_info() { echo "Installing $toolName using composer"; } step_5() { cd /opt 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:" mysql -u root -e 'SHOW DATABASES;' echo -en "Enter database name: " read mysqlDatabase endCheckEmpty mysqlDatabase "database name" mysql -u root -e 'CREATE DATABASE '$mysqlDatabase' CHARACTER SET utf8 COLLATE utf8_unicode_ci;' saveReturn $? endReturn echo "Existing mysql user:" 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" mysql -u root -e 'CREATE USER '"'"$mysqlUser"'"'@'"'"'localhost'"'"' IDENTIFIED BY '"'"$mysqlPass"'"';' saveReturn $? endReturn mysql -u root -e 'GRANT ALL PRIVILEGES ON '$mysqlDatabase'.* TO '"'"$mysqlUser"'"'@'"'"'localhost'"'"';' saveReturn $? endReturn 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/php.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() { chown -R librenms:librenms /opt/librenms setfacl -d -m g::rwx /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd chmod -R ug=rwX /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd } # Sequence Revision VERSION_SEQREV=1 # 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