#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= # Exit if an error occurs during the execution of the script ynh_abort_if_errors ### If it's a multi-instance app, meaning it can be installed several times independently ### The id of the app as stated in the manifest is available as $YNH_APP_ID ### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) ### The app instance name is available as $YNH_APP_INSTANCE_NAME ### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample ### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 ### - ynhexample__{N} for the subsequent installations, with N=3,4, ... ### The app instance name is probably what interests you most, since this is ### guaranteed to be unique. This is a good unique identifier to define installation path, ### db names, ... app="zabbix" final_path="/var/www/zabbix" #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= ### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". ### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" ynh_secure_remove $final_path #================================================= # STORE SETTINGS FROM MANIFEST #================================================= domain=$(ynh_app_setting_get $app domain) #path_url=$(ynh_app_setting_get $app path) #not used #admin=$(ynh_app_setting_get $app admin) #not used is_public=$(ynh_app_setting_get $app is_public) #language=$(ynh_app_setting_get $app language) #not used nonfree=$(ynh_app_setting_get $app nonfree) #================================================= # INSTALL DEPENDENCIES #================================================= ynh_print_info "Install Zabbix repository" install_zabbix_repo ynh_print_info "Update and install dependencies" ynh_package_update ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq zabbix-server-mysql zabbix-agent zabbix-frontend-php DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php ynh_replace_string --match_string="# fr_FR.UTF-8 UTF-8" --replace_string="fr_FR.UTF-8 UTF-8" --target_file=/etc/locale.gen locale-gen ln -s /usr/share/zabbix /var/www/zabbix ynh_secure_remove $final_path/conf/zabbix.conf.php ynh_app_setting_set $app final_path $final_path #================================================= # NGINX CONFIGURATION #================================================= ### `ynh_add_nginx_config` will use the file conf/nginx.conf # Create a dedicated nginx config ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" # Restore sudo file ynh_restore_file "/etc/sudoers.d/zabbix" #================================================= # Restore db #================================================= db_name=$(ynh_app_setting_get $app db_name) db_user=$(ynh_app_setting_get $app db_user) db_pwd=$(ynh_app_setting_get $app mysqlpwd) ynh_mysql_setup_db "$db_user" "$db_name" "$db_pwd" convert_ZabbixDB ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < ./db.sql #================================================= # Restore configs files #================================================= ### `ynh_replace_string` is used to replace a string in a file. ### (It's compatible with sed regular expressions syntax) ynh_restore_file "/usr/share/zabbix/conf/zabbix.conf.php" chown -R www-data. /usr/share/zabbix ynh_restore_file "/etc/zabbix" ls -Rail "/etc/zabbix" #ynh_restore_file "/etc/zabbix/web" #ynh_restore_file "/etc/zabbix/web/init.zabbix.conf.php.sh" ynh_restore_file "/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config" if [ ! -L /etc/zabbix/zabbix_agentd.d ];then ln -s /etc/zabbix/zabbix_agentd.conf.d /etc/zabbix/zabbix_agentd.d fi systemctl enable zabbix-agent && systemctl restart zabbix-agent change_timeoutAgent systemctl enable zabbix-server && systemctl restart zabbix-server yunohost service add snmpd -d "Management of SNMP Daemon" yunohost service add zabbix-server -d "Management Zabbix server daemon : Collect, agregate, compute and notify" yunohost service add zabbix-agent -d "Management Zabbix agent daemon : send informations about this host to the server" #================================================= # SETUP LOGROTATE #================================================= ### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app. ### Use this helper only if there is effectively a log file for this app. ### If you're not using this helper: ### - Remove the section "BACKUP LOGROTATE" in the backup script ### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script ### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script ### - And the section "SETUP LOGROTATE" in the upgrade script # Use logrotate to manage application logfile(s) #ynh_use_logrotate #no need, use native logrotate in zabbix packages #================================================= # SETUP SSOWAT #================================================= # Make app public if necessary if [ "$is_public" -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. ynh_app_setting_set $app unprotected_uris "/" fi #================================================= # RELOAD NGINX #================================================= systemctl reload nginx systemctl reload php7.0-fpm # Reload SSOwat config yunohost app ssowatconf #test if zabbix server is started check_proc_zabbixagent #test if zabbix agent is started check_proc_zabbixserver