install 5.0 KB

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