]> git.99rst.org Git - openwrt-luci.git/blob
23eb4403295d1c2174a3fc94cc863579e41f8253
[openwrt-luci.git] /
1 # Tabs only for indentation, spaces ok in comments.
2
3 # jq -f _device_json_transform.jq old.json
4 # Transform from the old schema:
5 # {
6 # "vendorName": "...",
7 # "deviceName": "...",
8 # "boardNames": ["..."],
9 # "partition1MTD": "mtdX",
10 # "partition2MTD": "mtdY",
11 # "labelOffset": 32,
12 # "bootEnv1": "boot_part",
13 # "bootEnv1Partition1Value": 1,
14 # "bootEnv1Partition2Value": 2,
15 # "bootEnv2": "bootcmd",
16 # "bootEnv2Partition1Value": "run nandboot",
17 # "bootEnv2Partition2Value": "run altnandboot",
18 # "opOffset": 0,
19 # "ubiVolume": 2
20 # }
21 #
22 # …to the new schema:
23 # {
24 # "device": { "vendor": "...", "model": "...", "board": ["..."] },
25 # "commands": { "params": [...], "get": "fw_printenv", "set": "fw_setenv", "save": null },
26 # "partitions": [
27 # { "number": 1, "param_values": [...], "mtd": "mtdX", "labelOffsetBytes": <int|null>, "altMountOptions": {...|null} },
28 # { "number": 2, "param_values": [...], "mtd": "mtdY", "labelOffsetBytes": <int|null>, "altMountOptions": {...|null} }
29 # ]
30 # }
31
32 . as $in
33 | ([$in.bootEnv1, $in.bootEnv2] | map(select(. != null))) as $params
34 | {
35 device: {
36 vendor: $in.vendorName,
37 model: $in.deviceName,
38 board: (if ($in.boardNames | type) == "array" then $in.boardNames else [$in.boardNames] end)
39 },
40 commands: {
41 params: $params,
42 get: "fw_printenv",
43 set: "fw_setenv",
44 save: null
45 },
46 partitions: [
47 (if $in.partition1MTD != null then
48 {
49 number: 1,
50 param_values: (
51 # Align to commands.params: value for param[0], param[1], ...
52 # Only include entries that exist (skip nulls)
53 [
54 (if ($params | length) > 0 then $in.bootEnv1Partition1Value else empty end),
55 (if ($params | length) > 1 then $in.bootEnv2Partition1Value else empty end)
56 ] | map(select(. != null))
57 ),
58 mtd: $in.partition1MTD,
59 labelOffsetBytes: ($in.labelOffset // null)
60 } + (
61 if ($in.opOffset != null or $in.ubiVolume != null) then
62 { altMountOptions: { mtdOffset: ($in.opOffset // null), ubiVolume: ($in.ubiVolume // null) } }
63 else
64 {}
65 end
66 )
67 else empty end),
68 (if $in.partition2MTD != null then
69 {
70 number: 2,
71 param_values: (
72 [
73 (if ($params | length) > 0 then $in.bootEnv1Partition2Value else empty end),
74 (if ($params | length) > 1 then $in.bootEnv2Partition2Value else empty end)
75 ] | map(select(. != null))
76 ),
77 mtd: $in.partition2MTD,
78 labelOffsetBytes: ($in.labelOffset // null)
79 } + (
80 if ($in.opOffset != null or $in.ubiVolume != null) then
81 { altMountOptions: { mtdOffset: ($in.opOffset // null), ubiVolume: ($in.ubiVolume // null) } }
82 else
83 {}
84 end
85 )
86 else empty end)
87 ]
88 }
git clone https://git.99rst.org/PROJECT