Skip to content

Commit

Permalink
dietpi: make hotspot not disable eth0 by removing allow-hotplug
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed Dec 21, 2024
1 parent 4b9fd44 commit b9296da
Showing 1 changed file with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,20 +283,6 @@ def teardown_hotspot(self):
shell=True,
)
if self._baseos == "dietpi":
# switch hotplug to allow wifi
with open("/etc/network/interfaces", "r") as current, open("/etc/network/interfaces.new", "w") as update:
lines = current.readlines()
for line in lines:
if "allow-hotplug" in line:
if self.wlan in line:
update.write(f"allow-hotplug {self.wlan}\n")
else:
update.write(f"# {line}")
else:
update.write(f"{line}")
os.remove("/etc/network/interfaces")
os.rename("/etc/network/interfaces.new", "/etc/network/interfaces")

output = subprocess.run(
f"systemctl restart --no-block networking.service",
shell=True,
Expand Down Expand Up @@ -361,9 +347,37 @@ def test_wifi(self):
success = False

if self._baseos == "dietpi":
# switch hotplug to test for wifi and apply changes
with open("/etc/network/interfaces", "r") as current, open("/etc/network/interfaces.new", "w") as update:
lines = current.readlines()
for line in lines:
if "allow-hotplug" in line:
if self.wlan in line:
update.write(f"allow-hotplug {self.wlan}\n")
else:
update.write(f"# {line}")
else:
update.write(f"{line}")
os.rename("/etc/network/interfaces", "/etc/network/interfaces.orig.hotspot")
os.rename("/etc/network/interfaces.new", "/etc/network/interfaces")
output = subprocess.run(
f"systemctl restart --no-block networking.service",
shell=True,
capture_output=True,
)

# test wifi
self.writeWpaConf(ssid=self.ssid, passwd=self.passwd, path="/etc/wpa_supplicant/wpa_supplicant.conf")
success = self.wpa_cli_reconfigure()

# restore original /etc/network/interfaces and apply changes
os.rename("/etc/network/interfaces.orig.hotspot", "/etc/network/interfaces")
output = subprocess.run(
f"systemctl restart --no-block networking.service",
shell=True,
capture_output=True,
)

elif self._baseos == "raspbian":
# try for a while because it takes a bit for NetworkManager to come back up
startTime = time.time()
Expand Down

0 comments on commit b9296da

Please sign in to comment.