upgrade 5.3 KB

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