#!/bin/bash # ## Installation and maintenance for LibreNMS ## Using buster repositories for php 7.3 installation toolName="librenms" 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" step_config() { initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" if [ $? -eq 0 ] ; then CONFIG=1 echo " Install: $LNMS_DIR" echo " Backup: $LNMS_BU_DIR" else exit 1 fi } step_1_info() { echo "Updating apt"; } step_1_alias() { ALIAS="install"; } step_1() { exe apt update } step_2_info() { echo "Installing $toolname dependencies:" echoinfo "$libreDeps" } step_2() { exe apt install $librePackages endReturn -o $? "Failed to install $toolName dependencies" } step_3_info() { echo "Installing PHP related packages:" fetchPhpVersion echoinfo `eval echo "$librePhpDeps"` } step_3() { fetchPhpVersion exe apt install `eval echo "$librePhpDeps"` endReturn -o $? "Failed to install $toolName php dependencies" } 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 "Failed to create $toolName user" } 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 endReturn -o $? "Failed to install php dependencies" } step_10_info() { echo "Create mysql database for $toolName"; } step_10() { ${WDIR}/mysql.sh -q createdb endReturn -o $? "Failed to create mysql database $LNMS_DB_NAME" } 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_30_info() { echo "Backup ${toolName} web direcotry"; } step_30_alias() { ALIAS="backup"; } step_30() { [ $QUIET -ne 2 ] && echo " [I] Backup install directory ${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_alias() { ALIAS="backupdb"; } step_31() { case "$2" in daily|Daily|DAILY) [ $QUIET -ne 2 ] && echo " [I] Daily backup..." exep "mysqldump --single-transaction -u root ${LNMS_DB_NAME} | bzip2 -c > \"${LNMS_BU_DIR}/${toolName}_daily.sql.bz2\"" ;; *) [ $QUIET -ne 2 ] && echo " [I] Monthly backup..." exep "mysqldump --single-transaction -u root ${LNMS_DB_NAME} | bzip2 -c > \"${LNMS_BU_DIR}/monthly/\`date +%Y%m%d\`_${toolName}.sql.bz2\"" ;; esac } 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 } fetchPhpVersion() { if [ ! -z $phpVersion ] ; then return 0 fi phpVersion="$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')" } # Sequence Revision VERSION_SEQREV=12 . /usr/local/bin/sequencer.sh