install 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/bash
  2. #=================================================
  3. # IMPORT GENERIC HELPERS
  4. #=================================================
  5. source _common.sh
  6. source /usr/share/yunohost/helpers
  7. #=================================================
  8. # INITIALIZE AND STORE SETTINGS
  9. #=================================================
  10. zabbix_username="svc_${app}_ldap"
  11. zabbix_password=$(ynh_string_random --length=32)
  12. ynh_app_setting_set --app="$app" --key=zabbix_username --value="$zabbix_username"
  13. ynh_app_setting_set --app="$app" --key=zabbix_password --value="$zabbix_password"
  14. #=================================================
  15. # DOWNLOAD, CHECK AND UNPACK SOURCE
  16. #=================================================
  17. ynh_script_progression --message="Setting up source files..."
  18. chmod -R o-rwx "/usr/share/zabbix"
  19. chown -R "$app:www-data" "/usr/share/zabbix"
  20. #=================================================
  21. # IMPORT DEFAULT DATA
  22. #=================================================
  23. ynh_script_progression --message="Import default data in database..."
  24. export mysqlconn="mysql --user=$db_user --password=$db_pwd --database=$db_name"
  25. $mysqlconn -e "ALTER DATABASE $db_name CHARACTER SET utf8 COLLATE utf8_general_ci;"
  26. zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | $mysqlconn
  27. convert_ZabbixDB
  28. #=================================================
  29. # APP INITIAL CONFIGURATION
  30. #=================================================
  31. ynh_script_progression --message="Adding $app's configuration files..."
  32. ynh_add_config --template="../conf/etc_zabbix_web_zabbix.conf.php" --destination="/etc/zabbix/web/zabbix.conf.php"
  33. chmod 400 "/etc/zabbix/web/zabbix.conf.php"
  34. chown "$app:www-data" "/etc/zabbix/web/zabbix.conf.php"
  35. ynh_replace_string --match_string="DBName=zabbix" --replace_string="DBName=$db_name" --target_file=/etc/zabbix/zabbix_server.conf
  36. ynh_replace_string --match_string="DBUser=zabbix" --replace_string="DBUser=$db_user" --target_file=/etc/zabbix/zabbix_server.conf
  37. ynh_replace_string --match_string="# DBPassword=" --replace_string="# DBPassword=\nDBPassword=$db_pwd" --target_file=/etc/zabbix/zabbix_server.conf
  38. #=================================================
  39. # SYSTEM CONFIGURATION
  40. #=================================================
  41. ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
  42. ynh_replace_string --match_string="# $language.UTF-8 UTF-8" --replace_string="$language.UTF-8 UTF-8" --target_file=/etc/locale.gen
  43. locale-gen
  44. # Create a PHP-FPM config (with conf/extra_php-fpm.conf being appended to it)
  45. ynh_add_fpm_config
  46. # Create a dedicated NGINX config using the conf/nginx.conf template
  47. ynh_add_nginx_config
  48. change_timeoutAgent
  49. systemctl enable zabbix-agent --quiet
  50. systemctl enable zabbix-server --quiet
  51. yunohost service add snmpd --description="Management of SNMP Daemon"
  52. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  53. 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"
  54. update_initZabbixConf
  55. #=================================================
  56. # SETUP APPLICATION
  57. #=================================================
  58. ynh_script_progression --message="Setting up application..."
  59. mkdir -p /usr/share/zabbix-cli
  60. python3 -m venv /usr/share/zabbix-cli
  61. /usr/share/zabbix-cli/bin/pip install zabbix-cli-uio
  62. #ldap zabbix user creation in zabbix database
  63. yunohost user create "$zabbix_username" --fullname "${zabbix_username//_}" --domain "$domain" --password "$zabbix_password" -q 0
  64. ynh_add_config --template="zabbix-cli_default.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
  65. /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
  66. ynh_add_config --template="zabbix-cli.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
  67. #sso integration activation
  68. $mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;"
  69. #Ldap integration activation
  70. $mysqlconn -e "UPDATE \`config\` SET \`authentication_type\` = '1', \`ldap_host\` = '127.0.0.1', \`ldap_port\` = '389', \`ldap_base_dn\` = 'ou=users,dc=yunohost,dc=org', \`ldap_search_attribute\` = 'uid' WHERE \`config\`.\`configid\` = 1;"
  71. #admin creation in zabbix database
  72. lastname=$(ynh_user_get_info "$admin" lastname)
  73. firstname=$(ynh_user_get_info "$admin" firstname)
  74. /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
  75. #users creation in zabbix database
  76. for user in $(ynh_user_list);
  77. do
  78. if [ "$user" != "$admin" ] && [ "$user" != "$zabbix_username" ] && [ "$user" != "admin" ] && [ "$user" != "guest" ]
  79. then
  80. lastname=$(ynh_user_get_info --username="$user" --key=lastname)
  81. firstname=$(ynh_user_get_info --username="$user" --key=firstname)
  82. /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
  83. fi
  84. done
  85. disable_guest_user
  86. disable_admin_user
  87. set_mediatype_default_yunohost
  88. import_template
  89. link_template
  90. #=================================================
  91. # START SYSTEMD SERVICE
  92. #=================================================
  93. ynh_script_progression --message="Starting $app's systemd service..."
  94. # Start a systemd service
  95. ynh_systemd_action --service_name="$app-server" --action="restart" --log_path="/var/log/$app/${app}_server.log"
  96. ynh_systemd_action --service_name="$app-agent" --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  97. #=================================================
  98. # END OF SCRIPT
  99. #=================================================
  100. ynh_script_progression --message="Installation of $app completed"