upgrade 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. final_path=$(ynh_app_setting_get $app final_path)
  17. firmware_nonfree=$(ynh_app_setting_get $app firmware_nonfree)
  18. packages=$(ynh_app_setting_get $app packages)
  19. #=================================================
  20. # ENSURE DOWNWARD COMPATIBILITY
  21. #=================================================
  22. ynh_print_info "Ensuring downward compatibility..."
  23. # If final_path doesn't exist, create it
  24. if [ -z $final_path ]; then
  25. final_path=/var/www/$app
  26. ynh_app_setting_set $app final_path $final_path
  27. fi
  28. if [ -z $packages ]; then
  29. if [[ $firmware_nonfree -eq 1 ]]; then
  30. packages=$nonfree_packages
  31. else
  32. packages=$free_packages
  33. fi
  34. ynh_app_setting_set $app packages $packages
  35. fi
  36. #=================================================
  37. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  38. #=================================================
  39. ynh_print_info "Backing up the app before upgrading (may take a while)..."
  40. # Backup the current version of the app
  41. ynh_backup_before_upgrade
  42. ynh_clean_setup () {
  43. # restore it if the upgrade fails
  44. ynh_restore_upgradebackup
  45. }
  46. # Exit if an error occurs during the execution of the script
  47. ynh_abort_if_errors
  48. #=================================================
  49. # CHECK THE PATH
  50. #=================================================
  51. # Normalize the URL path syntax
  52. path_url=$(ynh_normalize_url_path $path_url)
  53. #=================================================
  54. # STANDARD UPGRADE STEPS
  55. #=================================================
  56. # DOWNLOAD, CHECK AND UNPACK SOURCE
  57. #=================================================
  58. ynh_print_info "Upgrading source files..."
  59. # Download, check integrity, uncompress and patch the source from app.src
  60. cp -a ../sources/* ${final_path}/
  61. chown -R www-data: ${final_path}/
  62. chmod -R 0644 ${final_path}/*
  63. find ${final_path}/ -type d -exec chmod +x {} \;
  64. #=================================================
  65. # NGINX CONFIGURATION
  66. #=================================================
  67. ynh_print_info "Upgrading nginx web server configuration..."
  68. # Create a dedicated nginx config
  69. ynh_add_nginx_config
  70. #=================================================
  71. # UPGRADE DEPENDENCIES
  72. #=================================================
  73. ynh_print_info "Upgrading dependencies..."
  74. ynh_install_app_dependencies "$pkg_dependencies" "$packages"
  75. #=================================================
  76. # CREATE DEDICATED USER
  77. #=================================================
  78. ynh_print_info "Making sure dedicated system user exists..."
  79. # Create a dedicated user (if not existing)
  80. ynh_system_user_create $app
  81. #=================================================
  82. # PHP-FPM CONFIGURATION
  83. #=================================================
  84. ynh_print_info "Upgrading php-fpm configuration..."
  85. # Create a dedicated php-fpm config
  86. ynh_add_fpm_config
  87. #=================================================
  88. # SPECIFIC UPGRADE
  89. #=================================================
  90. # FIX CONFIGS
  91. #=================================================
  92. ### 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.
  93. ynh_backup_if_checksum_is_different "$final_path/config.php"
  94. ynh_replace_string "__PATH__" "${path_url}" "$final_path/config.php"
  95. # Recalculate and store the checksum of the file for the next upgrade.
  96. ynh_store_file_checksum "$final_path/config.php"
  97. #=================================================
  98. # SETUP SYSTEMD
  99. #=================================================
  100. ynh_print_info "Upgrading systemd configuration..."
  101. # Create a dedicated systemd config
  102. ynh_add_systemd_config $service_name
  103. # Make sure that the yunohost service has a description and need-lock enabled
  104. yunohost service remove $service_name
  105. yunohost service add $service_name --description "Creates a Wi-Fi access point" --need_lock
  106. yunohost service start $service_name
  107. #=================================================
  108. # GENERIC FINALIZATION
  109. #=================================================
  110. # SECURE FILES AND DIRECTORIES
  111. #=================================================
  112. # Set permissions on app files
  113. chown -R www-data: $final_path
  114. #=================================================
  115. # SETUP SSOWAT
  116. #=================================================
  117. ynh_print_info "Upgrading SSOwat configuration..."
  118. #=================================================
  119. # RELOAD NGINX
  120. #=================================================
  121. ynh_print_info "Reloading nginx web server..."
  122. systemctl restart php7.0-fpm
  123. systemctl reload nginx
  124. #=================================================
  125. # END OF SCRIPT
  126. #=================================================
  127. ynh_print_info "Upgrade of $app completed"