restore 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. domain=$(ynh_app_setting_get $app domain)
  20. path_url=$(ynh_app_setting_get $app path)
  21. final_path=$(ynh_app_setting_get $app final_path)
  22. service_name=$(ynh_app_setting_get $app service_name)
  23. service_checker_name=$service_name"-checker"
  24. #=================================================
  25. # CHECK IF THE APP CAN BE RESTORED
  26. #=================================================
  27. ynh_print_info "Validating restoration parameters..."
  28. ynh_webpath_available $domain $path_url \
  29. || ynh_die "Path not available: ${domain}${path_url}"
  30. test ! -d $final_path \
  31. || ynh_die "There is already a directory: $final_path "
  32. #=================================================
  33. # STANDARD RESTORATION STEPS
  34. #=================================================
  35. # RESTORE THE NGINX CONFIGURATION
  36. #=================================================
  37. ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
  38. #=================================================
  39. # RESTORE THE APP MAIN DIR
  40. #=================================================
  41. ynh_print_info "Restoring the app main directory..."
  42. ynh_restore_file "$final_path"
  43. ynh_restore_file "/etc/sudoers.d/${app}_ynh"
  44. ynh_restore_file "/usr/local/bin/ipv6_expanded"
  45. ynh_restore_file "/usr/local/bin/ipv6_compressed"
  46. ynh_restore_file "/usr/local/bin/$service_name-loadcubefile.sh"
  47. ynh_restore_file "/etc/yunohost/hooks.d/90-vpnclient.tpl"
  48. ynh_restore_file "/etc/openvpn/client.conf.tpl"
  49. ynh_restore_file "/etc/openvpn/client.conf.tpl.restore"
  50. ynh_restore_file "/etc/openvpn/keys/"
  51. ynh_restore_file "/usr/local/bin/$service_name"
  52. ynh_restore_file "/usr/local/bin/$service_checker_name.sh"
  53. #=================================================
  54. # RECREATE THE DEDICATED USER
  55. #=================================================
  56. ynh_print_info "Recreating the dedicated system user..."
  57. # Create the dedicated user (if not existing)
  58. ynh_system_user_create $app
  59. #=================================================
  60. # RESTORE USER RIGHTS
  61. #=================================================
  62. # Restore permissions on app files
  63. chown -R $app: $final_path
  64. #=================================================
  65. # RESTORE THE PHP-FPM CONFIGURATION
  66. #=================================================
  67. ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
  68. #=================================================
  69. # SPECIFIC RESTORATION
  70. #=================================================
  71. # REINSTALL DEPENDENCIES
  72. #=================================================
  73. ynh_print_info "Reinstalling dependencies..."
  74. # Define and install dependencies
  75. ynh_install_app_dependencies "$pkg_dependencies"
  76. #=================================================
  77. # RESTORE SYSTEMD
  78. #=================================================
  79. ynh_print_info "Restoring the systemd configuration..."
  80. ynh_restore_file "/etc/systemd/system/$service_name.service"
  81. ynh_restore_file "/etc/systemd/system/$service_checker_name.service"
  82. ynh_restore_file "/etc/systemd/system/$service_checker_name.timer"
  83. ynh_restore_file "/etc/systemd/system/openvpn@.service"
  84. systemctl daemon-reload
  85. systemctl enable "$service_name.service"
  86. systemctl enable "$service_checker_name.service"
  87. systemctl enable "openvpn@.service"
  88. #=================================================
  89. # ADVERTISE SERVICE IN ADMIN PANEL
  90. #=================================================
  91. yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock
  92. yunohost service add $service_checker_name --description "Makes sure that the VPN service is running" --need_lock
  93. #=================================================
  94. # GENERIC FINALIZATION
  95. #=================================================
  96. # RELOAD NGINX AND PHP-FPM
  97. #=================================================
  98. ynh_print_info "Reloading nginx web server and php-fpm..."
  99. systemctl restart php7.0-fpm
  100. systemctl reload nginx
  101. #=================================================
  102. # END OF SCRIPT
  103. #=================================================
  104. ynh_print_info "Restoration completed for $app"