restore 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "/etc/sudoers.d/${app}_ynh"
  35. ynh_restore_file "/usr/local/bin/$service_name-loadcubefile.sh"
  36. ynh_restore_file "/etc/yunohost/hooks.d/90-vpnclient.tpl"
  37. ynh_restore_file "/etc/openvpn/client.conf.tpl"
  38. ynh_restore_file "/etc/openvpn/client.conf.tpl.restore"
  39. ynh_restore_file "/etc/openvpn/keys/"
  40. ynh_restore_file "/usr/local/bin/$service_name"
  41. ynh_restore_file "/usr/local/bin/$service_checker_name.sh"
  42. #=================================================
  43. # RECREATE THE DEDICATED USER
  44. #=================================================
  45. ynh_print_info "Recreating the dedicated system user..."
  46. # Create the dedicated user (if not existing)
  47. ynh_system_user_create $app
  48. #=================================================
  49. # RESTORE USER RIGHTS
  50. #=================================================
  51. # Restore permissions on app files
  52. chown -R $app: $final_path
  53. #=================================================
  54. # SPECIFIC RESTORATION
  55. #=================================================
  56. # REINSTALL DEPENDENCIES
  57. #=================================================
  58. ynh_print_info "Reinstalling dependencies..."
  59. # Define and install dependencies
  60. ynh_install_app_dependencies "$pkg_dependencies"
  61. #=================================================
  62. # RESTORE SYSTEMD
  63. #=================================================
  64. ynh_print_info "Restoring the systemd configuration..."
  65. ynh_restore_file "/etc/systemd/system/$service_name.service"
  66. ynh_restore_file "/etc/systemd/system/$service_checker_name.service"
  67. ynh_restore_file "/etc/systemd/system/$service_checker_name.timer"
  68. ynh_restore_file "/etc/systemd/system/openvpn@.service"
  69. systemctl daemon-reload
  70. systemctl enable "$service_name.service" --quiet
  71. systemctl enable "$service_checker_name.service" --quiet
  72. systemctl enable "openvpn@.service" --quiet
  73. #=================================================
  74. # ADVERTISE SERVICE IN ADMIN PANEL
  75. #=================================================
  76. 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"
  77. #=================================================
  78. # GENERIC FINALIZATION
  79. #=================================================
  80. #=================================================
  81. # END OF SCRIPT
  82. #=================================================
  83. ynh_print_info "Restoration completed for $app"