upgrade 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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..." --time --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)..." --time --weight=1
  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..." --time --weight=1
  39. #
  40. # N.B. : the followings setting migrations snippets are provided as *EXAMPLES*
  41. # of what you may want to do in some cases (e.g. a setting was not defined on
  42. # some legacy installs and you therefore want to initiaze stuff during upgrade)
  43. #
  44. #If db_name doesn't exist, create it
  45. if [ -z "$db_name" ]; then
  46. db_name=$(ynh_sanitize_dbid --db_name=$app)
  47. ynh_app_setting_set --app=$app --key=db_name --value=$db_name
  48. fi
  49. #If final_path doesn't exist, create it
  50. if [ -z "$final_path" ]; then
  51. final_path=/var/www/$app
  52. ynh_app_setting_set --app=$app --key=final_path --value=$final_path
  53. fi
  54. ### If nobody installed your app before 4.1,
  55. ### then you may safely remove these lines
  56. # Cleaning legacy permissions
  57. if ynh_legacy_permissions_exists; then
  58. ynh_legacy_permissions_delete_all
  59. ynh_app_setting_delete --app=$app --key=is_public
  60. fi
  61. #=================================================
  62. # CREATE DEDICATED USER
  63. #=================================================
  64. ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
  65. # Create a dedicated user (if not existing)
  66. ynh_system_user_create --username=$app --home_dir="$final_path"
  67. #=================================================
  68. # DOWNLOAD, CHECK AND UNPACK SOURCE
  69. #=================================================
  70. if [ "$upgrade_type" == "UPGRADE_APP" ]
  71. then
  72. ynh_script_progression --message="Upgrading source files..." --time --weight=1
  73. # Download, check integrity, uncompress and patch the source from app.src
  74. ynh_setup_source --dest_dir="$final_path"
  75. fi
  76. chmod 750 "$final_path"
  77. chmod -R o-rwx "$final_path"
  78. chown -R $app:www-data "$final_path"
  79. #=================================================
  80. # NGINX CONFIGURATION
  81. #=================================================
  82. ynh_script_progression --message="Upgrading NGINX web server configuration..." --time --weight=1
  83. # Create a dedicated NGINX config
  84. ynh_add_nginx_config
  85. #=================================================
  86. # PHP-FPM CONFIGURATION
  87. #=================================================
  88. ynh_script_progression --message="Upgrading PHP-FPM configuration..." --time --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..." --time --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" --time --last