restore 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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="ynhzabbix"
  24. #=================================================
  25. # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
  26. #=================================================
  27. ### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
  28. ### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
  29. rm -fr /var/www/zabbix
  30. # Normalize the url path syntax
  31. path_url=$(ynh_normalize_url_path $path_url)
  32. # Check web path availability
  33. ynh_webpath_available $domain $path_url
  34. # Register (book) web path
  35. ynh_webpath_register $app $domain $path_url
  36. #=================================================
  37. # STORE SETTINGS FROM MANIFEST
  38. #=================================================
  39. domain=$(ynh_app_setting_get $app domain)
  40. path_url=$(ynh_app_setting_get $app path)
  41. admin=$(ynh_app_setting_get $app admin)
  42. is_public=$(ynh_app_setting_get $app is_public)
  43. language=$(ynh_app_setting_get $app language)
  44. #=================================================
  45. # INSTALL DEPENDENCIES
  46. #=================================================
  47. wget "https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-2+stretch_all.deb"
  48. dpkg -i zabbix-release_*.deb
  49. rm zabbix-release_*.deb
  50. echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list
  51. ynh_package_update
  52. 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
  53. yunohost service add snmpd -d "Management of SNMP Daemon"
  54. DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php
  55. ar x *.deb
  56. tar xzf control.tar.gz
  57. sed -i 's/apache2 | httpd, //' control
  58. tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control
  59. ar rcs zabbix-frontend-php+stretch_all-noapache2.deb debian-binary control.tar.gz data.tar.xz
  60. dpkg -i zabbix-frontend-php+stretch_all-noapache2.deb
  61. rm -fr zabbix-*.deb
  62. ynh_package_install zabbix-server-mysql zabbix-agent
  63. DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php
  64. sed -i "s/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/g" /etc/locale.gen
  65. locale-gen
  66. ln -s /usr/share/zabbix /var/www/zabbix
  67. rm $final_path/conf/zabbix.conf.php
  68. ynh_app_setting_set $app final_path $final_path
  69. #=================================================
  70. # NGINX CONFIGURATION
  71. #=================================================
  72. ### `ynh_add_nginx_config` will use the file conf/nginx.conf
  73. # Create a dedicated nginx config
  74. ynh_restore_file "/usr/share/zabbix/conf/zabbix.conf.php"
  75. #=================================================
  76. # PHP-FPM CONFIGURATION
  77. #=================================================
  78. ynh_restore_file "/etc/php/7.0/fpm/pool.d/ynhzabbix.conf"
  79. # Reload SSOwat config
  80. yunohost app ssowatconf
  81. # Reload Nginx
  82. systemctl reload nginx
  83. # Remove the public access
  84. if [ $is_public -eq 0 ]
  85. then
  86. ynh_app_setting_delete $app skipped_uris
  87. fi
  88. #=================================================
  89. # Restore db
  90. #=================================================
  91. db_name=$(ynh_app_setting_get $app db_name)
  92. db_user=$(ynh_app_setting_get $app db_user)
  93. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  94. ynh_mysql_setup_db $db_user $db_name $db_pwd
  95. ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
  96. #=================================================
  97. # Restore configs files
  98. #=================================================
  99. ### `ynh_replace_string` is used to replace a string in a file.
  100. ### (It's compatible with sed regular expressions syntax)
  101. ynh_restore_file "/usr/share/zabbix/conf/zabbix.conf.php"
  102. chown -R www-data. /usr/share/zabbix
  103. ynh_restore_file "/etc/zabbix"
  104. systemctl enable zabbix-server && systemctl start zabbix-server
  105. #=================================================
  106. # SETUP LOGROTATE
  107. #=================================================
  108. ### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app.
  109. ### Use this helper only if there is effectively a log file for this app.
  110. ### If you're not using this helper:
  111. ### - Remove the section "BACKUP LOGROTATE" in the backup script
  112. ### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script
  113. ### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script
  114. ### - And the section "SETUP LOGROTATE" in the upgrade script
  115. # Use logrotate to manage application logfile(s)
  116. ynh_use_logrotate
  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