restore 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
  8. source ../settings/scripts/_common.sh
  9. source /usr/share/yunohost/helpers
  10. #=================================================
  11. # FIND AND OPEN A PORT
  12. #=================================================
  13. ynh_script_progression --message="Configuring firewall..."
  14. # Update firewall for DHCP
  15. ynh_exec_warn_less yunohost firewall allow --no-upnp --ipv6 UDP 547
  16. ynh_exec_warn_less yunohost firewall allow --no-upnp UDP 67
  17. # Meh idk where to put this ... On RPi, by default wlan is blocked
  18. if test -e /usr/sbin/rfkill && rfkill | grep wlan | grep -q -w 'blocked'
  19. then
  20. ynh_print_info "Unblocking wlan interface..."
  21. /usr/sbin/rfkill unblock wlan
  22. fi
  23. #=================================================
  24. # STANDARD RESTORATION STEPS
  25. #=================================================
  26. ynh_script_progression --message="Restoring configurations ..."
  27. ynh_restore_file --origin_path="/etc/hostapd/$app/hostapd.conf" --not_mandatory
  28. ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv6.conf" --not_mandatory
  29. ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv4.conf" --not_mandatory
  30. ynh_restore_file --origin_path="/usr/local/bin/$service_name"
  31. ynh_restore_file --origin_path="/etc/openvpn/scripts/route-up.d/90-${service_name}"
  32. ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/90-${service_name}"
  33. ynh_restore_file --origin_path="/etc/systemd/system/$service_name.service"
  34. ynh_restore_file --origin_path="/etc/systemd/system/hostapd@$app.service"
  35. yunohost service add "$service_name" --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --need_lock
  36. #=================================================
  37. # START SYSTEMD SERVICE
  38. #=================================================
  39. ynh_script_progression --message="Starting the hotspot service..."
  40. hot_reload_usb_wifi_cards
  41. if [[ -z "${wifi_device:-}" ]] || ! grep -q -F "$wifi_device" <(unused_iw_devices); then
  42. wifi_device=$(unused_iw_devices | head -n 1)
  43. ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}"
  44. fi
  45. if [[ -z "${wifi_device:-}" ]]; then
  46. ynh_app_setting_set --app=$app --key=service_enabled --value=0
  47. else
  48. ynh_app_setting_set --app=$app --key=service_enabled --value=1
  49. fi
  50. # Start a systemd service if device is present
  51. if [[ "${wifi_device:-}" == "" ]]; then
  52. echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
  53. else
  54. yunohost service start $service_name
  55. fi
  56. #=================================================
  57. # END OF SCRIPT
  58. #=================================================
  59. ynh_script_progression --message="Restoration completed for $app"