install 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/bin/bash
  2. # Fix: Zabbix unter Debian 12 & PHP 8.2 / YunoHost zuverlässig installieren
  3. # Diese Module werden von Zabbix für MySQL/MariaDB und PHP 8.2 zwingend benötigt
  4. #apt update
  5. apt install -y php8.2-mysql php8.2-gd php8.2-bcmath php8.2-mbstring php8.2-xml php8.2-ldap php8.2-curl
  6. # Restart von PHP-FPM und NGINX, damit neue Module erkannt werden
  7. systemctl restart php8.2-fpm
  8. systemctl restart nginx
  9. #=================================================
  10. # IMPORT GENERIC HELPERS
  11. #=================================================
  12. source _common.sh
  13. source /usr/share/yunohost/helpers
  14. #=================================================
  15. # INITIALIZE AND STORE SETTINGS
  16. #=================================================
  17. zabbix_username="svc_${app}_ldap"
  18. zabbix_password=$(ynh_string_random --length=32)
  19. ynh_app_setting_set --app="$app" --key=zabbix_username --value="$zabbix_username"
  20. ynh_app_setting_set --app="$app" --key=zabbix_password --value="$zabbix_password"
  21. #=================================================
  22. # DOWNLOAD, CHECK AND UNPACK SOURCE
  23. #=================================================
  24. ynh_script_progression --message="Setting up source files..."
  25. chmod -R o-rwx "/usr/share/zabbix"
  26. chown -R "$app:www-data" "/usr/share/zabbix"
  27. #=================================================
  28. # IMPORT DEFAULT DATA
  29. #=================================================
  30. ynh_script_progression --message="Import default data in database..."
  31. export mysqlconn="mysql --user=$db_user --password=$db_pwd --database=$db_name"
  32. $mysqlconn -e "ALTER DATABASE $db_name CHARACTER SET utf8 COLLATE utf8_general_ci;"
  33. zcat /usr/share/zabbix/sql-scripts/mysql/server.sql.gz | $mysqlconn
  34. convert_ZabbixDB
  35. #=================================================
  36. # APP INITIAL CONFIGURATION
  37. #=================================================
  38. ynh_script_progression --message="Adding $app's configuration files..."
  39. ynh_add_config --template="../conf/etc_zabbix_web_zabbix.conf.php" --destination="/etc/zabbix/web/zabbix.conf.php"
  40. ynh_add_config --template="../conf/etc_apt_preferences.d_zabbix" --destination="/etc/apt/preferences.d/zabbix_repo"
  41. chmod 644 "/etc/apt/preferences.d/zabbix_repo"
  42. chmod 400 "/etc/zabbix/web/zabbix.conf.php"
  43. chown "$app:www-data" "/etc/zabbix/web/zabbix.conf.php"
  44. ynh_replace_string --match_string="DBName=zabbix" --replace_string="DBName=$db_name" --target_file="/etc/zabbix/zabbix_server.conf"
  45. ynh_replace_string --match_string="DBUser=zabbix" --replace_string="DBUser=$db_user" --target_file="/etc/zabbix/zabbix_server.conf"
  46. ynh_replace_string --match_string="# DBPassword=" --replace_string="# DBPassword=\nDBPassword=$db_pwd" --target_file="/etc/zabbix/zabbix_server.conf"
  47. #=================================================
  48. # SYSTEM CONFIGURATION
  49. #=================================================
  50. ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
  51. ynh_replace_string --match_string="# ${language}\.UTF-8 UTF-8" --replace_string="${language}\.UTF-8 UTF-8" --target_file="/etc/locale.gen"
  52. locale-gen
  53. # Create a PHP-FPM config (with conf/extra_php-fpm.conf being appended to it)
  54. ynh_add_fpm_config
  55. # Create a dedicated NGINX config using the conf/nginx.conf template
  56. ynh_add_nginx_config
  57. change_timeoutAgent
  58. systemctl enable zabbix-agent --quiet
  59. systemctl enable zabbix-server --quiet
  60. yunohost service add snmpd --description="Management of SNMP Daemon"
  61. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  62. yunohost service add zabbix-agent --description="Management Zabbix agent daemon : send informations about this host to the server" --log="/var/log/$app/${app}_agent.log"
  63. update_initZabbixConf
  64. #=================================================
  65. # SETUP APPLICATION
  66. #=================================================
  67. ynh_script_progression --message="Setting up application..."
  68. ynh_print_info --message="Installing zabbix-cli"
  69. mkdir -p /usr/share/zabbix-cli
  70. python3 -m venv /usr/share/zabbix-cli
  71. /usr/share/zabbix-cli/bin/pip install zabbix-cli-uio
  72. # ldap zabbix user creation
  73. ynh_print_info --message="Creating ldap zabbix user"
  74. yunohost user create "$zabbix_username" --fullname "${zabbix_username//_}" --domain "$domain" --password "$zabbix_password" -q 0
  75. ynh_add_config --template="zabbix-cli_default.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
  76. /usr/share/zabbix-cli/bin/zabbix-cli --config "/usr/share/zabbix-cli/zabbix-cli.toml" create_user "$zabbix_username" --firstname "$zabbix_username" --lastname "$zabbix_username" --passwd "$zabbix_password" --role superadmin --groups 7
  77. ynh_add_config --template="zabbix-cli.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
  78. ynh_secure_remove --file="/usr/share/zabbix-cli/.zabbix-cli_auth_token"
  79. # sso integration activation
  80. ynh_print_info --message="Enabling LDAP authentication"
  81. $mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;"
  82. #Ldap integration activation
  83. $mysqlconn -e "INSERT INTO \`userdirectory\` (\`userdirectoryid\`,\`name\`, \`description\`, \`idp_type\`, \`provision_status\`) VALUES (1,'localhost', '', '1', '0');"
  84. $mysqlconn -e "INSERT INTO \`userdirectory_ldap\` (\`userdirectoryid\`,\`host\`, \`port\`, \`base_dn\`, \`search_attribute\`, \`bind_dn\`, \`bind_password\`, \`start_tls\`, \`search_filter\`, \`group_basedn\`, \`group_name\`, \`group_member\`, \`user_ref_attr\`, \`group_filter\`, \`group_membership\`, \`user_username\`, \`user_lastname\`) VALUES (1,'127.0.0.1', '389', 'ou=users,dc=yunohost,dc=org', 'uid', '', '', '0', '', '', '', '', '', '', '', '', '');"
  85. $mysqlconn -e "UPDATE \`config\` SET \`authentication_type\` = '1', \`ldap_auth_enabled\` = '1', \`ldap_userdirectoryid\` = '1' WHERE \`config\`.\`configid\` = 1;"
  86. # admin user creation
  87. ynh_print_info --message="Creating admin user"
  88. lastname=$(ynh_user_get_info "$admin" lastname)
  89. firstname=$(ynh_user_get_info "$admin" firstname)
  90. /usr/share/zabbix-cli/bin/zabbix-cli --config /usr/share/zabbix-cli/zabbix-cli.toml create_user "$admin" --firstname "$firstname" --lastname "$lastname" --role superadmin --groups 7
  91. # users creation
  92. ynh_print_info --message="Creating all users"
  93. for user in $(ynh_user_list);
  94. do
  95. if [ "$user" != "$admin" ] && [ "$user" != "$zabbix_username" ] && [ "$user" != "admin" ] && [ "$user" != "guest" ]
  96. then
  97. lastname=$(ynh_user_get_info --username="$user" --key=lastname)
  98. firstname=$(ynh_user_get_info --username="$user" --key=firstname)
  99. /usr/share/zabbix-cli/bin/zabbix-cli --config /usr/share/zabbix-cli/zabbix-cli.toml create_user $user --firstname $firstname --lastname $lastname --role user --groups 8
  100. fi
  101. done
  102. disable_guest_user
  103. disable_admin_user
  104. set_mediatype_default_yunohost
  105. import_template
  106. link_template
  107. #=================================================
  108. # START SYSTEMD SERVICE
  109. #=================================================
  110. ynh_script_progression --message="Starting $app's systemd service..."
  111. # Start a systemd service
  112. ynh_systemd_action --service_name="$app-server" --action="restart" --log_path="/var/log/$app/${app}_server.log"
  113. ynh_systemd_action --service_name="$app-agent" --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  114. #=================================================
  115. # END OF SCRIPT
  116. #=================================================
  117. ynh_script_progression --message="Installation of $app completed"