upgrade 4.4 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..." --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. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  17. #=================================================
  18. # CHECK VERSION
  19. #=================================================
  20. upgrade_type=$(ynh_check_app_version_changed)
  21. #=================================================
  22. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  23. #=================================================
  24. ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
  25. # Backup the current version of the app
  26. ynh_backup_before_upgrade
  27. ynh_clean_setup () {
  28. # Restore it if the upgrade fails
  29. ynh_restore_upgradebackup
  30. }
  31. # Exit if an error occurs during the execution of the script
  32. ynh_abort_if_errors
  33. #=================================================
  34. # STANDARD UPGRADE STEPS
  35. #=================================================
  36. # STOP SYSTEMD SERVICE
  37. #=================================================
  38. ynh_script_progression --message="Stopping a systemd service..." --weight=1
  39. ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
  40. #=================================================
  41. # CREATE DEDICATED USER
  42. #=================================================
  43. ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
  44. # Create a dedicated user (if not existing)
  45. ynh_system_user_create --username=$app --home_dir="$final_path"
  46. #=================================================
  47. # DOWNLOAD, CHECK AND UNPACK SOURCE
  48. #=================================================
  49. if [ "$upgrade_type" == "UPGRADE_APP" ]
  50. then
  51. ynh_script_progression --message="Upgrading source files..." --weight=1
  52. # Download, check integrity, uncompress and patch the source from app.src
  53. ynh_setup_source --dest_dir="$final_path"
  54. fi
  55. chmod 750 "$final_path"
  56. chmod -R o-rwx "$final_path"
  57. chown -R $app:www-data "$final_path"
  58. #=================================================
  59. # UPGRADE DEPENDENCIES
  60. #=================================================
  61. ynh_script_progression --message="Upgrading dependencies..." --weight=1
  62. # Install Nodejs
  63. ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
  64. # Install Yarn
  65. ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
  66. #=================================================
  67. # NGINX CONFIGURATION
  68. #=================================================
  69. ynh_script_progression --message="Upgrading NGINX web server configuration..." --time --weight=1
  70. # Create a dedicated NGINX config
  71. ynh_add_nginx_config
  72. #=================================================
  73. # SETUP SYSTEMD
  74. #=================================================
  75. ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
  76. env_path="$PATH"
  77. # Create a dedicated systemd config
  78. ynh_add_systemd_config
  79. #=================================================
  80. # INTEGRATE SERVICE IN YUNOHOST
  81. #=================================================
  82. ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
  83. yunohost service add $app --description="Customizable browser's home page" --log="/var/log/$app/$app.log"
  84. #=================================================
  85. # START SYSTEMD SERVICE
  86. #=================================================
  87. ynh_script_progression --message="Starting a systemd service..." --weight=1
  88. ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
  89. #=================================================
  90. # RELOAD NGINX
  91. #=================================================
  92. ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  93. ynh_systemd_action --service_name=nginx --action=reload
  94. #=================================================
  95. # END OF SCRIPT
  96. #=================================================
  97. ynh_script_progression --message="Upgrade of $app completed" --last