network 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh
  2. if [ "$1" = "test" ]; then
  3. . /lib/recovery-mode/l10n.sh
  4. echo $(eval_gettext "Enable networking")
  5. exit 0
  6. fi
  7. # Check for existing connectivity
  8. check_connectivity() {
  9. ip route get 1.2.3.4 >/dev/null 2>&1
  10. retval_route=$?
  11. grep ^nameserver -q /etc/resolv.conf
  12. retval_resolve=$?
  13. if [ "$retval_route" = "0" ] && [ "$retval_resolve" ]; then
  14. exit 0
  15. fi
  16. }
  17. # Try handling networking using systemd
  18. if [ -d /run/systemd/system ]; then
  19. echo "Enabling networking..."
  20. for i in dbus.socket systemd-udevd.service systemd-sysctl.service systemd-resolved.service networking.service systemd-networkd.service NetworkManager.service; do
  21. systemctl is-enabled -q $i && systemctl start --no-ask-password --job-mode=ignore-dependencies $i
  22. done
  23. echo "Waiting for networking to be configured..."
  24. systemctl is-enabled -q NetworkManager.service && systemctl start --no-ask-password NetworkManager-wait-online.service
  25. systemctl is-enabled -q systemd-networkd.service && systemctl start --no-ask-password systemd-networkd-wait-online.service
  26. echo "Done."
  27. exit 0
  28. fi
  29. # Start by trying to bring everything up
  30. ifup -a
  31. check_connectivity
  32. # Then try Network Manager
  33. if type NetworkManager >/dev/null 2>&1; then
  34. echo "Trying to start NetworkManager..."
  35. mkdir -p /run/dbus
  36. chown messagebus:messagebus /run/dbus
  37. dbus-daemon --system --nopidfile
  38. NetworkManager
  39. trap "killall dbus-daemon NetworkManager" EXIT HUP INT QUIT PIPE
  40. timeout=15
  41. while [ $timeout -ge 0 ]; do
  42. check_connectivity
  43. sleep 1
  44. timeout=$((timeout-1))
  45. done
  46. fi
  47. # Try running dhclient on everything else
  48. cd /sys/class/net/
  49. for interface in *; do
  50. dhclient -1 $interface
  51. check_connectivity
  52. done
  53. exit 0