upgrade 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. port=$(ynh_app_setting_get $app port)
  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=$(ynh_sanitize_dbid $app)
  39. ynh_app_setting_set $app final_path $final_path
  40. fi
  41. #=================================================
  42. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  43. #=================================================
  44. ynh_backup_before_upgrade # Backup the current version of the app
  45. ynh_clean_setup () {
  46. ynh_restore_upgradebackup # restore it if the upgrade fails
  47. }
  48. ynh_abort_if_errors # Exit if an error occurs during the execution of the script
  49. #=================================================
  50. # CHECK THE PATH
  51. #=================================================
  52. # Normalize the URL path syntax
  53. path_url=$(ynh_normalize_url_path $path_url)
  54. #=================================================
  55. # STANDARD UPGRADE STEPS
  56. #=================================================
  57. # DOWNLOAD, CHECK AND UNPACK SOURCE
  58. #=================================================
  59. # Download, check integrity, uncompress and patch the source from app.src
  60. ynh_setup_source "$final_path"
  61. #=================================================
  62. # NGINX CONFIGURATION
  63. #=================================================
  64. # Create a dedicated nginx config
  65. ynh_add_nginx_config
  66. #=================================================
  67. # CREATE DEDICATED USER
  68. #=================================================
  69. # Create a system user
  70. ynh_system_user_create $app
  71. #=================================================
  72. # PHP-FPM CONFIGURATION
  73. #=================================================
  74. # Create a dedicated php-fpm config
  75. ynh_add_fpm_config
  76. #=================================================
  77. # SPECIFIC UPGRADE
  78. #=================================================
  79. # ...
  80. #=================================================
  81. # Verify the checksum and backup the file if it's different
  82. ynh_backup_if_checksum_is_different "$final_path/CONFIG_FILE"
  83. # Recalculate and store the config file checksum into the app settings
  84. ynh_store_file_checksum "$final_path/CONFIG_FILE"
  85. #=================================================
  86. # SETUP LOGROTATE
  87. #=================================================
  88. # Use logrotate to manage app-specific logfile(s)
  89. ynh_use_logrotate
  90. #=================================================
  91. # SETUP SYSTEMD
  92. #=================================================
  93. # Create a dedicated systemd config
  94. ynh_systemd_config
  95. #=================================================
  96. # GENERIC FINALIZATION
  97. #=================================================
  98. # SECURE FILES AND DIRECTORIES
  99. #=================================================
  100. # Set right permissions for curl installation
  101. chown -R root: $final_path
  102. #=================================================
  103. # SETUP SSOWAT
  104. #=================================================
  105. if [ $is_public -eq 0 ]
  106. then # Remove the public access
  107. ynh_app_setting_delete $app skipped_uris
  108. fi
  109. # Make app public if necessary
  110. if [ $is_public -eq 1 ]
  111. then
  112. # unprotected_uris allows SSO credentials to be passed anyway
  113. ynh_app_setting_set $app unprotected_uris "/"
  114. fi
  115. #=================================================
  116. # RELOAD NGINX
  117. #=================================================
  118. systemctl reload nginx