build: create JSON files containing image info
The JSON info files contain details about the created firmware images
per device and are stored next to the created images.
The JSON files are stored as "$(IMAGE_PREFIX).json" and contain some
device/image meta data as well as a list of created firmware images.
An example of openwrt-ramips-rt305x-aztech_hw550-3g.json
{
"id": "aztech_hw550-3g",
"image_prefix": "openwrt-ramips-rt305x-aztech_hw550-3g",
"images": [
{
"name": "openwrt-ramips-rt305x-aztech_hw550-3g-squashfs-sysupgrade.bin",
"sha256": "db2b34b0ec4a83d9bf612cf66fab0dc3722b191cb9bedf111e5627a4298baf20",
"type": "sysupgrade"
}
],
"metadata_version": 1,
"supported_devices": [
"aztech,hw550-3g",
"hw550-3g"
],
"target": "ramips/rt305x",
"titles": [
{
"model": "HW550-3G",
"vendor": "Aztech"
},
{
"model": "ALL0239-3G",
"vendor": "Allnet"
}
],
"version_commit": "r10920+123-0cc87b3bac",
"version_number": "SNAPSHOT"
}
Signed-off-by: Paul Spooren <mail@aparcar.org>
2019-08-18 19:56:45 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-03-12 22:55:41 +00:00
|
|
|
from os import getenv
|
|
|
|
from pathlib import Path
|
|
|
|
from sys import argv
|
build: create JSON files containing image info
The JSON info files contain details about the created firmware images
per device and are stored next to the created images.
The JSON files are stored as "$(IMAGE_PREFIX).json" and contain some
device/image meta data as well as a list of created firmware images.
An example of openwrt-ramips-rt305x-aztech_hw550-3g.json
{
"id": "aztech_hw550-3g",
"image_prefix": "openwrt-ramips-rt305x-aztech_hw550-3g",
"images": [
{
"name": "openwrt-ramips-rt305x-aztech_hw550-3g-squashfs-sysupgrade.bin",
"sha256": "db2b34b0ec4a83d9bf612cf66fab0dc3722b191cb9bedf111e5627a4298baf20",
"type": "sysupgrade"
}
],
"metadata_version": 1,
"supported_devices": [
"aztech,hw550-3g",
"hw550-3g"
],
"target": "ramips/rt305x",
"titles": [
{
"model": "HW550-3G",
"vendor": "Aztech"
},
{
"model": "ALL0239-3G",
"vendor": "Allnet"
}
],
"version_commit": "r10920+123-0cc87b3bac",
"version_number": "SNAPSHOT"
}
Signed-off-by: Paul Spooren <mail@aparcar.org>
2019-08-18 19:56:45 +00:00
|
|
|
import hashlib
|
2020-03-12 22:55:41 +00:00
|
|
|
import json
|
build: create JSON files containing image info
The JSON info files contain details about the created firmware images
per device and are stored next to the created images.
The JSON files are stored as "$(IMAGE_PREFIX).json" and contain some
device/image meta data as well as a list of created firmware images.
An example of openwrt-ramips-rt305x-aztech_hw550-3g.json
{
"id": "aztech_hw550-3g",
"image_prefix": "openwrt-ramips-rt305x-aztech_hw550-3g",
"images": [
{
"name": "openwrt-ramips-rt305x-aztech_hw550-3g-squashfs-sysupgrade.bin",
"sha256": "db2b34b0ec4a83d9bf612cf66fab0dc3722b191cb9bedf111e5627a4298baf20",
"type": "sysupgrade"
}
],
"metadata_version": 1,
"supported_devices": [
"aztech,hw550-3g",
"hw550-3g"
],
"target": "ramips/rt305x",
"titles": [
{
"model": "HW550-3G",
"vendor": "Aztech"
},
{
"model": "ALL0239-3G",
"vendor": "Allnet"
}
],
"version_commit": "r10920+123-0cc87b3bac",
"version_number": "SNAPSHOT"
}
Signed-off-by: Paul Spooren <mail@aparcar.org>
2019-08-18 19:56:45 +00:00
|
|
|
|
2020-03-12 22:55:41 +00:00
|
|
|
if len(argv) != 2:
|
|
|
|
print("ERROR: JSON info script requires output arg")
|
|
|
|
exit(1)
|
build: create JSON files containing image info
The JSON info files contain details about the created firmware images
per device and are stored next to the created images.
The JSON files are stored as "$(IMAGE_PREFIX).json" and contain some
device/image meta data as well as a list of created firmware images.
An example of openwrt-ramips-rt305x-aztech_hw550-3g.json
{
"id": "aztech_hw550-3g",
"image_prefix": "openwrt-ramips-rt305x-aztech_hw550-3g",
"images": [
{
"name": "openwrt-ramips-rt305x-aztech_hw550-3g-squashfs-sysupgrade.bin",
"sha256": "db2b34b0ec4a83d9bf612cf66fab0dc3722b191cb9bedf111e5627a4298baf20",
"type": "sysupgrade"
}
],
"metadata_version": 1,
"supported_devices": [
"aztech,hw550-3g",
"hw550-3g"
],
"target": "ramips/rt305x",
"titles": [
{
"model": "HW550-3G",
"vendor": "Aztech"
},
{
"model": "ALL0239-3G",
"vendor": "Allnet"
}
],
"version_commit": "r10920+123-0cc87b3bac",
"version_number": "SNAPSHOT"
}
Signed-off-by: Paul Spooren <mail@aparcar.org>
2019-08-18 19:56:45 +00:00
|
|
|
|
2020-03-12 22:55:41 +00:00
|
|
|
json_path = Path(argv[1])
|
|
|
|
bin_dir = Path(getenv("BIN_DIR"))
|
2021-09-13 09:44:04 +00:00
|
|
|
file_path = bin_dir / getenv("FILE_NAME")
|
build: create JSON files containing image info
The JSON info files contain details about the created firmware images
per device and are stored next to the created images.
The JSON files are stored as "$(IMAGE_PREFIX).json" and contain some
device/image meta data as well as a list of created firmware images.
An example of openwrt-ramips-rt305x-aztech_hw550-3g.json
{
"id": "aztech_hw550-3g",
"image_prefix": "openwrt-ramips-rt305x-aztech_hw550-3g",
"images": [
{
"name": "openwrt-ramips-rt305x-aztech_hw550-3g-squashfs-sysupgrade.bin",
"sha256": "db2b34b0ec4a83d9bf612cf66fab0dc3722b191cb9bedf111e5627a4298baf20",
"type": "sysupgrade"
}
],
"metadata_version": 1,
"supported_devices": [
"aztech,hw550-3g",
"hw550-3g"
],
"target": "ramips/rt305x",
"titles": [
{
"model": "HW550-3G",
"vendor": "Aztech"
},
{
"model": "ALL0239-3G",
"vendor": "Allnet"
}
],
"version_commit": "r10920+123-0cc87b3bac",
"version_number": "SNAPSHOT"
}
Signed-off-by: Paul Spooren <mail@aparcar.org>
2019-08-18 19:56:45 +00:00
|
|
|
|
2021-09-13 09:44:04 +00:00
|
|
|
if not file_path.is_file():
|
|
|
|
print("Skip JSON creation for non existing file", file_path)
|
2020-03-12 22:55:41 +00:00
|
|
|
exit(0)
|
build: create JSON files containing image info
The JSON info files contain details about the created firmware images
per device and are stored next to the created images.
The JSON files are stored as "$(IMAGE_PREFIX).json" and contain some
device/image meta data as well as a list of created firmware images.
An example of openwrt-ramips-rt305x-aztech_hw550-3g.json
{
"id": "aztech_hw550-3g",
"image_prefix": "openwrt-ramips-rt305x-aztech_hw550-3g",
"images": [
{
"name": "openwrt-ramips-rt305x-aztech_hw550-3g-squashfs-sysupgrade.bin",
"sha256": "db2b34b0ec4a83d9bf612cf66fab0dc3722b191cb9bedf111e5627a4298baf20",
"type": "sysupgrade"
}
],
"metadata_version": 1,
"supported_devices": [
"aztech,hw550-3g",
"hw550-3g"
],
"target": "ramips/rt305x",
"titles": [
{
"model": "HW550-3G",
"vendor": "Aztech"
},
{
"model": "ALL0239-3G",
"vendor": "Allnet"
}
],
"version_commit": "r10920+123-0cc87b3bac",
"version_number": "SNAPSHOT"
}
Signed-off-by: Paul Spooren <mail@aparcar.org>
2019-08-18 19:56:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_titles():
|
|
|
|
titles = []
|
|
|
|
for prefix in ["", "ALT0_", "ALT1_", "ALT2_"]:
|
|
|
|
title = {}
|
|
|
|
for var in ["vendor", "model", "variant"]:
|
2020-03-12 22:55:41 +00:00
|
|
|
if getenv("DEVICE_{}{}".format(prefix, var.upper())):
|
|
|
|
title[var] = getenv("DEVICE_{}{}".format(prefix, var.upper()))
|
build: create JSON files containing image info
The JSON info files contain details about the created firmware images
per device and are stored next to the created images.
The JSON files are stored as "$(IMAGE_PREFIX).json" and contain some
device/image meta data as well as a list of created firmware images.
An example of openwrt-ramips-rt305x-aztech_hw550-3g.json
{
"id": "aztech_hw550-3g",
"image_prefix": "openwrt-ramips-rt305x-aztech_hw550-3g",
"images": [
{
"name": "openwrt-ramips-rt305x-aztech_hw550-3g-squashfs-sysupgrade.bin",
"sha256": "db2b34b0ec4a83d9bf612cf66fab0dc3722b191cb9bedf111e5627a4298baf20",
"type": "sysupgrade"
}
],
"metadata_version": 1,
"supported_devices": [
"aztech,hw550-3g",
"hw550-3g"
],
"target": "ramips/rt305x",
"titles": [
{
"model": "HW550-3G",
"vendor": "Aztech"
},
{
"model": "ALL0239-3G",
"vendor": "Allnet"
}
],
"version_commit": "r10920+123-0cc87b3bac",
"version_number": "SNAPSHOT"
}
Signed-off-by: Paul Spooren <mail@aparcar.org>
2019-08-18 19:56:45 +00:00
|
|
|
|
|
|
|
if title:
|
|
|
|
titles.append(title)
|
|
|
|
|
|
|
|
if not titles:
|
2020-03-12 22:55:41 +00:00
|
|
|
titles.append({"title": getenv("DEVICE_TITLE")})
|
build: create JSON files containing image info
The JSON info files contain details about the created firmware images
per device and are stored next to the created images.
The JSON files are stored as "$(IMAGE_PREFIX).json" and contain some
device/image meta data as well as a list of created firmware images.
An example of openwrt-ramips-rt305x-aztech_hw550-3g.json
{
"id": "aztech_hw550-3g",
"image_prefix": "openwrt-ramips-rt305x-aztech_hw550-3g",
"images": [
{
"name": "openwrt-ramips-rt305x-aztech_hw550-3g-squashfs-sysupgrade.bin",
"sha256": "db2b34b0ec4a83d9bf612cf66fab0dc3722b191cb9bedf111e5627a4298baf20",
"type": "sysupgrade"
}
],
"metadata_version": 1,
"supported_devices": [
"aztech,hw550-3g",
"hw550-3g"
],
"target": "ramips/rt305x",
"titles": [
{
"model": "HW550-3G",
"vendor": "Aztech"
},
{
"model": "ALL0239-3G",
"vendor": "Allnet"
}
],
"version_commit": "r10920+123-0cc87b3bac",
"version_number": "SNAPSHOT"
}
Signed-off-by: Paul Spooren <mail@aparcar.org>
2019-08-18 19:56:45 +00:00
|
|
|
|
|
|
|
return titles
|
|
|
|
|
|
|
|
|
2020-03-12 22:55:41 +00:00
|
|
|
device_id = getenv("DEVICE_ID")
|
2021-09-13 09:44:04 +00:00
|
|
|
file_hash = hashlib.sha256(file_path.read_bytes()).hexdigest()
|
2020-03-12 22:55:41 +00:00
|
|
|
|
2021-09-13 09:44:04 +00:00
|
|
|
file_info = {
|
2020-03-12 22:55:41 +00:00
|
|
|
"metadata_version": 1,
|
|
|
|
"target": "{}/{}".format(getenv("TARGET"), getenv("SUBTARGET")),
|
|
|
|
"version_code": getenv("VERSION_CODE"),
|
|
|
|
"version_number": getenv("VERSION_NUMBER"),
|
2021-08-29 03:10:57 +00:00
|
|
|
"source_date_epoch": int(getenv("SOURCE_DATE_EPOCH")),
|
2020-03-12 22:55:41 +00:00
|
|
|
"profiles": {
|
|
|
|
device_id: {
|
2021-02-22 14:55:43 +00:00
|
|
|
"image_prefix": getenv("DEVICE_IMG_PREFIX"),
|
2020-03-12 22:55:41 +00:00
|
|
|
"images": [
|
|
|
|
{
|
2021-09-13 09:44:04 +00:00
|
|
|
"type": getenv("FILE_TYPE"),
|
|
|
|
"name": getenv("FILE_NAME"),
|
|
|
|
"sha256": file_hash,
|
2020-03-12 22:55:41 +00:00
|
|
|
}
|
|
|
|
],
|
2020-06-30 11:02:43 +00:00
|
|
|
"device_packages": getenv("DEVICE_PACKAGES").split(),
|
2020-03-12 22:55:41 +00:00
|
|
|
"supported_devices": getenv("SUPPORTED_DEVICES").split(),
|
|
|
|
"titles": get_titles(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-09-13 09:44:04 +00:00
|
|
|
if getenv("FILE_FILESYSTEM"):
|
|
|
|
file_info["profiles"][device_id]["images"][0]["filesystem"] = getenv(
|
|
|
|
"FILE_FILESYSTEM"
|
|
|
|
)
|
|
|
|
|
|
|
|
json_path.write_text(json.dumps(file_info, separators=(",", ":")))
|