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