install 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/bash
  2. #=================================================
  3. # IMPORT GENERIC HELPERS
  4. #=================================================
  5. source _common.sh
  6. source /usr/share/yunohost/helpers
  7. #=================================================
  8. # DOWNLOAD, CHECK AND UNPACK SOURCE
  9. #=================================================
  10. ynh_script_progression --message="Setting up source files..."
  11. chmod -R o-rwx "/usr/share/zabbix"
  12. chown -R "$app:www-data" "/usr/share/zabbix"
  13. #=================================================
  14. # IMPORT DEFAULT DATA
  15. #=================================================
  16. ynh_script_progression --message="Import default data in database..."
  17. export mysqlconn="mysql --user=$db_user --password=$db_pwd --database=$db_name"
  18. $mysqlconn -e "ALTER DATABASE $db_name CHARACTER SET utf8 COLLATE utf8_general_ci;"
  19. zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | $mysqlconn
  20. convert_ZabbixDB
  21. #sso integration
  22. $mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;"
  23. #admin creation
  24. surname=$(ynh_user_get_info "$admin" lastname)
  25. name=$(ynh_user_get_info "$admin" firstname)
  26. $mysqlconn -e "INSERT INTO \`users\` (\`userid\`,\`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES (3,'$admin', '$admin', '$admin', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$language', '30s', 3, 'default', 0, '', 0, 50);"
  27. $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\`, \`usrgrpid\`, \`userid\`) VALUES (5, 7, 3);"
  28. #users creation in zabbix database
  29. i=4
  30. for user in $(ynh_user_list);
  31. do
  32. if [ "$user" != "$admin" ]
  33. then
  34. surname=$(ynh_user_get_info --username="$user" --key=lastname)
  35. name=$(ynh_user_get_info --username="$user" --key=firstname)
  36. $mysqlconn -e "INSERT INTO \`users\` (\`userid\`, \`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES ($i,'$user', '$name', '$surname', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$language', '30s', 1, 'default', 0, '', 0, 50);"
  37. i=$((i+1))
  38. fi
  39. done
  40. disable_guest_user
  41. set_mediatype_default_yunohost
  42. #=================================================
  43. # ADD A CONFIGURATION
  44. #=================================================
  45. ynh_script_progression --message="Adding a configuration file..."
  46. ynh_add_config --template="../conf/etc_zabbix_web_zabbix.conf.php" --destination="/etc/zabbix/web/zabbix.conf.php"
  47. chmod 400 "/etc/zabbix/web/zabbix.conf.php"
  48. chown "$app:www-data" "/etc/zabbix/web/zabbix.conf.php"
  49. ynh_replace_string --match_string="DBName=zabbix" --replace_string="DBName=$db_name" --target_file=/etc/zabbix/zabbix_server.conf
  50. ynh_replace_string --match_string="DBUser=zabbix" --replace_string="DBUser=$db_user" --target_file=/etc/zabbix/zabbix_server.conf
  51. ynh_replace_string --match_string="# DBPassword=" --replace_string="# DBPassword=\nDBPassword=$db_pwd" --target_file=/etc/zabbix/zabbix_server.conf
  52. #=================================================
  53. # SYSTEM CONFIGURATION
  54. #=================================================
  55. ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
  56. ynh_replace_string --match_string="# $language.UTF-8 UTF-8" --replace_string="$language.UTF-8 UTF-8" --target_file=/etc/locale.gen
  57. locale-gen
  58. # Create a dedicated PHP-FPM config
  59. ynh_add_fpm_config
  60. # Create a dedicated NGINX config
  61. ynh_add_nginx_config
  62. change_timeoutAgent
  63. systemctl enable zabbix-agent --quiet
  64. systemctl enable zabbix-server --quiet
  65. yunohost service add snmpd --description="Management of SNMP Daemon"
  66. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  67. 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"
  68. update_initZabbixConf
  69. #=================================================
  70. # SETUP APPLICATION WITH CURL
  71. #=================================================
  72. ynh_script_progression --message="Setting up application with CURL..."
  73. import_template
  74. link_template
  75. disable_admin_user
  76. #=================================================
  77. # START SYSTEMD SERVICE
  78. #=================================================
  79. ynh_script_progression --message="Starting $app's systemd service..."
  80. # Start a systemd service
  81. ynh_systemd_action --service_name="$app-server" --action="restart" --log_path="/var/log/$app/${app}_server.log"
  82. ynh_systemd_action --service_name="$app-agent" --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  83. #=================================================
  84. # END OF SCRIPT
  85. #=================================================
  86. ynh_script_progression --message="Installation of $app completed"