upgrade 4.8 KB

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