forked from freifunk-gluon/gluon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add image customization generation script
this script creates the helper lua from the openwrt toh to be included in the image-customization.lua
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import requests | ||
from pathlib import Path | ||
toh = requests.get("https://openwrt.org/toh.json").json() | ||
|
||
entries = toh["entries"] | ||
captions = toh["captions"] | ||
columns = toh["columns"] | ||
|
||
def get_devices_from_gluon(): | ||
devices = [] | ||
for path in Path("../targets").glob("*"): | ||
file = path.read_text() | ||
for line in file.splitlines(): | ||
if line.startswith("device('"): | ||
devices.append(line.split("('")[1].split("',")[0]) | ||
return devices | ||
|
||
def create_caption_dict(columns, entries): | ||
result = {} | ||
for entry in entries: | ||
result_entry = {} | ||
for index, column in enumerate(columns): | ||
result_entry[column] = entry[index] | ||
brand = result_entry["brand"] | ||
model = result_entry["model"] | ||
device = f"{brand}-{model}" | ||
device = result_entry["deviceid"].split(":")[1] | ||
device = device.lower().replace("_", "-").replace(" ", "-").replace("!", "-") | ||
|
||
if result.get(device): | ||
#print(f"Duplicate device: {device}") | ||
continue | ||
result[device] = result_entry | ||
return result | ||
|
||
result = create_caption_dict(columns, entries) | ||
devices = get_devices_from_gluon() | ||
has_gluon = {k: v for k, v in result.items() if k in devices} | ||
|
||
has_lte = {k: v for k, v in result.items() if v["modem"] and v["modem"] == "LTE" in has_gluon} | ||
is_outdoor = {k: v for k, v in result.items() if v["modem"] and v["outdoor"] == "Yes" in has_gluon} | ||
has_usb = {k: v for k, v in has_gluon.items() if v["usbports"] and v["usbports"] != ["-"]} | ||
has_wifi24 = {k: v for k, v in has_gluon.items() if v["wlan24ghz"] and v["wlan24ghz"] != ["-"]} | ||
has_wifi50 = {k: v for k, v in has_gluon.items() if v["wlan50ghz"] and v["wlan50ghz"] != ["-"]} | ||
|
||
with open("image-customization-helper.lua", "w") as f: | ||
|
||
usb_devices = "', '".join([device for device in has_usb]) | ||
lte_devices = "', '".join([device for device in has_lte]) | ||
outdoor_devices = "', '".join([device for device in is_outdoor]) | ||
has_wifi24_devices = "', '".join([device for device in has_wifi24]) | ||
has_wifi50_devices = "', '".join([device for device in has_wifi50]) | ||
lines = f"""#!/usr/bin/lua | ||
has_usb = false | ||
if device('{usb_devices}') then) | ||
has_usb = true | ||
end | ||
has_lte = false | ||
if device('{lte_devices}') then) | ||
has_lte = true | ||
end | ||
is_outdoor = false | ||
if device('{outdoor_devices}') then) | ||
is_outdoor = true | ||
end | ||
has_wifi24 = false | ||
if device('{has_wifi24_devices}') then) | ||
is_outdoor = true | ||
end | ||
has_wifi50 = false | ||
if device('{has_wifi50_devices}') then) | ||
is_outdoor = true | ||
end | ||
""" | ||
f.writelines(lines) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/lua | ||
has_usb = false | ||
if device('cudy-wr1300-v1', 'ravpower-rp-wd009', 'enterasys-ws-ap3715i', 'd-link-dir-860l-b1', 'd-link-dir-882-a1', 'd-link-dir-505', 'gl.inet-gl-mt1300', 'gl.inet-gl-xe300', 'gl.inet-gl-usb150', 'gl.inet-gl-ar150', 'gl.inet-vixmini', 'gl.inet-gl-b1300', 'gl.inet-gl-ar750', 'gl.inet-gl-mt3000', 'gl.inet-gl-ar300m-lite', 'devolo-wifi-pro-1750e', 'onion-omega', 'asus-tuf-ax4200', 'asus-rt-ac51u', 'asus-tuf-ax6000', 'asus-rt-ax53u', 'linksys-wrt1200ac', 'aerohive-hiveap-330', 'netgear-wndr3800', 'netgear-wndrmac-v2', 'netgear-wndr3700-v2', 'netgear-wndr3700-v5', 'netgear-wndr3700-v4', 'netgear-r6260', 'netgear-r6120', 'netgear-dgn3500b', 'netgear-r6220', 'extreme-networks-ws-ap3825i', '8devices-jalapeno', 'lemaker-banana-pro', 'ocedo-panda', 'aruba-ap-303h', 'aruba-ap-365', 'avm-fritz-box-7360-v2', 'avm-fritz-box-4040', 'avm-fritz-box-4020', 'avm-fritz-box-7530', 'xiaomi-mi-router-4c', 'tp-link-archer-c7-v5', 'tp-link-archer-d50-v1', 'tp-link-tl-wr1043nd-v3', 'tp-link-tl-wr842n-v3', 'tp-link-tl-wr902ac-v1', 'tp-link-tl-mr3420-v5', 'tp-link-archer-c50-v3', 'tp-link-archer-c7-v4', 'tp-link-tl-wr1043nd-v4', 'tp-link-tl-wr1043nd-v2', 'tp-link-tl-wr902ac-v3', 'tp-link-archer-a7-v5', 'tp-link-tl-wdr4900-v1', 'tp-link-td-w8980', 'tp-link-tl-mr3020-v3', 'tp-link-archer-c2600', 'tp-link-tl-wdr3600-v1', 'tp-link-archer-c59-v1', 'tp-link-tl-wdr3500-v1', 'zyxel-nbg6617', 'buffalo-wzr-600dhp', 'plasma-cloud-pa1200') then) | ||
has_usb = true | ||
end | ||
|
||
has_lte = false | ||
if device('zte-mf281', 'zte-mf289f', 'gl.inet-gl-xe300', 'wavlink-ws-wn572hp3-4g', 'tp-link-tl-mr6400-v5') then) | ||
has_lte = true | ||
end | ||
|
||
is_outdoor = false | ||
if device('devolo-wifi-pro-1750x', 'aruba-ap-365', 'wavlink-ws-wn572hp3-4g', 'tp-link-wbs210-v2', 'tp-link-cpe510-v3', 'tp-link-archer-c50-v4', 'tp-link-eap225-outdoor-v1', 'tp-link-archer-c50-v3', 'tp-link-wbs210-v1', 'tp-link-cpe510-v1', 'tp-link-cpe210-v1', 'tp-link-archer-c20-v5', 'tp-link-cpe220-v3', 'tp-link-cpe710-v1', 'tp-link-wbs510-v1', 'tp-link-cpe510-v2', 'tp-link-eap225-outdoor-v3', 'tp-link-cpe210-v3', 'tp-link-cpe210-v2', 'zyxel-nwa55axe', 'mikrotik-sxtsq-5-ac-rbsxtsqg-5acd', 'plasma-cloud-pa1200') then) | ||
is_outdoor = true | ||
end |