restore 6.6 KB

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