restore 3.5 KB

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