restore 3.4 KB

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