restore 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. firmware_nonfree=$(ynh_app_setting_get $app firmware_nonfree)
  23. service_name=$(ynh_app_setting_get $app service_name)
  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. if [[ $firmware_nonfree -eq 1 ]]; then
  44. # check if non-free is set on sources.list
  45. if ! grep -q non-free /etc/apt/sources.list ; then
  46. sed '/debian/{s/main/& non-free/}' -i /etc/apt/sources.list
  47. fi
  48. packages=$nonfree_packages
  49. else
  50. packages=$free_packages
  51. mkdir -p /lib/firmware
  52. ynh_restore_file "/lib/firmware/htc_7010.fw"
  53. ynh_restore_file "/lib/firmware/htc_9271.fw"
  54. fi
  55. ynh_restore_file "/etc/sudoers.d/${app}_ynh"
  56. ynh_restore_file "/usr/local/bin/iw_multissid"
  57. ynh_restore_file "/usr/local/bin/iw_devices"
  58. ynh_restore_file "/usr/local/bin/iw_ssids"
  59. ynh_restore_file "/usr/local/bin/ipv6_expanded"
  60. ynh_restore_file "/usr/local/bin/ipv6_compressed"
  61. for FILE in $(ls /etc/hostapd/hostapd.conf{.tpl?,} 2>/dev/null)
  62. do
  63. ynh_restore_file "$FILE"
  64. done
  65. ynh_restore_file "/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl"
  66. ynh_restore_file "/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl"
  67. ynh_restore_file "/usr/local/bin/$service_name"
  68. ynh_restore_file "/etc/init.d/hostapd"
  69. #=================================================
  70. # RECREATE THE DEDICATED USER
  71. #=================================================
  72. ynh_print_info "Recreating the dedicated system user..."
  73. # Create the dedicated user (if not existing)
  74. ynh_system_user_create $app
  75. #=================================================
  76. # RESTORE USER RIGHTS
  77. #=================================================
  78. # Restore permissions on app files
  79. chown -R www-data: $final_path
  80. #=================================================
  81. # RESTORE THE PHP-FPM CONFIGURATION
  82. #=================================================
  83. ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
  84. #=================================================
  85. # SPECIFIC RESTORATION
  86. #=================================================
  87. # REINSTALL DEPENDENCIES
  88. #=================================================
  89. ynh_print_info "Reinstalling dependencies..."
  90. # Define and install dependencies
  91. ynh_install_app_dependencies "$pkg_dependencies" "$packages"
  92. #=================================================
  93. # RESTORE SYSTEMD
  94. #=================================================
  95. ynh_print_info "Restoring the systemd configuration..."
  96. ynh_restore_file "/etc/systemd/system/$service_name.service"
  97. systemctl enable $service_name.service
  98. #=================================================
  99. # ADVERTISE SERVICE IN ADMIN PANEL
  100. #=================================================
  101. yunohost service add $app --log "/var/log/$app/$app.log"
  102. #=================================================
  103. # GENERIC FINALIZATION
  104. #=================================================
  105. # RELOAD NGINX AND PHP-FPM
  106. #=================================================
  107. ynh_print_info "Reloading nginx web server and php-fpm..."
  108. systemctl restart php7.0-fpm
  109. systemctl reload nginx
  110. #=================================================
  111. # END OF SCRIPT
  112. #=================================================
  113. ynh_print_info "Restoration completed for $app"