restore 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. final_path=$(ynh_app_setting_get $app final_path)
  20. #=================================================
  21. # CHECK IF THE APP CAN BE RESTORED
  22. #=================================================
  23. ynh_print_info "Validating restoration parameters..."
  24. test ! -d $final_path \
  25. || ynh_die "There is already a directory: $final_path "
  26. #=================================================
  27. # STANDARD RESTORATION STEPS
  28. #=================================================
  29. #=================================================
  30. # RESTORE THE APP MAIN DIR
  31. #=================================================
  32. ynh_print_info "Restoring the app main directory..."
  33. ynh_restore_file "$final_path"
  34. ynh_restore_file "/usr/local/bin/$service_name-loadcubefile.sh"
  35. ynh_restore_file "/etc/yunohost/hooks.d/90-vpnclient.tpl"
  36. ynh_restore_file "/etc/openvpn/client.conf.tpl"
  37. ynh_restore_file "/etc/openvpn/client.conf.tpl.restore"
  38. ynh_restore_file "/etc/openvpn/keys/"
  39. ynh_restore_file "/usr/local/bin/$service_name"
  40. ynh_restore_file "/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. # RESTORE USER RIGHTS
  49. #=================================================
  50. # Restore permissions on app files
  51. chown -R $app: $final_path
  52. #=================================================
  53. # SPECIFIC RESTORATION
  54. #=================================================
  55. # REINSTALL DEPENDENCIES
  56. #=================================================
  57. ynh_print_info "Reinstalling dependencies..."
  58. # Define and install dependencies
  59. ynh_install_app_dependencies "$pkg_dependencies"
  60. #=================================================
  61. # RESTORE SYSTEMD
  62. #=================================================
  63. ynh_print_info "Restoring the systemd configuration..."
  64. ynh_restore_file "/etc/systemd/system/$service_name.service"
  65. ynh_restore_file "/etc/systemd/system/$service_checker_name.service"
  66. ynh_restore_file "/etc/systemd/system/$service_checker_name.timer"
  67. ynh_restore_file "/etc/systemd/system/openvpn@.service"
  68. systemctl daemon-reload
  69. systemctl enable "$service_name.service" --quiet
  70. systemctl enable "$service_checker_name.service" --quiet
  71. systemctl enable "openvpn@.service" --quiet
  72. #=================================================
  73. # ADVERTISE SERVICE IN ADMIN PANEL
  74. #=================================================
  75. 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"
  76. #=================================================
  77. # GENERIC FINALIZATION
  78. #=================================================
  79. #=================================================
  80. # END OF SCRIPT
  81. #=================================================
  82. ynh_print_info "Restoration completed for $app"