upgrade 5.4 KB

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