install 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. ynh_add_config --template="../conf/etc_apt_preferences.d_zabbix" --destination="/etc/apt/preferences.d/zabbix_repo"
  34. chmod 644 "/etc/apt/preferences.d/zabbix_repo"
  35. chmod 400 "/etc/zabbix/web/zabbix.conf.php"
  36. chown "$app:www-data" "/etc/zabbix/web/zabbix.conf.php"
  37. ynh_replace_string --match_string="DBName=zabbix" --replace_string="DBName=$db_name" --target_file=/etc/zabbix/zabbix_server.conf
  38. ynh_replace_string --match_string="DBUser=zabbix" --replace_string="DBUser=$db_user" --target_file=/etc/zabbix/zabbix_server.conf
  39. ynh_replace_string --match_string="# DBPassword=" --replace_string="# DBPassword=\nDBPassword=$db_pwd" --target_file=/etc/zabbix/zabbix_server.conf
  40. #=================================================
  41. # SYSTEM CONFIGURATION
  42. #=================================================
  43. ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
  44. ynh_replace_string --match_string="# ${language}\.UTF-8 UTF-8" --replace_string="${language}\.UTF-8 UTF-8" --target_file=/etc/locale.gen
  45. locale-gen
  46. # Create a PHP-FPM config (with conf/extra_php-fpm.conf being appended to it)
  47. ynh_add_fpm_config
  48. # Create a dedicated NGINX config using the conf/nginx.conf template
  49. ynh_add_nginx_config
  50. change_timeoutAgent
  51. systemctl enable zabbix-agent --quiet
  52. systemctl enable zabbix-server --quiet
  53. yunohost service add snmpd --description="Management of SNMP Daemon"
  54. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  55. 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"
  56. update_initZabbixConf
  57. #=================================================
  58. # SETUP APPLICATION
  59. #=================================================
  60. ynh_script_progression --message="Setting up application..."
  61. ynh_print_info --message="Installing zabbix-cli"
  62. mkdir -p /usr/share/zabbix-cli
  63. python3 -m venv /usr/share/zabbix-cli
  64. /usr/share/zabbix-cli/bin/pip install zabbix-cli-uio
  65. # ldap zabbix user creation
  66. ynh_print_info --message="Creating ldap zabbix user"
  67. yunohost user create "$zabbix_username" --fullname "${zabbix_username//_}" --domain "$domain" --password "$zabbix_password" -q 0
  68. ynh_add_config --template="zabbix-cli_default.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
  69. /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
  70. ynh_add_config --template="zabbix-cli.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
  71. ynh_secure_remove --file="/usr/share/zabbix-cli/.zabbix-cli_auth_token"
  72. # sso integration activation
  73. ynh_print_info --message="Enabling LDAP authentication"
  74. $mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;"
  75. #Ldap integration activation
  76. $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;"
  77. # admin user creation
  78. ynh_print_info --message="Creating admin user"
  79. lastname=$(ynh_user_get_info "$admin" lastname)
  80. firstname=$(ynh_user_get_info "$admin" firstname)
  81. /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
  82. # users creation
  83. ynh_print_info --message="Creating all users"
  84. for user in $(ynh_user_list);
  85. do
  86. if [ "$user" != "$admin" ] && [ "$user" != "$zabbix_username" ] && [ "$user" != "admin" ] && [ "$user" != "guest" ]
  87. then
  88. lastname=$(ynh_user_get_info --username="$user" --key=lastname)
  89. firstname=$(ynh_user_get_info --username="$user" --key=firstname)
  90. /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
  91. fi
  92. done
  93. disable_guest_user
  94. disable_admin_user
  95. set_mediatype_default_yunohost
  96. import_template
  97. link_template
  98. #=================================================
  99. # START SYSTEMD SERVICE
  100. #=================================================
  101. ynh_script_progression --message="Starting $app's systemd service..."
  102. # Start a systemd service
  103. ynh_systemd_action --service_name="$app-server" --action="restart" --log_path="/var/log/$app/${app}_server.log"
  104. ynh_systemd_action --service_name="$app-agent" --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  105. #=================================================
  106. # END OF SCRIPT
  107. #=================================================
  108. ynh_script_progression --message="Installation of $app completed"