Skip to content

Commit 217b18c

Browse files
committed
gluon-setup-mode: rename phys before starting setup mode
Signed-off-by: Florian Maurer <f.maurer@outlook.de>
1 parent cd074cc commit 217b18c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S20network

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ start_service() {
4848
init_switch
4949
iw reg set "$(lua -e 'print(require("gluon.site").regdom())')"
5050

51+
/usr/bin/lua -e 'require("gluon.setup-mode").rename_phys()'
52+
5153
procd_open_instance
5254
procd_set_param command /sbin/netifd -c /var/gluon/setup-mode/config
5355
procd_set_param respawn

package/gluon-setup-mode/luasrc/usr/lib/lua/gluon/setup-mode.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local platform = require 'gluon.platform'
2+
local json = require 'jsonc'
23

34

45
local M = {}
@@ -11,4 +12,32 @@ function M.get_status_led()
1112
end
1213
end
1314

15+
function M.rename_phys()
16+
-- Load board data from JSON file
17+
local board_data = json.load('/etc/board.json')
18+
local wlan_data = board_data.wlan or {}
19+
20+
-- Iterate over all entries in wlan_data
21+
for phyname, data in pairs(wlan_data) do
22+
local path = data.path
23+
if path then
24+
-- Get the phyname using iwinfo
25+
-- lua iwinfo does return nil by path instead
26+
-- local other_phyname = iwinfo.nl80211.phyname('path=' .. path)
27+
28+
local f = io.popen("iwinfo nl80211 phyname path=" .. path)
29+
local other_phyname = f:read("*a")
30+
f:close()
31+
32+
-- Check if the retrieved phyname doesn't match the key
33+
if other_phyname ~= "" and other_phyname ~= phyname then
34+
-- Execute the command
35+
os.execute(string.format("iw %s set name %s", other_phyname, phyname))
36+
37+
print(string.format("Renamed phy %s to %s", other_phyname, phyname))
38+
end
39+
end
40+
end
41+
end
42+
1443
return M

0 commit comments

Comments
 (0)