restore 6.1 KB

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