mirror of
https://github.com/FUjr/gl-infra-builder.git
synced 2025-12-17 09:34:51 +00:00
Merge branch 'main' of github.com:gl-inet/gl-infra-builder into main
This commit is contained in:
commit
4af2d19dd7
27
.github/workflows/release.yml
vendored
Normal file
27
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
on:
|
||||
push:
|
||||
# Sequence of patterns matched against refs/tags
|
||||
tags:
|
||||
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
|
||||
|
||||
name: Create Release
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Create Release
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Create Release
|
||||
id: create_release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
|
||||
with:
|
||||
tag_name: ${{ github.ref }}
|
||||
release_name: Release ${{ github.ref }}
|
||||
body_path: |
|
||||
./README.md
|
||||
draft: false
|
||||
prerelease: true
|
||||
@ -1,224 +0,0 @@
|
||||
From d241bf66829b407e263e6233efcf923d972b80fb Mon Sep 17 00:00:00 2001
|
||||
From: Yejiang Luo <luoyejiang@gl-inet.com>
|
||||
Date: Tue, 1 Jun 2021 09:59:49 +0800
|
||||
Subject: [PATCH] scripts: add gen_config.py
|
||||
|
||||
This script is used to setup the tree based on the profiles/.
|
||||
|
||||
Signed-off-by: Yejiang Luo <luoyejiang@gl-inet.com>
|
||||
---
|
||||
openwrt-18.06/scripts/gen_config.py | 202 ++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 202 insertions(+)
|
||||
create mode 100755 openwrt-18.06/scripts/gen_config.py
|
||||
|
||||
diff --git a/openwrt-18.06/scripts/gen_config.py b/openwrt-18.06/scripts/gen_config.py
|
||||
new file mode 100755
|
||||
index 0000000..320c17e
|
||||
--- /dev/null
|
||||
+++ b/openwrt-18.06/scripts/gen_config.py
|
||||
@@ -0,0 +1,202 @@
|
||||
+#!/usr/bin/env python3
|
||||
+
|
||||
+from os import getenv
|
||||
+from pathlib import Path
|
||||
+from shutil import rmtree
|
||||
+from subprocess import run
|
||||
+from subprocess import call
|
||||
+import time
|
||||
+import sys
|
||||
+import yaml
|
||||
+
|
||||
+profile_folder = Path(getenv("PROFILES", "./profiles")).absolute()
|
||||
+
|
||||
+
|
||||
+def die(msg: str):
|
||||
+ """Quit script with error message
|
||||
+
|
||||
+ msg (str): Error message to print
|
||||
+ """
|
||||
+ print(msg)
|
||||
+ sys.exit(1)
|
||||
+
|
||||
+
|
||||
+def usage(code: int = 0):
|
||||
+ """Print script usage
|
||||
+
|
||||
+ Args:
|
||||
+ code (int): exit code
|
||||
+ """
|
||||
+ print(f"""Usage: {sys.argv[0]} <profile> [options...]
|
||||
+
|
||||
+ clean Remove feeds before setup
|
||||
+ list List available profiles
|
||||
+ help Print this message
|
||||
+ """)
|
||||
+ sys.exit(code)
|
||||
+
|
||||
+
|
||||
+def load_yaml(fname: str, profile: dict):
|
||||
+ profile_file = (profile_folder / fname).with_suffix(".yml")
|
||||
+
|
||||
+ if not profile_file.is_file():
|
||||
+ die(f"Profile {fname} not found")
|
||||
+
|
||||
+ new = yaml.safe_load(profile_file.read_text())
|
||||
+ for n in new:
|
||||
+ if n in {"profile", "target", "subtarget", "external_target"}:
|
||||
+ if profile.get(n):
|
||||
+ die(f"Duplicate tag found {n}")
|
||||
+ profile.update({n: new.get(n)})
|
||||
+ elif n in {"description"}:
|
||||
+ profile["description"].append(new.get(n))
|
||||
+ elif n in {"packages"}:
|
||||
+ profile["packages"].extend(new.get(n))
|
||||
+ elif n in {"diffconfig"}:
|
||||
+ profile["diffconfig"] += new.get(n)
|
||||
+ elif n in {"feeds"}:
|
||||
+ for f in new.get(n):
|
||||
+ if f.get("name", "") == "" or (f.get("uri", "") == "" and f.get("path", "") == ""):
|
||||
+ die(f"Found bad feed {f}")
|
||||
+ profile["feeds"][f.get("name")] = f
|
||||
+ return profile
|
||||
+
|
||||
+
|
||||
+def clean_tree():
|
||||
+ print("Cleaning tree")
|
||||
+ rmtree("./tmp", ignore_errors=True)
|
||||
+ rmtree("./packages/feeds/", ignore_errors=True)
|
||||
+ rmtree("./tmp/", ignore_errors=True)
|
||||
+ rmtree(".git/rebase-apply/", ignore_errors=True)
|
||||
+ if Path("./feeds.conf").is_file():
|
||||
+ Path("./feeds.conf").unlink()
|
||||
+ if Path("./.config").is_file():
|
||||
+ Path("./.config").unlink()
|
||||
+
|
||||
+
|
||||
+def merge_profiles(profiles):
|
||||
+ profile = {"packages": [], "description": [], "diffconfig": "", "feeds": {}}
|
||||
+
|
||||
+ for p in profiles:
|
||||
+ profile = load_yaml(p, profile)
|
||||
+
|
||||
+ return profile
|
||||
+
|
||||
+
|
||||
+def setup_feeds(profile):
|
||||
+ feeds_conf = Path("feeds.conf")
|
||||
+ if feeds_conf.is_file():
|
||||
+ feeds_conf.unlink()
|
||||
+
|
||||
+ feeds = []
|
||||
+ for p in profile.get("feeds", []):
|
||||
+ try:
|
||||
+ f = profile["feeds"].get(p)
|
||||
+ if all(k in f for k in ("branch", "revision", "path")):
|
||||
+ die(f"Please specify either a branch, a revision or a path: {f}")
|
||||
+ if "path" in f:
|
||||
+ feeds.append(f'{f.get("method", "src-link")},{f["name"]},{f["path"]}')
|
||||
+ elif "revision" in f:
|
||||
+ feeds.append(f'{f.get("method", "src-git")},{f["name"]},{f["uri"]}^{f.get("revision")}')
|
||||
+ else:
|
||||
+ feeds.append(f'{f.get("method", "src-git")},{f["name"]},{f["uri"]};{f.get("branch", "master")}')
|
||||
+
|
||||
+ except:
|
||||
+ print(f"Badly configured feed: {f}")
|
||||
+
|
||||
+ if run(["./scripts/feeds", "uninstall", "-a"]).returncode:
|
||||
+ die(f"Error uninstall feeds")
|
||||
+
|
||||
+ if run(["./scripts/feeds", "setup", "-b", *feeds]).returncode:
|
||||
+ die(f"Error setting up feeds")
|
||||
+
|
||||
+ if run(["./scripts/feeds", "update"]).returncode:
|
||||
+ die(f"Error updating feeds")
|
||||
+
|
||||
+ for p in profile.get("feeds", []):
|
||||
+ f = profile["feeds"].get(p)
|
||||
+ if run(["./scripts/feeds", "install", "-a", "-f", "-p", f.get("name")]).returncode:
|
||||
+ die(f"Error installing {feed}")
|
||||
+
|
||||
+ packages = ["./scripts/feeds", "install"]
|
||||
+ for package in profile.get("packages", []):
|
||||
+ packages.append(package)
|
||||
+ if len(packages) > 2:
|
||||
+ if run(packages).returncode:
|
||||
+ die(f"Error installing packages")
|
||||
+
|
||||
+ if profile.get("external_target", False):
|
||||
+ if run(["./scripts/feeds", "install", profile["target"]]).returncode:
|
||||
+ die(f"Error installing external target {profile['target']}")
|
||||
+
|
||||
+def setup_all_feeds():
|
||||
+ print("Install all feeds...")
|
||||
+ if run(["./scripts/feeds", "install", "-a", "-f"]).returncode:
|
||||
+ die(f"Error installing")
|
||||
+
|
||||
+def generate_config(profile):
|
||||
+ config_output = f"""CONFIG_TARGET_{profile["target"]}=y
|
||||
+CONFIG_TARGET_{profile["target"]}_{profile["subtarget"]}=y
|
||||
+CONFIG_TARGET_{profile["target"]}_{profile["subtarget"]}_{profile["profile"]}=y
|
||||
+"""
|
||||
+
|
||||
+ config_output += f"{profile.get('diffconfig', '')}"
|
||||
+
|
||||
+ for package in profile.get("packages", []):
|
||||
+ print(f"Add package to .config: {package}")
|
||||
+ config_output += f"CONFIG_PACKAGE_{package}=y\n"
|
||||
+
|
||||
+ Path(".config").write_text(config_output)
|
||||
+ print("Configuration written to .config")
|
||||
+
|
||||
+
|
||||
+def generate_files(profile):
|
||||
+ if run(["mkdir", "-p", "files/etc"]).returncode:
|
||||
+ die(f"Error create files")
|
||||
+
|
||||
+ compile_time = time.strftime('%Y-%m-%d %k:%M:%S', time.localtime(time.time()))
|
||||
+ call("echo %s > %s" % (compile_time, "files/etc/version.date"), shell=True)
|
||||
+
|
||||
+
|
||||
+if __name__ == "__main__":
|
||||
+ if "list" in sys.argv:
|
||||
+ print(f"Profiles in {profile_folder}")
|
||||
+ print("Target Profiles:")
|
||||
+ print("\n".join(sorted(map(lambda p: str(p.stem), profile_folder.glob("target_*.yml")))))
|
||||
+ print("\nFunction Profiles:")
|
||||
+ print("\n".join(sorted(map(lambda p: str(p.stem), profile_folder.glob('[!t]*.yml')))))
|
||||
+ quit(0)
|
||||
+
|
||||
+ if "help" in sys.argv:
|
||||
+ usage()
|
||||
+
|
||||
+ if len(sys.argv) < 2:
|
||||
+ usage(1)
|
||||
+
|
||||
+ if "clean" in sys.argv:
|
||||
+ clean_tree()
|
||||
+ print("Tree is now clean")
|
||||
+ quit(0)
|
||||
+
|
||||
+ profile = merge_profiles(sys.argv[1:])
|
||||
+
|
||||
+ print("Using the following profiles:")
|
||||
+ for d in profile.get("description"):
|
||||
+ print(f" - {d}")
|
||||
+
|
||||
+ clean_tree()
|
||||
+ setup_feeds(profile)
|
||||
+ setup_all_feeds()
|
||||
+ generate_config(profile)
|
||||
+ generate_files(profile)
|
||||
+
|
||||
+ print("Running make defconfig")
|
||||
+ if run(["make", "defconfig"]).returncode:
|
||||
+ die(f"Error running make defconfig")
|
||||
+
|
||||
+ if call("grep 'CONFIG_TARGET_PROFILE' .config|grep %s" % (profile['profile']), shell=True) != 0:
|
||||
+ die(f"Error: Cant not find the profile '%s'! Please check again!" % (profile['profile']))
|
||||
+
|
||||
+ for package in profile['packages']:
|
||||
+ if call("grep 'CONFIG_PACKAGE_%s=y' .config" % (package), shell=True) != 0:
|
||||
+ die(f"Error: the package '%s' is not found or is not configured!" % (package))
|
||||
--
|
||||
2.7.4
|
||||
|
||||
@ -43,8 +43,8 @@ def usage(code: int = 0):
|
||||
sys.exit(code)
|
||||
|
||||
def load_metadata():
|
||||
with open("gl_metadata.yaml", "r") as stream:
|
||||
try:
|
||||
try:
|
||||
with open("gl_metadata.yaml", "r") as stream:
|
||||
metadata=yaml.safe_load(stream)
|
||||
version = metadata["version"]
|
||||
call("echo %s > %s" % (version, "files/etc/glversion"), shell=True)
|
||||
@ -53,8 +53,9 @@ def load_metadata():
|
||||
call("echo %s > %s" % (version_type, "files/etc/version.type"), shell=True)
|
||||
print("firmware version: " +version)
|
||||
print("firmware type: " +version_type)
|
||||
except yaml.YAMLError as exc:
|
||||
print("load gl metadata failed")
|
||||
except:
|
||||
pass
|
||||
#print("load gl metadata failed")
|
||||
|
||||
|
||||
def load_yaml(fname: str, profile: dict):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user