From ae0a46b8d0e6c9cf43c747cfa5508a862e9c9374 Mon Sep 17 00:00:00 2001 From: Florian Maurer Date: Sat, 1 Feb 2025 11:45:26 +0100 Subject: [PATCH] gluon-setup-mode: rename phys before starting setup mode --- .../lib/gluon/setup-mode/rc.d/S20network | 2 + .../luasrc/usr/lib/lua/gluon/setup-mode.lua | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S20network b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S20network index 9721558299..586c8be2b7 100755 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S20network +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S20network @@ -48,6 +48,8 @@ start_service() { init_switch iw reg set "$(lua -e 'print(require("gluon.site").regdom())')" + /usr/bin/lua -e 'require("gluon.setup-mode").rename_phys()' + procd_open_instance procd_set_param command /sbin/netifd -c /var/gluon/setup-mode/config procd_set_param respawn diff --git a/package/gluon-setup-mode/luasrc/usr/lib/lua/gluon/setup-mode.lua b/package/gluon-setup-mode/luasrc/usr/lib/lua/gluon/setup-mode.lua index 3b107bf97c..36ef495661 100644 --- a/package/gluon-setup-mode/luasrc/usr/lib/lua/gluon/setup-mode.lua +++ b/package/gluon-setup-mode/luasrc/usr/lib/lua/gluon/setup-mode.lua @@ -1,4 +1,5 @@ local platform = require 'gluon.platform' +local json = require 'jsonc' local M = {} @@ -11,4 +12,43 @@ function M.get_status_led() end end +function M.rename_phys() + -- Load board data from JSON file + local board_data = json.load('/etc/board.json') + local wlan_data = board_data.wlan or {} + + -- Iterate over all entries in wlan_data + for phyname, data in pairs(wlan_data) do + local path = data.path + if path then + -- Get the phyname using iwinfo + -- lua iwinfo does return nil by path instead + -- local other_phyname = iwinfo.nl80211.phyname('path=' .. path) + + local cmd = "iwinfo nl80211 phyname path=" .. path + local f = io.popen(cmd) + local other_phyname = f:read("*a") + f:close() + + -- Trim whitespace from the result + other_phyname = other_phyname:gsub("^%s*(.-)%s*$", "%1") + + -- Check if the retrieved phyname doesn't match the key + if other_phyname ~= "" and other_phyname ~= phyname then + -- Construct the command to rename the phy + local cmd = string.format("iw %s set name %s", other_phyname, phyname) + + -- Execute the command + os.execute(cmd) + + print(string.format("Renamed %s to %s", other_phyname, phyname)) + else + print(string.format("No renaming needed for %s", phyname)) + end + else + print(string.format("No path found for %s", phyname)) + end + end +end + return M