upgrade 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. # ENSURE DOWNWARD COMPATIBILITY
  42. #=================================================
  43. ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
  44. #
  45. # N.B. : the followings setting migrations snippets are provided as *EXAMPLES*
  46. # of what you may want to do in some cases (e.g. a setting was not defined on
  47. # some legacy installs and you therefore want to initiaze stuff during upgrade)
  48. #
  49. # If db_name doesn't exist, create it
  50. #if [ -z "$db_name" ]; then
  51. # db_name=$(ynh_sanitize_dbid --db_name=$app)
  52. # ynh_app_setting_set --app=$app --key=db_name --value=$db_name
  53. #fi
  54. # If final_path doesn't exist, create it
  55. #if [ -z "$final_path" ]; then
  56. # final_path=/var/www/$app
  57. # ynh_app_setting_set --app=$app --key=final_path --value=$final_path
  58. #fi
  59. ### If nobody installed your app before 4.1,
  60. ### then you may safely remove these lines
  61. # Cleaning legacy permissions
  62. if ynh_legacy_permissions_exists; then
  63. ynh_legacy_permissions_delete_all
  64. ynh_app_setting_delete --app=$app --key=is_public
  65. fi
  66. if ! ynh_permission_exists --permission="admin"; then
  67. # Create the required permissions
  68. ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
  69. fi
  70. # Create a permission if needed
  71. if ! ynh_permission_exists --permission="api"; then
  72. ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
  73. fi
  74. #=================================================
  75. # CREATE DEDICATED USER
  76. #=================================================
  77. ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
  78. # Create a dedicated user (if not existing)
  79. ynh_system_user_create --username=$app --home_dir="$final_path"
  80. #=================================================
  81. # DOWNLOAD, CHECK AND UNPACK SOURCE
  82. #=================================================
  83. if [ "$upgrade_type" == "UPGRADE_APP" ]
  84. then
  85. ynh_script_progression --message="Upgrading source files..." --weight=1
  86. # Download, check integrity, uncompress and patch the source from app.src
  87. ynh_setup_source --dest_dir="$final_path"
  88. fi
  89. chmod 750 "$final_path"
  90. chmod -R o-rwx "$final_path"
  91. chown -R $app:www-data "$final_path"
  92. #=================================================
  93. # UPGRADE DEPENDENCIES
  94. #=================================================
  95. ynh_script_progression --message="Upgrading dependencies..." --weight=1
  96. # Install Nodejs
  97. ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
  98. # Install Yarn
  99. ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
  100. #=================================================
  101. # NGINX CONFIGURATION
  102. #=================================================
  103. ynh_script_progression --message="Upgrading NGINX web server configuration..." --time --weight=1
  104. # Create a dedicated NGINX config
  105. ynh_add_nginx_config
  106. #=================================================
  107. # SETUP SYSTEMD
  108. #=================================================
  109. ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
  110. # Create a dedicated systemd config
  111. ynh_add_systemd_config
  112. #=================================================
  113. # INTEGRATE SERVICE IN YUNOHOST
  114. #=================================================
  115. ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
  116. yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log"
  117. #=================================================
  118. # START SYSTEMD SERVICE
  119. #=================================================
  120. ynh_script_progression --message="Starting a systemd service..." --weight=1
  121. ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
  122. #=================================================
  123. # RELOAD NGINX
  124. #=================================================
  125. ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  126. ynh_systemd_action --service_name=nginx --action=reload
  127. #=================================================
  128. # END OF SCRIPT
  129. #=================================================
  130. ynh_script_progression --message="Upgrade of $app completed" --last