restore 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
  8. source ../settings/scripts/_common.sh
  9. source /usr/share/yunohost/helpers
  10. #=================================================
  11. # MANAGE SCRIPT FAILURE
  12. #=================================================
  13. ynh_clean_setup () {
  14. #### Remove this function if there's nothing to clean before calling the remove script.
  15. true
  16. }
  17. # Exit if an error occurs during the execution of the script
  18. ynh_abort_if_errors
  19. #=================================================
  20. # LOAD SETTINGS
  21. #=================================================
  22. ynh_script_progression --message="Loading installation settings..." --weight=1
  23. app=$YNH_APP_INSTANCE_NAME
  24. domain=$(ynh_app_setting_get --app=$app --key=domain)
  25. path_url=$(ynh_app_setting_get --app=$app --key=path)
  26. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  27. #=================================================
  28. # CHECK IF THE APP CAN BE RESTORED
  29. #=================================================
  30. ynh_script_progression --message="Validating restoration parameters..." --weight=1
  31. test ! -d $final_path \
  32. || ynh_die --message="There is already a directory: $final_path "
  33. #=================================================
  34. # STANDARD RESTORATION STEPS
  35. #=================================================
  36. # RECREATE THE DEDICATED USER
  37. #=================================================
  38. ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
  39. # Create the dedicated user (if not existing)
  40. ynh_system_user_create --username=$app --home_dir="$final_path"
  41. #=================================================
  42. # RESTORE THE APP MAIN DIR
  43. #=================================================
  44. ynh_script_progression --message="Restoring the app main directory..." --weight=1
  45. ynh_restore_file --origin_path="$final_path"
  46. chmod 750 "$final_path"
  47. chmod -R o-rwx "$final_path"
  48. chown -R $app:www-data "$final_path"
  49. #=================================================
  50. # SPECIFIC RESTORATION
  51. #=================================================
  52. # REINSTALL DEPENDENCIES
  53. #=================================================
  54. ynh_script_progression --message="Reinstalling dependencies..." --weight=1
  55. # Install Nodejs
  56. ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
  57. # Install Yarn
  58. ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
  59. #=================================================
  60. # RESTORE THE NGINX CONFIGURATION
  61. #=================================================
  62. ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
  63. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
  64. #=================================================
  65. # RESTORE SYSTEMD
  66. #=================================================
  67. ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
  68. ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
  69. systemctl enable $app.service --quiet
  70. #=================================================
  71. # INTEGRATE SERVICE IN YUNOHOST
  72. #=================================================
  73. ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
  74. yunohost service add $app --description="Customizable browser's home page" --log="/var/log/$app/$app.log"
  75. #=================================================
  76. # START SYSTEMD SERVICE
  77. #=================================================
  78. ynh_script_progression --message="Starting a systemd service..." --weight=1
  79. ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
  80. #=================================================
  81. # GENERIC FINALIZATION
  82. #=================================================
  83. # RELOAD NGINX AND PHP-FPM
  84. #=================================================
  85. ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  86. ynh_systemd_action --service_name=nginx --action=reload
  87. #=================================================
  88. # END OF SCRIPT
  89. #=================================================
  90. ynh_script_progression --message="Restoration completed for $app" --last