restore 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 $final_path
  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_add_nginx_config
  75. #=================================================
  76. # CREATE DEDICATED USER
  77. #=================================================
  78. # Create a system user
  79. #ynh_system_user_create $app
  80. #=================================================
  81. # PHP-FPM CONFIGURATION
  82. #=================================================
  83. ynh_add_fpm_config
  84. # Reload SSOwat config
  85. yunohost app ssowatconf
  86. # Reload Nginx
  87. systemctl reload nginx
  88. # Remove the public access
  89. if [ $is_public -eq 0 ]
  90. then
  91. ynh_app_setting_delete $app skipped_uris
  92. fi
  93. #=================================================
  94. # Restore db
  95. #=================================================
  96. db_name=$(ynh_app_setting_get $app db_name)
  97. db_user=$(ynh_app_setting_get $app db_user)
  98. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  99. ynh_mysql_setup_db $db_user $db_name $db_pwd
  100. ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
  101. #=================================================
  102. # Restore configs files
  103. #=================================================
  104. ### `ynh_replace_string` is used to replace a string in a file.
  105. ### (It's compatible with sed regular expressions syntax)
  106. ynh_restore_file "/usr/share/zabbix/conf/zabbix.conf.php"
  107. chown -R www-data. /usr/share/zabbix
  108. ynh_restore_file "/etc/zabbix"
  109. systemctl enable zabbix-server && systemctl start zabbix-server
  110. #=================================================
  111. # SETUP LOGROTATE
  112. #=================================================
  113. ### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app.
  114. ### Use this helper only if there is effectively a log file for this app.
  115. ### If you're not using this helper:
  116. ### - Remove the section "BACKUP LOGROTATE" in the backup script
  117. ### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script
  118. ### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script
  119. ### - And the section "SETUP LOGROTATE" in the upgrade script
  120. # Use logrotate to manage application logfile(s)
  121. ynh_use_logrotate
  122. #=================================================
  123. # SETUP SSOWAT
  124. #=================================================
  125. # Make app public if necessary
  126. if [ $is_public -eq 1 ]
  127. then
  128. # unprotected_uris allows SSO credentials to be passed anyway.
  129. ynh_app_setting_set $app unprotected_uris "/"
  130. fi
  131. #=================================================
  132. # RELOAD NGINX
  133. #=================================================
  134. systemctl reload nginx