upgrade 4.5 KB

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