restore 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source ../settings/scripts/_common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # MANAGE SCRIPT FAILURE
  11. #=================================================
  12. # Exit if an error occurs during the execution of the script
  13. ynh_abort_if_errors
  14. #=================================================
  15. # LOAD SETTINGS
  16. #=================================================
  17. ynh_print_info "Loading settings..."
  18. app=$YNH_APP_INSTANCE_NAME
  19. #=================================================
  20. # RESTORE THE APP MAIN DIR
  21. #=================================================
  22. ynh_print_info "Restoring the app files..."
  23. ynh_restore_file "/usr/local/bin/$service_name-loadcubefile.sh"
  24. ynh_restore_file "/etc/yunohost/hooks.d/90-vpnclient.tpl"
  25. ynh_restore_file "/etc/openvpn/client.conf.tpl"
  26. ynh_restore_file "/etc/openvpn/keys/"
  27. ynh_restore_file "/usr/local/bin/$service_name"
  28. ynh_restore_file "/usr/local/bin/$service_checker_name.sh"
  29. #=================================================
  30. # RECREATE THE DEDICATED USER
  31. #=================================================
  32. ynh_print_info "Recreating the dedicated system user..."
  33. # Create the dedicated user (if not existing)
  34. ynh_system_user_create $app
  35. #=================================================
  36. # SPECIFIC RESTORATION
  37. #=================================================
  38. # REINSTALL DEPENDENCIES
  39. #=================================================
  40. ynh_print_info "Reinstalling dependencies..."
  41. # Define and install dependencies
  42. ynh_install_app_dependencies "$pkg_dependencies"
  43. #=================================================
  44. # RESTORE SYSTEMD
  45. #=================================================
  46. ynh_print_info "Restoring the systemd configuration..."
  47. ynh_restore_file "/etc/systemd/system/$service_name.service"
  48. ynh_restore_file "/etc/systemd/system/$service_checker_name.service"
  49. ynh_restore_file "/etc/systemd/system/$service_checker_name.timer"
  50. ynh_restore_file "/etc/systemd/system/openvpn@.service.d/ovveride.conf"
  51. systemctl daemon-reload
  52. systemctl enable "$service_name.service" --quiet
  53. systemctl enable "$service_checker_name.service" --quiet
  54. systemctl enable "openvpn@.service" --quiet
  55. #=================================================
  56. # ADVERTISE SERVICE IN ADMIN PANEL
  57. #=================================================
  58. yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock --test_status="systemctl is-active openvpn@client.service" --log "/var/log/ynh-vpnclient.log"
  59. #=================================================
  60. # GENERIC FINALIZATION
  61. #=================================================
  62. #=================================================
  63. # END OF SCRIPT
  64. #=================================================
  65. ynh_print_info "Restoration completed for $app"