upgrade 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. # LOAD SETTINGS
  11. #=================================================
  12. app=$YNH_APP_INSTANCE_NAME
  13. domain=$(ynh_app_setting_get $app domain)
  14. path_url=$(ynh_app_setting_get $app path)
  15. admin=$(ynh_app_setting_get $app admin)
  16. is_public=$(ynh_app_setting_get $app is_public)
  17. final_path=$(ynh_app_setting_get $app final_path)
  18. language=$(ynh_app_setting_get $app language)
  19. db_name=$(ynh_app_setting_get $app db_name)
  20. #=================================================
  21. # ENSURE DOWNWARD COMPATIBILITY
  22. #=================================================
  23. # Fix is_public as a boolean value
  24. if [ "$is_public" = "Yes" ]; then
  25. ynh_app_setting_set $app is_public 1
  26. is_public=1
  27. elif [ "$is_public" = "No" ]; then
  28. ynh_app_setting_set $app is_public 0
  29. is_public=0
  30. fi
  31. # If db_name doesn't exist, create it
  32. if [ -z $db_name ]; then
  33. db_name=$(ynh_sanitize_dbid $app)
  34. ynh_app_setting_set $app db_name $db_name
  35. fi
  36. # If final_path doesn't exist, create it
  37. if [ -z $final_path ]; then
  38. final_path=/var/www/$app
  39. ynh_app_setting_set $app final_path $final_path
  40. fi
  41. #=================================================
  42. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  43. #=================================================
  44. # Backup the current version of the app
  45. ynh_backup_before_upgrade
  46. ynh_clean_setup () {
  47. # restore it if the upgrade fails
  48. ynh_restore_upgradebackup
  49. }
  50. # Exit if an error occurs during the execution of the script
  51. ynh_abort_if_errors
  52. #=================================================
  53. # CHECK THE PATH
  54. #=================================================
  55. # Normalize the URL path syntax
  56. path_url=$(ynh_normalize_url_path $path_url)
  57. #=================================================
  58. # STANDARD UPGRADE STEPS
  59. #=================================================
  60. # DOWNLOAD, CHECK AND UNPACK SOURCE
  61. #=================================================
  62. # Download, check integrity, uncompress and patch the source from app.src
  63. ynh_setup_source "$final_path"
  64. #=================================================
  65. # NGINX CONFIGURATION
  66. #=================================================
  67. # Create a dedicated nginx config
  68. ynh_add_nginx_config
  69. if [ "$path_url" != "/" ]
  70. then
  71. ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
  72. fi
  73. ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
  74. #=================================================
  75. # UPGRADE DEPENDENCIES
  76. #=================================================
  77. ynh_install_app_dependencies deb1 deb2
  78. #=================================================
  79. # CREATE DEDICATED USER
  80. #=================================================
  81. # Create a dedicated user (if not existing)
  82. ynh_system_user_create $app
  83. #=================================================
  84. # PHP-FPM CONFIGURATION
  85. #=================================================
  86. # Create a dedicated php-fpm config
  87. ynh_add_fpm_config
  88. #=================================================
  89. # SPECIFIC UPGRADE
  90. #=================================================
  91. # ...
  92. #=================================================
  93. ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
  94. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
  95. ynh_backup_if_checksum_is_different "$final_path/CONFIG_FILE"
  96. # Recalculate and store the checksum of the file for the next upgrade.
  97. ynh_store_file_checksum "$final_path/CONFIG_FILE"
  98. #=================================================
  99. # SETUP LOGROTATE
  100. #=================================================
  101. # Use logrotate to manage app-specific logfile(s)
  102. ynh_use_logrotate --non-append
  103. #=================================================
  104. # SETUP SYSTEMD
  105. #=================================================
  106. # Create a dedicated systemd config
  107. ynh_add_systemd_config
  108. #=================================================
  109. # GENERIC FINALIZATION
  110. #=================================================
  111. # SECURE FILES AND DIRECTORIES
  112. #=================================================
  113. # Set permissions on app files
  114. chown -R root: $final_path
  115. #=================================================
  116. # SETUP SSOWAT
  117. #=================================================
  118. # Make app public if necessary
  119. if [ $is_public -eq 1 ]
  120. then
  121. # unprotected_uris allows SSO credentials to be passed anyway
  122. ynh_app_setting_set $app unprotected_uris "/"
  123. fi
  124. #=================================================
  125. # RELOAD NGINX
  126. #=================================================
  127. systemctl reload nginx