restore 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # MANAGE SCRIPT FAILURE
  11. #=================================================
  12. # Exit if an error occurs during the execution of the script
  13. ynh_abort_if_errors
  14. ### If it's a multi-instance app, meaning it can be installed several times independently
  15. ### The id of the app as stated in the manifest is available as $YNH_APP_ID
  16. ### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
  17. ### The app instance name is available as $YNH_APP_INSTANCE_NAME
  18. ### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
  19. ### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
  20. ### - ynhexample__{N} for the subsequent installations, with N=3,4, ...
  21. ### The app instance name is probably what interests you most, since this is
  22. ### guaranteed to be unique. This is a good unique identifier to define installation path,
  23. ### db names, ...
  24. app="zabbix"
  25. final_path="/var/www/zabbix"
  26. #=================================================
  27. # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
  28. #=================================================
  29. ### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
  30. ### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
  31. rm -fr $final_path
  32. #=================================================
  33. # STORE SETTINGS FROM MANIFEST
  34. #=================================================
  35. domain=$(ynh_app_setting_get $app domain)
  36. #path_url=$(ynh_app_setting_get $app path) #not used
  37. #admin=$(ynh_app_setting_get $app admin) #not used
  38. is_public=$(ynh_app_setting_get $app is_public)
  39. #language=$(ynh_app_setting_get $app language) #not used
  40. #=================================================
  41. # INSTALL DEPENDENCIES
  42. #=================================================
  43. wget "https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-2+stretch_all.deb"
  44. dpkg -i zabbix-release_*.deb
  45. rm zabbix-release_*.deb
  46. echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list
  47. ynh_package_update
  48. ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype zabbix-server-mysql zabbix-agent
  49. yunohost service add snmpd -d "Management of SNMP Daemon"
  50. DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php
  51. ar x ./*.deb
  52. tar xzf control.tar.gz
  53. ynh_replace_string "apache2 | httpd, " "" control
  54. tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control
  55. ar rcs zabbix-frontend-php+stretch_all-noapache2.deb debian-binary control.tar.gz data.tar.xz
  56. dpkg -i zabbix-frontend-php+stretch_all-noapache2.deb
  57. rm -fr zabbix-*.deb
  58. DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php
  59. ynh_replace_string "# fr_FR.UTF-8 UTF-8" "fr_FR.UTF-8 UTF-8" /etc/locale.gen
  60. locale-gen
  61. ln -s /usr/share/zabbix /var/www/zabbix
  62. rm $final_path/conf/zabbix.conf.php
  63. ynh_app_setting_set $app final_path $final_path
  64. yunohost service add zabbix-server -d "Management of Zabbix Server - Monitoring server"
  65. yunohost service add zabbix-agent -d "Management of Zabbix Agent"
  66. #=================================================
  67. # NGINX CONFIGURATION
  68. #=================================================
  69. ### `ynh_add_nginx_config` will use the file conf/nginx.conf
  70. # Create a dedicated nginx config
  71. ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
  72. #=================================================
  73. # PHP-FPM CONFIGURATION
  74. #=================================================
  75. ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
  76. # Restore sudo file
  77. ynh_restore_file "/etc/sudoers.d/zabbix"
  78. # Reload SSOwat config
  79. yunohost app ssowatconf
  80. # Reload Nginx
  81. systemctl reload nginx
  82. # Remove the public access
  83. if [ "$is_public" -eq 0 ]
  84. then
  85. ynh_app_setting_delete $app skipped_uris
  86. fi
  87. #=================================================
  88. # Restore db
  89. #=================================================
  90. db_name=$(ynh_app_setting_get $app db_name)
  91. db_user=$(ynh_app_setting_get $app db_user)
  92. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  93. ynh_mysql_setup_db "$db_user" "$db_name" "$db_pwd"
  94. ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < ./db.sql
  95. #=================================================
  96. # Restore configs files
  97. #=================================================
  98. ### `ynh_replace_string` is used to replace a string in a file.
  99. ### (It's compatible with sed regular expressions syntax)
  100. ynh_restore_file "/usr/share/zabbix/conf/zabbix.conf.php"
  101. chown -R www-data. /usr/share/zabbix
  102. ynh_restore_file "/etc/zabbix"
  103. systemctl enable zabbix-server && systemctl start zabbix-server
  104. #=================================================
  105. # SETUP LOGROTATE
  106. #=================================================
  107. ### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app.
  108. ### Use this helper only if there is effectively a log file for this app.
  109. ### If you're not using this helper:
  110. ### - Remove the section "BACKUP LOGROTATE" in the backup script
  111. ### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script
  112. ### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script
  113. ### - And the section "SETUP LOGROTATE" in the upgrade script
  114. # Use logrotate to manage application logfile(s)
  115. #ynh_use_logrotate
  116. #no need, use native logrotate in zabbix packages
  117. #=================================================
  118. # SETUP SSOWAT
  119. #=================================================
  120. # Make app public if necessary
  121. if [ "$is_public" -eq 1 ]
  122. then
  123. # unprotected_uris allows SSO credentials to be passed anyway.
  124. ynh_app_setting_set $app unprotected_uris "/"
  125. fi
  126. #=================================================
  127. # RELOAD NGINX
  128. #=================================================
  129. systemctl reload nginx
  130. systemctl reload php7.0-fpm