restore 3.0 KB

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