From 68adb3108f8111b1be434bf63c03562d72bbbe6f Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 25 Jan 2021 10:31:02 +0100 Subject: Created an embryo for hardware detection. Supports detecting WiFi and UEFI. This fixes #44 and is a start for #82. --- archinstall/__init__.py | 1 + archinstall/lib/hardware.py | 10 ++++++++++ archinstall/lib/networking.py | 19 ++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 archinstall/lib/hardware.py (limited to 'archinstall') diff --git a/archinstall/__init__.py b/archinstall/__init__.py index 174c6885..ee2d0361 100644 --- a/archinstall/__init__.py +++ b/archinstall/__init__.py @@ -12,3 +12,4 @@ from .lib.services import * from .lib.packages import * from .lib.output import * from .lib.storage import * +from .lib.hardware import * \ No newline at end of file diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py new file mode 100644 index 00000000..c9483919 --- /dev/null +++ b/archinstall/lib/hardware.py @@ -0,0 +1,10 @@ +import os +from .networking import list_interfaces, enrichIfaceTypes + +def hasWifi(): + if 'WIRELESS' in enrichIfaceTypes(list_interfaces().values()).values(): + return True + return False + +def hasUEFI(): + return os.path.isdir('/sys/firmware/efi') \ No newline at end of file diff --git a/archinstall/lib/networking.py b/archinstall/lib/networking.py index 4829a58b..b69a43db 100644 --- a/archinstall/lib/networking.py +++ b/archinstall/lib/networking.py @@ -1,9 +1,9 @@ +import os import fcntl import socket import struct from collections import OrderedDict - def getHwAddr(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', bytes(ifname, 'utf-8')[:15])) @@ -19,5 +19,22 @@ def list_interfaces(skip_loopback=True): interfaces[mac] = iface return interfaces +def enrichIfaceTypes(interfaces :dict): + result = {} + for iface in interfaces: + if os.path.isdir(f"/sys/class/net/{iface}/bridge/"): + result[iface] = 'BRIDGE' + elif os.path.isfile(f"/sys/class/net/{iface}/tun_flags"): + # ethtool -i {iface} + result[iface] = 'TUN/TAP' + elif os.path.isdir(f"/sys/class/net/{iface}/device"): + if os.path.isdir(f"/sys/class/net/{iface}/wireless/"): + result[iface] = 'WIRELESS' + else: + result[iface] = 'PHYSICAL' + else: + result[iface] = 'UNKNOWN' + return result + def get_interface_from_mac(mac): return list_interfaces().get(mac.lower(), None) \ No newline at end of file -- cgit v1.2.3-54-g00ecf