upgrade 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #=================================================
  62. # NGINX CONFIGURATION
  63. #=================================================
  64. ynh_print_info "Upgrading nginx web server configuration..."
  65. # Create a dedicated nginx config
  66. ynh_add_nginx_config
  67. #=================================================
  68. # UPGRADE DEPENDENCIES
  69. #=================================================
  70. ynh_print_info "Upgrading dependencies..."
  71. ynh_install_app_dependencies "$pkg_dependencies" "$packages"
  72. #=================================================
  73. # CREATE DEDICATED USER
  74. #=================================================
  75. ynh_print_info "Making sure dedicated system user exists..."
  76. # Create a dedicated user (if not existing)
  77. ynh_system_user_create $app
  78. #=================================================
  79. # PHP-FPM CONFIGURATION
  80. #=================================================
  81. ynh_print_info "Upgrading php-fpm configuration..."
  82. # Create a dedicated php-fpm config
  83. ynh_add_fpm_config
  84. #=================================================
  85. # SPECIFIC UPGRADE
  86. #=================================================
  87. # FIX CONFIGS
  88. #=================================================
  89. ### 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.
  90. ynh_backup_if_checksum_is_different "$final_path/config.php"
  91. ynh_replace_string "__PATH__" "${path_url}" "$final_path/config.php"
  92. # Recalculate and store the checksum of the file for the next upgrade.
  93. ynh_store_file_checksum "$final_path/config.php"
  94. #=================================================
  95. # SETUP SYSTEMD
  96. #=================================================
  97. ynh_print_info "Upgrading systemd configuration..."
  98. # Create a dedicated systemd config
  99. ynh_add_systemd_config $service_name
  100. # Make sure that the yunohost service has a description and need-lock enabled
  101. yunohost service remove $service_name
  102. yunohost service add $service_name --description "Creates a Wi-Fi access point" --need_lock
  103. yunohost service start $service_name
  104. #=================================================
  105. # GENERIC FINALIZATION
  106. #=================================================
  107. # SECURE FILES AND DIRECTORIES
  108. #=================================================
  109. # Set permissions on app files
  110. chown -R $app: ${final_path}/
  111. chmod -R 0644 ${final_path}/*
  112. find ${final_path}/ -type d -exec chmod +x {} \;
  113. #=================================================
  114. # RELOAD NGINX
  115. #=================================================
  116. ynh_print_info "Reloading nginx web server..."
  117. systemctl restart php7.0-fpm
  118. systemctl reload nginx
  119. #=================================================
  120. # END OF SCRIPT
  121. #=================================================
  122. ynh_print_info "Upgrade of $app completed"