upgrade 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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_script_progression --message="Loading installation settings..." --weight=1
  13. app=$YNH_APP_INSTANCE_NAME
  14. domain=$(ynh_app_setting_get --app=$app --key=domain)
  15. path_url=$(ynh_app_setting_get --app=$app --key=path)
  16. admin=$(ynh_app_setting_get --app=$app --key=admin)
  17. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  18. db_name=$(ynh_app_setting_get --app=$app --key=db_name)
  19. #=================================================
  20. # CHECK VERSION
  21. #=================================================
  22. upgrade_type=$(ynh_check_app_version_changed)
  23. #=================================================
  24. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  25. #=================================================
  26. ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=6
  27. # Backup the current version of the app
  28. ynh_backup_before_upgrade
  29. ynh_clean_setup () {
  30. # Restore it if the upgrade fails
  31. ynh_restore_upgradebackup
  32. }
  33. # Exit if an error occurs during the execution of the script
  34. ynh_abort_if_errors
  35. #=================================================
  36. # ENSURE DOWNWARD COMPATIBILITY
  37. #=================================================
  38. ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
  39. #If db_name doesn't exist, create it
  40. if [ -z "$db_name" ]; then
  41. db_name=$(ynh_sanitize_dbid --db_name=$app)
  42. ynh_app_setting_set --app=$app --key=db_name --value=$db_name
  43. fi
  44. #If final_path doesn't exist, create it
  45. if [ -z "$final_path" ]; then
  46. final_path=/var/www/$app
  47. ynh_app_setting_set --app=$app --key=final_path --value=$final_path
  48. fi
  49. ### If nobody installed your app before 4.1,
  50. ### then you may safely remove these lines
  51. # Cleaning legacy permissions
  52. if ynh_legacy_permissions_exists; then
  53. ynh_legacy_permissions_delete_all
  54. ynh_app_setting_delete --app=$app --key=is_public
  55. fi
  56. #=================================================
  57. # CREATE DEDICATED USER
  58. #=================================================
  59. ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
  60. # Create a dedicated user (if not existing)
  61. ynh_system_user_create --username=$app --home_dir="$final_path"
  62. #=================================================
  63. # DOWNLOAD, CHECK AND UNPACK SOURCE
  64. #=================================================
  65. if [ "$upgrade_type" == "UPGRADE_APP" ]
  66. then
  67. ynh_script_progression --message="Upgrading source files..." --weight=3
  68. # Download, check integrity, uncompress and patch the source from app.src
  69. ynh_setup_source --dest_dir="$final_path"
  70. fi
  71. chmod 750 "$final_path"
  72. chmod -R o-rwx "$final_path"
  73. chown -R $app:www-data "$final_path"
  74. #=================================================
  75. # NGINX CONFIGURATION
  76. #=================================================
  77. ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
  78. # Create a dedicated NGINX config
  79. ynh_add_nginx_config
  80. #=================================================
  81. # UPGRADE DEPENDENCIES
  82. #=================================================
  83. ynh_script_progression --message="Upgrading dependencies..." --weight=1
  84. ynh_install_app_dependencies $pkg_dependencies
  85. #=================================================
  86. # PHP-FPM CONFIGURATION
  87. #=================================================
  88. ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1
  89. # Create a dedicated PHP-FPM config
  90. ynh_add_fpm_config
  91. #=================================================
  92. # RELOAD NGINX
  93. #=================================================
  94. ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  95. ynh_systemd_action --service_name=nginx --action=reload
  96. #=================================================
  97. # END OF SCRIPT
  98. #=================================================
  99. ynh_script_progression --message="Upgrade of $app completed" --last