restore 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 --origin_path="/usr/local/bin/$service_name-loadcubefile.sh"
  24. ynh_restore_file --origin_path="/etc/yunohost/hooks.d/90-vpnclient.tpl"
  25. ynh_restore_file --origin_path="/etc/openvpn/client.conf.tpl"
  26. ynh_restore_file --origin_path="/etc/openvpn/client.conf" --not_mandatory
  27. ynh_restore_file --origin_path="/etc/openvpn/client.cube" --not_mandatory
  28. ynh_restore_file --origin_path="/etc/openvpn/client.ovpn" --not_mandatory
  29. ynh_restore_file --origin_path="/etc/openvpn/scripts/route-up.d/10-set-firewall"
  30. ynh_restore_file --origin_path="/etc/openvpn/scripts/route-up.d/20-set-dns"
  31. ynh_restore_file --origin_path="/etc/openvpn/scripts/route-up.d/30-set-server-ipv6-route"
  32. ynh_restore_file --origin_path="/etc/openvpn/scripts/route-up.d/40-set-ipv6"
  33. ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/10-unset-firewall"
  34. ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/20-unset-dns"
  35. ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/30-unset-server-ipv6-route"
  36. ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/40-unset-ipv6"
  37. ynh_restore_file --origin_path="/etc/openvpn/keys/"
  38. ynh_restore_file --origin_path="/etc/openvpn/scripts/run-parts.sh"
  39. ynh_restore_file --origin_path="/usr/local/bin/$service_name"
  40. ynh_restore_file --origin_path="/usr/local/bin/$service_checker_name.sh"
  41. #=================================================
  42. # RECREATE THE DEDICATED USER
  43. #=================================================
  44. ynh_print_info "Recreating the dedicated system user..."
  45. # Create the dedicated user (if not existing)
  46. ynh_system_user_create $app
  47. #=================================================
  48. # SPECIFIC RESTORATION
  49. #=================================================
  50. # REINSTALL DEPENDENCIES
  51. #=================================================
  52. ynh_print_info "Reinstalling dependencies..."
  53. # Define and install dependencies
  54. ynh_install_app_dependencies "$pkg_dependencies"
  55. #=================================================
  56. # RESTORE SYSTEMD
  57. #=================================================
  58. ynh_print_info "Restoring the systemd configuration..."
  59. ynh_restore_file --origin_path="/etc/systemd/system/$service_name.service"
  60. ynh_restore_file --origin_path="/etc/systemd/system/$service_checker_name.service"
  61. ynh_restore_file --origin_path="/etc/systemd/system/$service_checker_name.timer"
  62. ynh_restore_file --origin_path="/etc/systemd/system/openvpn@.service.d/override.conf"
  63. systemctl daemon-reload
  64. systemctl enable "$service_name.service" --quiet
  65. systemctl enable "$service_checker_name.service" --quiet
  66. systemctl enable "openvpn@.service" --quiet
  67. #=================================================
  68. # ADVERTISE SERVICE IN ADMIN PANEL
  69. #=================================================
  70. 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"
  71. #=================================================
  72. # GENERIC FINALIZATION
  73. #=================================================
  74. #=================================================
  75. # END OF SCRIPT
  76. #=================================================
  77. ynh_print_info "Restoration completed for $app"