upgrade 5.3 KB

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