From 5c0ca6658fe4087f71283145e09edf83831d9533 Mon Sep 17 00:00:00 2001
From: hugcabbage <77980779+hugcabbage@users.noreply.github.com>
Date: Wed, 24 Jan 2024 00:35:37 +0800
Subject: [PATCH] multi: scripts update
---
extra-files/modify-xiaomi-router-4a-3g-v2.sh | 11 +-
extra-files/renew.py | 11 +-
extra-files/tools/__init__.py | 0
extra-files/tools/code_summary.py | 134 +++++------
extra-files/tools/color.py | 16 ++
extra-files/tools/color.sh | 37 +++
extra-files/tools/crypt_text.py | 0
extra-files/tools/process_text.py | 224 ++++++++----------
extra-files/tools/routine_cmd.py | 0
extra-files/tools/workflow.py | 0
extra-files/transit.py | 232 ++++++++++++-------
extra-files/update-geodata.sh | 33 ++-
preset-immortalwrt/1.clone.sh | 2 +-
preset-immortalwrt/1.modify.sh | 5 +-
preset-lede/1.clone.sh | 7 +-
preset-lede/1.modify.sh | 3 +-
preset-lienol-openwrt/1.clone.sh | 7 +-
preset-lienol-openwrt/1.modify.sh | 2 +-
preset-openwrt/1.clone.sh | 5 +-
preset-openwrt/1.modify.sh | 19 +-
preset-x-wrt/1.clone.sh | 2 +-
preset-x-wrt/1.modify.sh | 14 +-
templet/produce.py | 36 +--
23 files changed, 463 insertions(+), 337 deletions(-)
mode change 100644 => 100755 extra-files/modify-xiaomi-router-4a-3g-v2.sh
mode change 100644 => 100755 extra-files/renew.py
mode change 100644 => 100755 extra-files/tools/__init__.py
mode change 100644 => 100755 extra-files/tools/code_summary.py
create mode 100644 extra-files/tools/color.py
create mode 100644 extra-files/tools/color.sh
mode change 100644 => 100755 extra-files/tools/crypt_text.py
mode change 100644 => 100755 extra-files/tools/process_text.py
mode change 100644 => 100755 extra-files/tools/routine_cmd.py
mode change 100644 => 100755 extra-files/tools/workflow.py
mode change 100644 => 100755 extra-files/transit.py
mode change 100644 => 100755 extra-files/update-geodata.sh
mode change 100644 => 100755 preset-immortalwrt/1.clone.sh
mode change 100644 => 100755 preset-immortalwrt/1.modify.sh
mode change 100644 => 100755 preset-lede/1.clone.sh
mode change 100644 => 100755 preset-lede/1.modify.sh
mode change 100644 => 100755 preset-lienol-openwrt/1.clone.sh
mode change 100644 => 100755 preset-lienol-openwrt/1.modify.sh
mode change 100644 => 100755 preset-openwrt/1.clone.sh
mode change 100644 => 100755 preset-openwrt/1.modify.sh
mode change 100644 => 100755 preset-x-wrt/1.clone.sh
mode change 100644 => 100755 preset-x-wrt/1.modify.sh
diff --git a/extra-files/modify-xiaomi-router-4a-3g-v2.sh b/extra-files/modify-xiaomi-router-4a-3g-v2.sh
old mode 100644
new mode 100755
index 2fcc1887..a6eef88e
--- a/extra-files/modify-xiaomi-router-4a-3g-v2.sh
+++ b/extra-files/modify-xiaomi-router-4a-3g-v2.sh
@@ -1,8 +1,15 @@
-#!/bin/sh
+#!/usr/bin/env bash
AIMFILE=target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-common.dtsi
AIDFILE=target/linux/ramips/dts/mt7621_youhua_wr1200js.dts
-[ ! -e "$AIMFILE" ] && AIMFILE=target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-3g-v2.dtsi
+[ -e "$AIMFILE" ] || AIMFILE=target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-3g-v2.dtsi
+
+MARK="// The file has been modified by@hugcabbage"
+if grep -q "$MARK" $AIMFILE; then
+ exit 0
+else
+ sed -i "1i $MARK" $AIMFILE
+fi
SPECIFIC_LINE=$(sed -n '/&spi0/=' $AIMFILE)
BASE_TEXT=$(sed '/&spi0/,/^};/d' $AIMFILE)
diff --git a/extra-files/renew.py b/extra-files/renew.py
old mode 100644
new mode 100755
index a7bebf7a..1c73bf0e
--- a/extra-files/renew.py
+++ b/extra-files/renew.py
@@ -3,8 +3,8 @@
import os
import shutil
+from tools.process_text import check_header_existence
from tools.process_text import generate_header
-from tools.process_text import get_remain_text
from tools.process_text import modify_config_header
from tools.process_text import simplify_config
from tools.routine_cmd import gen_dot_config
@@ -17,13 +17,14 @@ def main():
fce = f'{destdir}/{fclone}' if os.path.exists(f'{destdir}/{fclone}') else f'{destdir}/1.clone.sh'
fcg = f'{destdir}/{fconfig}'
- rt = get_remain_text(fcg)
+ has_header = check_header_existence(fcg)
- sample = {'xiaomi-ac2100': ['xx', 'ramips', 'mt7621', 'xiaomi_mi-router-ac2100']}
- modify_config_header(fcg, generate_header(sample, 'xiaomi-ac2100'))
+ if not has_header:
+ sample = {'xiaomi-ac2100': ['xx', 'ramips', 'mt7621', 'xiaomi_mi-router-ac2100']}
+ modify_config_header(fcg, generate_header(sample, 'xiaomi-ac2100'))
gen_dot_config(fce, fcg)
- simplify_config(fcg, remain_text=rt)
+ simplify_config(fcg, keep_header=has_header)
# Move .fullbak to the backups directory
os.makedirs(bas := f'{destdir}/backups', exist_ok=True)
diff --git a/extra-files/tools/__init__.py b/extra-files/tools/__init__.py
old mode 100644
new mode 100755
diff --git a/extra-files/tools/code_summary.py b/extra-files/tools/code_summary.py
old mode 100644
new mode 100755
index ca955d78..ef2eb7aa
--- a/extra-files/tools/code_summary.py
+++ b/extra-files/tools/code_summary.py
@@ -3,6 +3,7 @@
import re
import subprocess
from datetime import datetime
+from urllib.parse import urlparse
from zoneinfo import ZoneInfo
@@ -18,6 +19,10 @@ class CodeSummary:
login_ip: str
login_user: str
login_pwd: str
+ board: str
+ subtarget: str
+ arch_packages: str
+ profile: list
def __init__(self, codedir):
self.codedir = codedir
@@ -28,24 +33,11 @@ def __init__(self, codedir):
@property
def summary_dict(self):
- last_log = self.get_last_log()
- build_date = self.get_build_date()
- login_info = self.get_login_info()
- profiles = self.get_profiles()
return {
- 'code_from': last_log[0],
- 'code_branch': last_log[1],
- 'code_tag': last_log[2],
- 'code_commit_hash': last_log[3],
- 'code_commit_date': last_log[4],
- 'build_date': build_date,
- 'login_ip': login_info[0],
- 'login_user': login_info[1],
- 'login_pwd': login_info[2],
- 'board': profiles[0],
- 'subtarget': profiles[1],
- 'arch_packages': profiles[2],
- 'profile': profiles[3]
+ **self.get_last_log(),
+ **self.get_build_date(),
+ **self.get_login_info(),
+ **self.get_profiles()
}
def get_profiles(self):
@@ -54,28 +46,47 @@ def get_profiles(self):
CONFIG_TARGET_BOARD="ramips"
CONFIG_TARGET_SUBTARGET="mt7621"
CONFIG_TARGET_ARCH_PACKAGES="mipsel_24kc"
+ CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mi-router-ac2100=y
CONFIG_TARGET_DEVICE_ramips_mt7621_DEVICE_xiaomi_mi-router-ac2100=y
"""
file = self.config
- board, subtarget, arch_packages, profile = '', '', '', []
+ profiles = {
+ 'board': '',
+ 'subtarget': '',
+ 'arch_packages': '',
+ 'profile': []
+ }
+ patterns = {
+ 'board': r'CONFIG_TARGET_BOARD="(.*)"',
+ 'subtarget': r'CONFIG_TARGET_SUBTARGET="(.*)"',
+ 'arch_packages': r'CONFIG_TARGET_ARCH_PACKAGES="(.*)"',
+ 'profile': r'CONFIG_TARGET_(?!PER_).*DEVICE_(.*)=y'
+ }
with open(file, encoding='utf-8') as f:
for line in f:
- if line.startswith('CONFIG_TARGET_BOARD='):
- board = line.split('=')[1].strip().strip('"')
- elif line.startswith('CONFIG_TARGET_SUBTARGET='):
- subtarget = line.split('=')[1].strip().strip('"')
- elif line.startswith('CONFIG_TARGET_DEVICE_') and line.endswith('=y\n'):
- profile.append(line.strip().split("_DEVICE_")[-1].split("=")[0])
- elif line.startswith('CONFIG_TARGET_ARCH_PACKAGES='):
- arch_packages = line.split('=')[1].strip().strip('"')
-
- if all([board, subtarget, arch_packages, profile]):
+ for k, v in patterns.items():
+ m = re.match(v, line)
+ try:
+ profiles[k].append(m.group(1))
+ except AttributeError:
+ profiles[k] = m.group(1)
+ finally:
+ continue
+ if re.match('CONFIG_LINUX_', line):
break
- return board, subtarget, arch_packages, profile
+ return profiles
def get_last_log(self):
- prev_dir = os.getcwd()
+ log = {
+ 'code_from': '',
+ 'code_branch': [],
+ 'code_tag': [],
+ 'code_commit_hash': '',
+ 'code_commit_date': ''
+ }
+
+ prev_path = os.getcwd()
os.chdir(self.codedir)
code_url = subprocess.run(
'git remote get-url origin',
@@ -84,40 +95,39 @@ def get_last_log(self):
text=True).stdout.strip()
code_name_table = {
- ('coolsnowwolf', 'lede'): 'lede'
+ 'coolsnowwolf/lede': 'lede'
}
- code_ = tuple(code_url.rstrip('/').removesuffix('.git').split('/')[-2:])
+ code_ = urlparse(code_url).path[1:].removesuffix('.git')
try:
- code_from = code_name_table[code_]
+ log['code_from'] = code_name_table[code_]
except KeyError:
- if code_[0] == code_[1]:
- code_from = code_[0]
+ m = code_.split('/')
+ if m[0] == m[1]:
+ log['code_from'] = m[0]
else:
- code_from = code_[0] + '/' + code_[1]
+ log['code_from'] = code_
code_commit_log = subprocess.run(
'git log -1 --pretty=format:%cI%n%h%n%D',
shell=True,
capture_output=True,
text=True).stdout.strip().split('\n')
- code_commit_date = datetime.fromisoformat(
+ log['code_commit_date'] = datetime.fromisoformat(
code_commit_log[0]).astimezone(ZoneInfo('Asia/Shanghai')).isoformat()
- code_commit_hash = code_commit_log[1][:7]
+ log['code_commit_hash'] = code_commit_log[1][:7]
code_ref = code_commit_log[2].replace(' ', '').split(',')
- code_branch = []
- code_tag = []
for r in code_ref:
if r.startswith('HEAD->'):
- code_branch.append(r[6:])
+ log['code_branch'].append(r[6:])
elif r.startswith('tag:'):
- code_tag.append(r[4:])
+ log['code_tag'].append(r[4:])
elif '/' in r or r == 'HEAD' or r == 'grafted':
pass
else:
- code_branch.append(r)
+ log['code_branch'].append(r)
- if not code_branch:
+ if not log['code_branch']:
tag_belong_to = subprocess.run(
'git branch --contains HEAD',
shell=True,
@@ -125,35 +135,29 @@ def get_last_log(self):
text=True).stdout.strip().split('\n')
for tb in tag_belong_to:
if not tb.startswith('* (HEAD detached'):
- code_branch.append(tb.strip())
- if not code_tag:
- code_tag.append('snapshot')
+ log['code_branch'].append(tb.strip())
+ if not log['code_tag']:
+ log['code_tag'].append('snapshot')
- for i, cb in enumerate(code_branch.copy()):
- code_branch[i] = cb.removeprefix('openwrt-')
- for i, ct in enumerate(code_tag.copy()):
- code_tag[i] = ct.removeprefix('v')
+ for i, cb in enumerate(log['code_branch'].copy()):
+ log['code_branch'][i] = cb.removeprefix('openwrt-')
+ for i, ct in enumerate(log['code_tag'].copy()):
+ log['code_tag'][i] = ct.removeprefix('v')
- os.chdir(prev_dir)
+ os.chdir(prev_path)
- return (
- code_from,
- code_branch,
- code_tag,
- code_commit_hash,
- code_commit_date
- )
+ return log
def get_build_date(self):
- return datetime.now(ZoneInfo('Asia/Shanghai')).replace(microsecond=0).isoformat()
+ return {'build_date': datetime.now(ZoneInfo('Asia/Shanghai')).replace(microsecond=0).isoformat()}
def get_login_info(self):
username, password_id = self.__login_user()
- return (
- self.__login_ip(),
- username,
- self.__login_pwd(password_id)
- )
+ return {
+ 'login_user': username,
+ 'login_ip': self.__login_ip(),
+ 'login_pwd': self.__login_pwd(password_id)
+ }
def __login_ip(self):
"""Read the ip address from the config_generate file
diff --git a/extra-files/tools/color.py b/extra-files/tools/color.py
new file mode 100644
index 00000000..4bea055a
--- /dev/null
+++ b/extra-files/tools/color.py
@@ -0,0 +1,16 @@
+def _wrap_with(code):
+
+ def inner(text, bold=False):
+ c = code
+ if bold:
+ c = '1;{!s}'.format(c)
+ return '\033[{!s}m{!s}\033[0m'.format(c, text)
+ return inner
+
+red = _wrap_with(31)
+green = _wrap_with(32)
+yellow = _wrap_with(33)
+blue = _wrap_with(34)
+magenta = _wrap_with(35)
+cyan = _wrap_with(36)
+white = _wrap_with(37)
diff --git a/extra-files/tools/color.sh b/extra-files/tools/color.sh
new file mode 100644
index 00000000..39923af3
--- /dev/null
+++ b/extra-files/tools/color.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+color_out() {
+ if [ "$3" = "bold" ]; then
+ printf "\e[1;$1m%s\e[0;0m\n" "$2"
+ else
+ printf "\e[0;$1m%s\e[0;0m\n" "$2"
+ fi
+}
+
+red() {
+ color_out 31 "$1" "$2"
+}
+
+green() {
+ color_out 32 "$1" "$2"
+}
+
+yellow() {
+ color_out 33 "$1" "$2"
+}
+
+blue() {
+ color_out 34 "$1" "$2"
+}
+
+magenta() {
+ color_out 35 "$1" "$2"
+}
+
+cyan() {
+ color_out 36 "$1" "$2"
+}
+
+white() {
+ color_out 37 "$1" "$2"
+}
diff --git a/extra-files/tools/crypt_text.py b/extra-files/tools/crypt_text.py
old mode 100644
new mode 100755
diff --git a/extra-files/tools/process_text.py b/extra-files/tools/process_text.py
old mode 100644
new mode 100755
index 5792844f..2d969a6f
--- a/extra-files/tools/process_text.py
+++ b/extra-files/tools/process_text.py
@@ -1,16 +1,14 @@
"""Text processing"""
import json
-import os
import re
import shutil
-import sys
-def mlength(seq) -> int:
+def mlength(iterable) -> int:
"""Get the length of the longest element in the sequence"""
lengths = []
- for item in seq:
+ for item in iterable:
if isinstance(item, (list, tuple)):
mitem = mlength(item)
lengths.append(mitem)
@@ -23,39 +21,41 @@ def mlength(seq) -> int:
return 0
-def rectangles(*lists) -> tuple[list, list]:
+def rectangles(*iterables) -> tuple[list, list]:
"""Get the length (number of elements) and
- width (length of the longest element) of multiple lists
+ width (length of the longest element) of multiple sequences
"""
lengths = []
widths = []
- for lst in lists:
- lengths.append(len(lst))
- widths.append(mlength(lst))
+ for col in iterables:
+ lengths.append(len(col))
+ widths.append(mlength(col))
return lengths, widths
-def to_markdown_table(*lists) -> str:
- """Convert multiple lists to markdown tables"""
+def to_markdown_table(*iterables) -> str:
+ """Convert multiple sequences to Markdown tables"""
- # Calculate the maximum width of each column and determine whether all columns have the same length
- col_lengths, col_widths = rectangles(*lists)
+ # Calculate the maximum width of each column and
+ # check if all columns have the same number of elements
+ col_lengths, col_widths = rectangles(*iterables)
if len(set(col_lengths)) != 1:
- print('The list length is not uniform')
- sys.exit()
+ print('The number of elements in multiple columns is not equal,'
+ 'and they cannot be matched one-to-one')
+ return ''
# Create table header
header = '|' + '|'.join(str(lst[0]).center(col_widths[i])
- for i, lst in enumerate(lists)) + '|\n'
+ for i, lst in enumerate(iterables)) + '|\n'
separator = '|' + \
- '|'.join('-' * (col_widths[i]) for i in range(len(lists))) + '|\n'
+ '|'.join('-' * (col_widths[i]) for i in range(len(iterables))) + '|\n'
# Create table content
rows = ''
for i in range(1, col_lengths[0]):
row = '|'
- for j, lst in enumerate(lists):
+ for j, lst in enumerate(iterables):
if i < len(lst):
if isinstance(lst[i], (list, tuple)):
row += '
'.join(map(str, lst[i])).center(col_widths[j])
@@ -72,36 +72,14 @@ def to_markdown_table(*lists) -> str:
def manifest_to_lists(file) -> tuple[list, list]:
"""Convert manifest file into two lists"""
- if not os.path.isfile(file):
- print(f'Error: {file} does not exist.')
- sys.exit()
-
with open(file, encoding='utf-8') as f:
- lines = f.readlines()
-
- package = []
- version = []
- for line in lines:
- parts = line.strip().split(' - ')
- if len(parts) != 2:
- print(f'Error: invalid line format -> {line}')
- continue
- if parts[0] == 'kernel':
- parts[1] = parts[1][:-26]
- if parts[0].startswith('kmod-'):
- continue
- if parts[0].startswith('lib'):
- continue
- if 'i18n' in parts[0]:
- continue
- if 'lib-' in parts[0]:
- continue
- if 'mod-' in parts[0]:
- continue
- package.append(parts[0])
- version.append(parts[1])
-
- return package, version
+ text = f.read()
+ p1 = re.compile(r'^(kernel.*).{25}$', re.MULTILINE)
+ p2 = re.compile(r'^(?!.*lib\S|ruby-|.*mod-|.*i18n)(.*) - (.*)', re.MULTILINE)
+ text = p1.sub(r'\1', text)
+ m = p2.findall(text)
+ package, version = zip(*m)
+ return list(package), list(version)
def xlsx_to_dict(file) -> dict:
@@ -134,63 +112,38 @@ def dict_to_json(data: dict) -> str:
return json_str
-def get_remain_text(config) -> list:
+def check_header_existence(config):
with open(config, encoding='utf-8') as f:
- text = f.readlines()
-
- s, e = 0, 0
- for i, line in enumerate(text):
- if all(x in line for x in ('CONFIG_TARGET_', 'DEVICE')):
- s = i + 1
- elif '# Applications' in line:
- e = i
- break
- while not text[s].strip():
- s += 1
- while not text[e - 1].strip():
- e -= 1
-
- return text[s:e]
+ for line in f:
+ if line.startswith('CONFIG_TARGET'):
+ return True
+ if 'CONFIG_PACKAGE' in line:
+ return False
+ return False
-def generate_header(headers: dict, model: str) -> list:
+def generate_header(headers: dict, model: str) -> str:
t1, t2, t3 = headers[model][1:4]
- header = [
- f'CONFIG_TARGET_{t1}=y\n',
- f'CONFIG_TARGET_{t1}_{t2}=y\n',
- f'CONFIG_TARGET_{t1}_{t2}_DEVICE_{t3}=y\n'
- ]
+ header = (
+ '# Target\n'
+ f'CONFIG_TARGET_{t1}=y\n'
+ f'CONFIG_TARGET_{t1}_{t2}=y\n'
+ f'CONFIG_TARGET_{t1}_{t2}_DEVICE_{t3}=y\n')
return header
-def get_header_index(config) -> list:
- h_index = []
- with open(config, encoding='utf-8') as f:
- for i, line in enumerate(f):
- if line.startswith('CONFIG_TARGET') and line.endswith('=y\n'):
- h_index.append(i)
- if len(h_index) == 3 or i > 500:
- break
- return h_index
-
-
-def modify_config_header(config, header: list, new_file=None):
+def modify_config_header(config, header, new_file=None):
"""Replace or add header"""
- h_index = get_header_index(config)
+ p = '^CONFIG_TARGET_.*=y$'
with open(config, 'r+', encoding='utf-8') as f:
- content = f.readlines()
- if h_index:
- for i in range(3):
- content[h_index[i]] = header[i]
+ content = re.sub(p, '', f.read(), flags=re.MULTILINE)
+ if new_file:
+ with open(new_file, 'w', encoding='utf-8') as fn:
+ fn.write(header + content)
else:
- content[0:0] = header
- if not new_file:
f.seek(0, 0)
- f.writelines(content)
- return
- with open(new_file, 'w', encoding='utf-8') as f:
- f.writelines(content)
+ f.write(header + content)
def check_device_support_single(url, define_str):
@@ -206,53 +159,58 @@ def check_device_support_single(url, define_str):
return False
-def simplify_config(config, *, backup=True, remain_text: list = None, keep_header=False):
- """Simplify .config file, keep only applications and themes"""
+def get_shell_variables(text) -> dict:
+ """Get global variables in a shell script text"""
- if backup:
- shutil.copyfile(config, config + '.fullbak')
+ pattern = re.compile(r'^([a-zA-Z_][a-zA-Z0-9_]*)=(.*)$', re.MULTILINE)
+ matches = pattern.findall(text)
+ variables = {match[0]: match[1] for match in matches}
+ return variables
- header, apps, themes = [], [], []
- with open(config, encoding='utf-8') as f:
- apps_range, themes_range = False, False
- for line in f:
- if len(header) < 3 and line.startswith('CONFIG_TARGET') and line.endswith('=y\n'):
- header.append(line)
- elif re.match(r'# \d+\. Applications', line):
- apps_range = True
- elif re.match(r'# end of \d+\. Applications', line):
- apps_range = False
- elif apps_range:
- apps.append(line)
- elif re.match(r'# \d+\. Themes', line):
- themes_range = True
- elif re.match(r'# end of \d+\. Themes', line):
- themes_range = False
- elif themes_range:
- themes.append(line)
-
- if keep_header:
- header.insert(0, '# Target\n')
- header.append('\n')
- else:
- header.clear()
- if remain_text:
- remain_text.append('\n')
- else:
- remain_text = []
+def renew_shell_variables(text, variables, renews: dict) -> tuple[str, dict]:
+ """Renew variables in a shell script text"""
- re_remove_text = [
- r'^\n$',
- r'^#\n$',
- r'^# Configuration',
- r'^# end of'
+ for k, v in renews.items():
+ try:
+ p_old_str = rf'^{k}={variables[k]}$'
+ variables[k] = v
+ text = re.sub(p_old_str, rf'{k}={v}', text, flags=re.MULTILINE)
+ except KeyError:
+ pass
+ return text, variables
+
+
+def simplify_config(config, *, backup=True, keep_header=True):
+ save = ['# Target']
+ p1 = [
+ r'(CONFIG_TARGET_.*=y(?s:.*)CONFIG_LINUX_.*=y)',
+ r'(# \d\. Collections(?s:.*)# end of \d\. Modules)',
+ r'(# \d\. Applications(?s:.*)# end of \d\. Themes)'
+ ]
+ p2 = [
+ r'^CONFIG_TARGET_.*=y',
+ r'^# \d\.[\w ]+|^CONFIG_.*=y',
+ r'^# \d\.[\w ]+|^(?:# )?CONFIG_.*'
]
- apps = ['# Applications\n'] + [x for x in apps if not any(re.match(r, x) for r in re_remove_text)] + ['\n']
- themes = ['# Themes\n'] + [x for x in themes if not any(re.match(r, x) for r in re_remove_text)]
+ if backup:
+ shutil.copyfile(config, config + '.fullbak')
+ if not keep_header:
+ p1.pop(0)
+ p2.pop(0)
+ save.clear()
+
+ with open(config, encoding='utf-8') as f:
+ text = f.read()
+
+ m = re.findall('(?s:.*)'.join(p1), text)[0]
+ for i, p in enumerate(p2):
+ save.extend(re.findall(p, m[i], re.MULTILINE))
- text = header + remain_text + apps + themes
+ text = re.sub(r'^# \d\.([\w ]+)', r'\n#\1',
+ '\n'.join(save) + '\n', flags=re.MULTILINE)
+ text = re.sub(r'^\s+', '', text)
with open(config, 'w', encoding='utf-8') as f:
- f.writelines(text)
+ f.write(text)
diff --git a/extra-files/tools/routine_cmd.py b/extra-files/tools/routine_cmd.py
old mode 100644
new mode 100755
diff --git a/extra-files/tools/workflow.py b/extra-files/tools/workflow.py
old mode 100644
new mode 100755
diff --git a/extra-files/transit.py b/extra-files/transit.py
old mode 100644
new mode 100755
index 069dab9d..dcfefc27
--- a/extra-files/transit.py
+++ b/extra-files/transit.py
@@ -2,83 +2,91 @@
import glob
import json
import os
+import re
import shutil
from urllib.parse import urlparse
from tools.code_summary import CodeSummary
+from tools.color import *
from tools.crypt_text import crypt_str
from tools.process_text import check_device_support_single
+from tools.process_text import check_header_existence
from tools.process_text import generate_header
+from tools.process_text import get_shell_variables
from tools.process_text import manifest_to_lists
from tools.process_text import modify_config_header
+from tools.process_text import renew_shell_variables
from tools.process_text import to_markdown_table
from tools.workflow import set_output
from tools.workflow import set_summary
-def get_code_dir(clone_sh):
- with open(clone_sh, encoding='utf-8') as f:
- text = f.read()
- i = text.index('CODE_DIR=')
- j = text[i:].index('\n')
- codedir = text[i:][:j].split('=')[1]
- return codedir
+def switch_branch_or_tag(headers, model, text, variables, branch, ltag):
+ renews = dict()
+ url_frame = 'https://raw.githubusercontent.com/{code}/{branch}/target/linux/{t1}/image/{t2}.mk'
+ define_frame = 'define Device/{t3}'
+ if branch:
+ try:
+ code = urlparse(variables['CODE_URL']).path[1:].removesuffix('.git')
+ arguments = dict(zip(
+ ('code', 'branch', 't1', 't2', 't3'),
+ (code, branch, *headers[model][1:4])))
+ except TypeError:
+ # If hearders is None, switch the branch directly
+ # without checking if the branch supports the device
+ renews['CODE_BRANCH'] = branch
+ else:
+ mk_url = url_frame.format(**arguments)
+ define_str = define_frame.format(**arguments)
+ if check_device_support_single(mk_url, define_str):
+ renews['CODE_BRANCH'] = branch
+ else:
+ print(red(f"{branch} doesn't support this model,\nand the branch keeps default value"))
-def produce_temp_workfiles(headers: dict, model: str, temp: str, *, branch=None, ltag=False, ip=None, pwd=None) -> dict:
- """Generate temporary work files to make workflow easy to call,
- temp is the prefix for temporary files in the compilation process
- """
+ if ltag:
+ renews['SWITCH_LATEST_TAG'] = 'true'
+
+ return renew_shell_variables(text, variables, renews)
- num = num_ori = headers[model][0]
- t1, t2, t3 = headers[model][1:4]
- files = dict()
- # Generate temporary .config
- if not os.path.exists(num_ori + '.config'):
- num = '1'
- header = generate_header(headers, model)
- modify_config_header(num + '.config', header, tc1 := temp + '.config')
- files['dot_config'] = tc1
+def generate_temp_config(headers, model, temp, ori):
+ file = ori + '.config'
+ if not os.path.exists(file):
+ raise FileNotFoundError(red(f'{file} not found'))
+ if headers:
+ header = generate_header(headers, model)
+ modify_config_header(file, header, tc1 := temp + '.config')
+ else:
+ if not check_header_existence(file):
+ raise RuntimeError(red(f'{file} has no "CONFIG_TARGET_" string'))
+ shutil.copyfile(file, tc1 := temp + '.config')
+ return tc1
- # Generate temporary clone.sh
- if not os.path.exists(num_ori + '.clone.sh'):
- num = '1'
+
+def generate_temp_clone_sh(headers, model, temp, ori, branch, ltag):
+ num = ori if os.path.exists(ori + '.clone.sh') else '1'
with open(num + '.clone.sh', encoding='utf-8') as f:
- text = f.readlines()
- can_switch_branch = False
- for i, line in enumerate(text.copy()):
- if line.startswith('CODE_URL=') and branch:
- code = urlparse(line.split('=')[-1].strip()).path[1:].removesuffix('.git')
- subtarget_mk_url = f'https://raw.githubusercontent.com/{code}/{branch}/target/linux/{t1}/image/{t2}.mk'
- device_define_str = f'define Device/{t3}'
- if check_device_support_single(subtarget_mk_url, device_define_str):
- can_switch_branch = True
- else:
- print(f'{branch} branch does not support this model,\n'
- f'and the branch keeps default value')
- elif line.startswith('CODE_BRANCH=') and can_switch_branch:
- text[i] = 'CODE_BRANCH=' + branch + '\n'
- elif line.startswith('SWITCH_LATEST_TAG=') and ltag:
- text[i] = 'SWITCH_LATEST_TAG=true\n'
- break
- elif i >= 10:
- break
+ text = f.read()
+ variables = get_shell_variables(text)
+ if branch or ltag:
+ text, variables = switch_branch_or_tag(headers, model, text, variables, branch, ltag)
with open(tc2 := temp + '.clone.sh', 'w', encoding='utf-8') as f:
- f.writelines(text)
- files['clone_sh'] = tc2
+ f.write(text)
+ return tc2, variables
+
- # Generate temporary modify.sh
- if not os.path.exists(num_ori + '.modify.sh'):
- num = '1'
+def generate_temp_modify_sh(temp, ori, config, ip, pwd):
+ num = ori if os.path.exists(ori + '.modify.sh') else '1'
shutil.copyfile(num + '.modify.sh', tm1 := temp + '.modify.sh')
- spmodel = (
- 'xiaomi-4a-gigabit',
- 'xiaomi-3g-v2',
- 'xiaomi-4a-gigabit-v2'
- )
+
+ pattern = re.compile(
+ r'^CONFIG_TARGET_.*DEVICE_xiaomi_mi-router-(?:3g-v2|4a-gigabit)(?:-v2)?=y$',
+ re.MULTILINE)
+ with open(config, encoding='utf-8') as f:
+ c_text = f.read()
with open(tm1, 'a', encoding='utf-8') as f:
- if model in spmodel:
+ if pattern.search(c_text):
f.write('\n. $(dirname $0)/../extra-files/modify-xiaomi-router-4a-3g-v2.sh\n')
if ip:
new = 'lan) ipad=${ipaddr:-"' + ip + '"} ;;'
@@ -87,36 +95,77 @@ def produce_temp_workfiles(headers: dict, model: str, temp: str, *, branch=None,
if pwd:
f.write(
f"\nsed -i '/root/c{crypt_str(pwd)}' package/base-files/files/etc/shadow\n")
- files['modify_sh'] = tm1
+ return tm1
+
+
+def produce_temp_workfiles(
+ workdir: str,
+ model: str,
+ temp: str = '_temp',
+ *,
+ branch=None,
+ ltag=False,
+ ip=None,
+ pwd=None):
+ """Generate temporary work files to make workflow easy to call,
+ temp is the prefix for temporary files in the compilation process
+ """
+
+ prev_path = os.getcwd()
+ os.chdir(workdir)
+ cur_path = os.getcwd()
+ files = dict()
+
+ with open('headers.json', encoding='utf-8') as f:
+ headers = json.load(f)
+ try:
+ num_ori = headers[model][0]
+ except KeyError:
+ num_ori = model
+ headers = None
+
+ files['dot_config'] = os.path.join(
+ cur_path, generate_temp_config(headers, model, temp, num_ori))
- return files
+ clone_sh, variables = generate_temp_clone_sh(headers, model, temp, num_ori, branch, ltag)
+ files['clone_sh'] = os.path.join(cur_path, clone_sh)
+
+ files['modify_sh'] = os.path.join(
+ cur_path, generate_temp_modify_sh(temp, num_ori, files['dot_config'], ip, pwd))
+
+ os.chdir(prev_path)
+ return files, variables
def main():
destdir = os.getenv('DEPLOY_DIR')
temppre = os.getenv('TEMP_PREFIX')
- modelname = os.getenv('MODEL_NAME')
- branchname = os.getenv('BRANCH_NAME')
+ model = os.getenv('MODEL_NAME') or os.getenv('MULTI_CONFIG').removesuffix('.config')
+ branch = os.getenv('BRANCH_NAME')
latesttag = True if os.getenv('LATEST_TAG') == 'true' else False
- loginip = os.getenv('LOGIN_IP').strip()
- loginpwd = os.getenv('LOGIN_PWD').strip()
-
- os.chdir(destdir)
- with open('headers.json', encoding='utf-8') as f:
- hdata = json.load(f)
- files = produce_temp_workfiles(
- hdata, modelname, temppre, branch=branchname, ltag=latesttag, ip=loginip, pwd=loginpwd)
+ loginip = os.getenv('LOGIN_IP', '').strip()
+ loginpwd = os.getenv('LOGIN_PWD', '').strip()
+
+ files, variables = produce_temp_workfiles(
+ destdir, model, temppre, branch=branch, ltag=latesttag, ip=loginip, pwd=loginpwd)
+
+ fordevice = model.replace('-', ' ')
+ print(
+ 'The device you choose is:',
+ green(fordevice),
+ 'Temporary file paths:',
+ sep='\n'
+ )
+ for k, v in files.items():
+ print(v)
+ set_output(k, v)
- print(f'The model you choose is:\n{modelname}')
- print('Temporary file paths:')
- for item in files.items():
- print(di := f'{destdir}/{item[1]}')
- set_output(item[0], di)
- set_output('codedir', get_code_dir(files['clone_sh']))
+ set_output('fordevice', fordevice)
+ set_output('codedir', variables['CODE_DIR'])
def main2():
- modelname = os.getenv('MODEL_NAME')
+ fordevice = os.getenv('FOR_DEVICE')
codedir = os.getenv('CODE_DIR')
key_to_key2 = {
@@ -132,31 +181,36 @@ def main2():
'arch_packages': 'arch packages'
}
+ summary = ''
cs = CodeSummary(codedir)
- data = cs.summary_dict
- code_name = data['code_from'].split('/')[-1]
+ data1 = cs.summary_dict
+ code_name = data1['code_from'].split('/')[-1]
- d1 = ['item'] + list(data.keys())
- d2 = ['content'] + list(data.values())
+ d1 = ['item'] + list(data1.keys())
+ d2 = ['content'] + list(data1.values())
for i, x in enumerate(d1.copy()):
try:
d1[i] = key_to_key2[x]
except KeyError:
continue
- data = to_markdown_table(d1, d2)
- code_data = f'\n Code Summary -> Click to expand
\n\n{data}\n \n'
-
- file = glob.glob('_collected_firmware/*.manifest')[0]
- data = manifest_to_lists(file)
- d1 = ['package'] + data[0]
- d2 = ['version'] + data[1]
- data = to_markdown_table(d1, d2)
- package_data = f'\n Package Summary -> Click to expand
\n\n{data}\n \n'
-
- stitle = f'{code_name} for {modelname.replace("-", " ")}'
+ data1 = to_markdown_table(d1, d2)
+ summary += f'\n Code Summary -> Click to expand
\n\n{data1}\n \n'
+
+ try:
+ file = glob.glob('_collected_firmware/*.manifest')[0]
+ except IndexError:
+ print(red("Error: can't find manifest file"))
+ else:
+ data2 = manifest_to_lists(file)
+ d1 = ['package'] + data2[0]
+ d2 = ['version'] + data2[1]
+ data2 = to_markdown_table(d1, d2)
+ summary += f'\n\n Package Summary -> Click to expand
\n\n{data2}\n \n'
+
+ stitle = f'{code_name} for {fordevice}'
set_output('stitle', stitle)
- set_output('summary', s := f'{code_data}\n{package_data}')
- set_summary(f'## {stitle}\n\n{s}')
+ set_output('summary', summary)
+ set_summary(f'## {stitle}\n\n{summary}')
if __name__ == '__main__':
diff --git a/extra-files/update-geodata.sh b/extra-files/update-geodata.sh
old mode 100644
new mode 100755
index 31233046..fa615e40
--- a/extra-files/update-geodata.sh
+++ b/extra-files/update-geodata.sh
@@ -1,20 +1,31 @@
-#!/bin/sh
+#!/usr/bin/env bash
-[ -z "$GEODIR" ] && GEODIR=package/_supply_packages/pw-dependencies/v2ray-geodata
+echo "Start to update geodata..."
+GEOMK=package/feeds/packages/v2ray-geodata/Makefile
+[ -e "$GEOMK" ] || GEOMK=package/feeds/supply/v2ray-geodata/Makefile
+[ -e "$GEOMK" ] || exit 1
LATEST_VER=$(curl -fs https://api.github.com/repos/Loyalsoldier/v2ray-rules-dat/releases/latest | jq -r .'tag_name')
+MARK="# The file has been modified by@hugcabbage $LATEST_VER"
+if grep -q "$MARK" $GEOMK; then
+ echo "geodata is newest"
+ exit 0
+else
+ sed -i "1i $MARK" $GEOMK
+fi
GEOIP_HASH=$(curl -fsL https://github.com/Loyalsoldier/v2ray-rules-dat/releases/download/$LATEST_VER/geoip.dat.sha256sum | awk '{print $1}')
-
GEOSITE_HASH=$(curl -fsL https://github.com/Loyalsoldier/v2ray-rules-dat/releases/download/$LATEST_VER/geosite.dat.sha256sum | awk '{print $1}')
-sed -i "/GEOIP_VER:=/cGEOIP_VER:=$LATEST_VER" $GEODIR/Makefile
-sed -i "/GEOSITE_VER:=/cGEOSITE_VER:=$LATEST_VER" $GEODIR/Makefile
+sed -i "/GEOIP_VER:=/cGEOIP_VER:=$LATEST_VER" $GEOMK
+sed -i "/GEOSITE_VER:=/cGEOSITE_VER:=$LATEST_VER" $GEOMK
+
+sed -i '/HASH:=/d' $GEOMK
+sed -i "/FILE:=\$(GEOIP_FILE)/a\ HASH:=$GEOIP_HASH" $GEOMK
+sed -i "/FILE:=\$(GEOSITE_FILE)/a\ HASH:=$GEOSITE_HASH" $GEOMK
-sed -i '/HASH:=/d' $GEODIR/Makefile
-sed -i "/FILE:=\$(GEOIP_FILE)/a\ HASH:=$GEOIP_HASH" $GEODIR/Makefile
-sed -i "/FILE:=\$(GEOSITE_FILE)/a\ HASH:=$GEOSITE_HASH" $GEODIR/Makefile
+sed -i 's|v2fly/geoip|Loyalsoldier/v2ray-rules-dat|g' $GEOMK
+sed -i 's|v2fly/domain-list-community|Loyalsoldier/v2ray-rules-dat|g' $GEOMK
+sed -i 's|dlc.dat|geosite.dat|g' $GEOMK
-sed -i 's|v2fly/geoip|Loyalsoldier/v2ray-rules-dat|g' $GEODIR/Makefile
-sed -i 's|v2fly/domain-list-community|Loyalsoldier/v2ray-rules-dat|g' $GEODIR/Makefile
-sed -i 's|dlc.dat|geosite.dat|g' $GEODIR/Makefile
+echo "Updating geodata done"
diff --git a/preset-immortalwrt/1.clone.sh b/preset-immortalwrt/1.clone.sh
old mode 100644
new mode 100755
index 856b3d29..47fc4550
--- a/preset-immortalwrt/1.clone.sh
+++ b/preset-immortalwrt/1.clone.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
# download base code
CODE_DIR=_firmware_code
diff --git a/preset-immortalwrt/1.modify.sh b/preset-immortalwrt/1.modify.sh
old mode 100644
new mode 100755
index 4a6c52f6..27a8b796
--- a/preset-immortalwrt/1.modify.sh
+++ b/preset-immortalwrt/1.modify.sh
@@ -1,4 +1,7 @@
-#!/bin/sh
+#!/usr/bin/env bash
# modify login IP
#sed -i 's/192.168.1.1/192.168.10.1/g' package/base-files/files/bin/config_generate
+
+# replace geodata source
+. $(dirname $0)/../extra-files/update-geodata.sh
diff --git a/preset-lede/1.clone.sh b/preset-lede/1.clone.sh
old mode 100644
new mode 100755
index 2c4d0096..31a418fc
--- a/preset-lede/1.clone.sh
+++ b/preset-lede/1.clone.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
# download base code
CODE_DIR=_firmware_code
@@ -6,8 +6,9 @@ git clone --depth 1 https://github.com/coolsnowwolf/lede.git $CODE_DIR
mv ./$CODE_DIR/* ./
# download app codes
-rm -rf package/lean/luci-theme-argon
-mkdir -p package/_supply_packages && cd package/_supply_packages
+SUPPLY_DIR=_supply_packages
+echo "src-link supply $PWD/$SUPPLY_DIR" >> feeds.conf.default
+mkdir $SUPPLY_DIR && cd $SUPPLY_DIR
git clone --depth 1 -b 18.06 https://github.com/jerrykuku/luci-theme-argon.git
git clone --depth 1 https://github.com/jerrykuku/luci-app-argon-config.git
git clone --depth 1 https://github.com/kenzok8/openwrt-packages.git
diff --git a/preset-lede/1.modify.sh b/preset-lede/1.modify.sh
old mode 100644
new mode 100755
index 650dcbfc..98b20ba6
--- a/preset-lede/1.modify.sh
+++ b/preset-lede/1.modify.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
# modify login IP
#sed -i 's/192.168.1.1/192.168.31.1/g' package/base-files/files/bin/config_generate
@@ -42,5 +42,4 @@ sed -i '/KERNEL_PATCHVER/cKERNEL_PATCHVER:=5.10' target/linux/ramips/Makefile
#sed -i '/root/croot:$1$CBd7u73H$LvSDVXLBrzpk4JfuuN.Lv1:18676:0:99999:7:::' package/base-files/files/etc/shadow
# replace geodata source
-GEODIR=package/_supply_packages/small/v2ray-geodata
. $(dirname $0)/../extra-files/update-geodata.sh
diff --git a/preset-lienol-openwrt/1.clone.sh b/preset-lienol-openwrt/1.clone.sh
old mode 100644
new mode 100755
index 96635aed..58ca26d9
--- a/preset-lienol-openwrt/1.clone.sh
+++ b/preset-lienol-openwrt/1.clone.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
# download base code
CODE_DIR=_firmware_code
@@ -8,10 +8,11 @@ git clone --depth 1 -b $CODE_BRANCH $CODE_URL $CODE_DIR
mv ./$CODE_DIR/* ./
# download app codes
-mkdir -p package/_supply_packages && cd package/_supply_packages
+SUPPLY_DIR=_supply_packages
+echo "src-link supply $PWD/$SUPPLY_DIR" >> feeds.conf.default
+mkdir $SUPPLY_DIR && cd $SUPPLY_DIR
git clone --depth 1 https://github.com/jerrykuku/luci-theme-argon.git
git clone --depth 1 https://github.com/jerrykuku/luci-app-argon-config.git
-git clone --depth 1 https://github.com/jerrykuku/lua-maxminddb.git
git clone --depth 1 https://github.com/Ausaci/luci-app-nat6-helper.git
git clone --depth 1 https://github.com/xiaorouji/openwrt-passwall-packages.git pw-dependencies
git clone --depth 1 https://github.com/xiaorouji/openwrt-passwall.git && mv openwrt-passwall/luci-app-passwall ./ && rm -rf openwrt-passwall
diff --git a/preset-lienol-openwrt/1.modify.sh b/preset-lienol-openwrt/1.modify.sh
old mode 100644
new mode 100755
index b0ba78d1..c95b8380
--- a/preset-lienol-openwrt/1.modify.sh
+++ b/preset-lienol-openwrt/1.modify.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
# modify login IP
#sed -i 's/192.168.1.1/192.168.31.1/g' package/base-files/files/bin/config_generate
diff --git a/preset-openwrt/1.clone.sh b/preset-openwrt/1.clone.sh
old mode 100644
new mode 100755
index 04228775..1b01ac7a
--- a/preset-openwrt/1.clone.sh
+++ b/preset-openwrt/1.clone.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
# download base code
CODE_DIR=_firmware_code
@@ -26,7 +26,8 @@ echo "src-link supply $PWD/$SUPPLY_DIR" >> feeds.conf.default
mkdir $SUPPLY_DIR && cd $SUPPLY_DIR
git clone --depth 1 https://github.com/jerrykuku/luci-theme-argon.git
git clone --depth 1 https://github.com/jerrykuku/luci-app-argon-config.git
-git clone --depth 1 https://github.com/yichya/luci-app-xray.git
+git clone --depth 1 https://github.com/sbwml/luci-app-alist.git
+git clone --depth 1 https://github.com/yichya/luci-app-xray.git && mv luci-app-xray/core luci-app-xray-core && mv luci-app-xray/status luci-app-xray-status && rm -rf luci-app-xray
git clone --depth 1 https://github.com/xiaorouji/openwrt-passwall-packages.git pw-dependencies
git clone --depth 1 https://github.com/xiaorouji/openwrt-passwall.git && mv openwrt-passwall/luci-app-passwall ./ && rm -rf openwrt-passwall
git clone --depth 1 https://github.com/xiaorouji/openwrt-passwall2.git && mv openwrt-passwall2/luci-app-passwall2 ./ && rm -rf openwrt-passwall2
diff --git a/preset-openwrt/1.modify.sh b/preset-openwrt/1.modify.sh
old mode 100644
new mode 100755
index 9bf4f2e1..53770875
--- a/preset-openwrt/1.modify.sh
+++ b/preset-openwrt/1.modify.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
# modify login IP
#sed -i 's/192.168.1.1/192.168.10.1/g' package/base-files/files/bin/config_generate
@@ -8,4 +8,19 @@ mkdir -p files/etc/uci-defaults
cp $(dirname $0)/uci-scripts/* files/etc/uci-defaults/
# modify default package(s)
-sed -i 's/dnsmasq/dnsmasq-full/g' include/target.mk
+if ! grep -q "dnsmasq-full" include/target.mk; then
+ sed -i 's/dnsmasq/dnsmasq-full/g' include/target.mk
+fi
+
+# modify luci-app-xray category
+modify_lax_category() {
+ local mk=$1
+ [ -e $mk ] || return
+ sed -i 's/SECTION:=Custom/CATEGORY:=LuCI/g' $mk
+ sed -i 's/CATEGORY:=Extra packages/SUBMENU:=3. Applications/g' $mk
+}
+modify_lax_category 'package/feeds/supply/luci-app-xray-core/Makefile'
+modify_lax_category 'package/feeds/supply/luci-app-xray-status/Makefile'
+
+# replace geodata source
+. $(dirname $0)/../extra-files/update-geodata.sh
diff --git a/preset-x-wrt/1.clone.sh b/preset-x-wrt/1.clone.sh
old mode 100644
new mode 100755
index 8c08d262..328e3178
--- a/preset-x-wrt/1.clone.sh
+++ b/preset-x-wrt/1.clone.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
# download base code
CODE_DIR=_firmware_code
diff --git a/preset-x-wrt/1.modify.sh b/preset-x-wrt/1.modify.sh
old mode 100644
new mode 100755
index 9bf4f2e1..5ee2dc99
--- a/preset-x-wrt/1.modify.sh
+++ b/preset-x-wrt/1.modify.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
# modify login IP
#sed -i 's/192.168.1.1/192.168.10.1/g' package/base-files/files/bin/config_generate
@@ -9,3 +9,15 @@ cp $(dirname $0)/uci-scripts/* files/etc/uci-defaults/
# modify default package(s)
sed -i 's/dnsmasq/dnsmasq-full/g' include/target.mk
+
+# modify luci-app-xray category
+modify_lax_category() {
+ local mk=$1
+ sed -i 's/SECTION:=Custom/CATEGORY:=LuCI/g' $mk
+ sed -i 's/CATEGORY:=Extra packages/SUBMENU:=3. Applications/g' $mk
+}
+modify_lax_category 'package/feeds/supply/luci-app-xray-core/Makefile'
+modify_lax_category 'package/feeds/supply/luci-app-xray-status/Makefile'
+
+# replace geodata source
+. $(dirname $0)/../extra-files/update-geodata.sh
diff --git a/templet/produce.py b/templet/produce.py
index dae923ed..ee31b172 100755
--- a/templet/produce.py
+++ b/templet/produce.py
@@ -7,12 +7,12 @@
import toml
-sys.path.append(os.path.dirname(os.path.dirname(__file__)) + '/extra-files')
+sys.path.append(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'extra-files'))
+from tools.color import *
from tools.crypt_text import crypt_str
-from tools.routine_cmd import gen_dot_config
-from tools.process_text import simplify_config
-from tools.process_text import get_remain_text
from tools.process_text import generate_header
+from tools.process_text import simplify_config
+from tools.routine_cmd import gen_dot_config
def produce_git_command(link: str, isbase=False) -> str:
@@ -67,7 +67,7 @@ def produce_conf(data: dict, prefix: str):
if app_commands:
app_path = data.get('app_path', '')
- if not re.match(r'^package(/|$)', app_path):
+ if not re.match(r'package(/|$)', app_path):
app_path = 'package/_supply_packages'
dl_app_text = (
f'\n# download app codes\n'
@@ -75,7 +75,7 @@ def produce_conf(data: dict, prefix: str):
f'{app_commands}')
clone_text = (
- '#!/bin/sh\n'
+ '#!/usr/bin/env bash\n'
'\n# download base code\n'
f'{base_command}'
f'{dl_app_text}')
@@ -85,7 +85,7 @@ def produce_conf(data: dict, prefix: str):
# Generate modify.sh
modify_text = (
- '#!/bin/sh\n'
+ '#!/usr/bin/env bash\n'
'\n# modify login IP\n')
login_ip = data.get('login_ip')
if login_ip:
@@ -144,23 +144,28 @@ def get_serial(dest_dir, ow_last, ow_spec):
return str(total + 1)
-def delete_all(deploy_dir, dest_dir, wf_dir, ba_dir):
- if deploy_dir != 'templet':
+def delete_all(deploy_dir, dest_dir, wf_dir):
+ if deploy_dir == 'templet':
+ print(red('Cannot delete templet directory!'))
+ sys.exit(1)
+ else:
shutil.rmtree(dest_dir, ignore_errors=True)
for item in glob.glob(f'{wf_dir}/{deploy_dir}-[0-9]*'):
os.remove(item)
+ print(green(f'{deploy_dir} and related files have been removed!'))
sys.exit()
def delete_some(deploy_dir, dest_dir, wf_dir, some_num):
- some_num = some_num.replace(' ', '').rstrip(',').split(',')
+ nums = some_num.replace(' ', '').rstrip(',').split(',')
for root, dirs, files in os.walk(dest_dir):
for name in files:
- if any(name.startswith(serial + '.') for serial in some_num):
+ if any(name.startswith(serial + '.') for serial in nums):
os.remove(os.path.join(root, name))
- for serial in some_num:
+ for serial in nums:
for item in glob.glob(f'{wf_dir}/{deploy_dir}-{serial}*'):
os.remove(item)
+ print(green(f'Files related to {some_num} in {deploy_dir} have been removed!'))
sys.exit()
@@ -171,9 +176,8 @@ def process_config(ba_dir, init_file, serial):
if not init_dict.get('device_name'):
init_dict['device_name'] = init_dict['device'].replace('-', ' ').replace('_', ' ')
produce_conf(init_dict, serial)
- rt = get_remain_text(serial + '.config')
gen_dot_config(serial + '.clone.sh', serial + '.config')
- simplify_config(serial + '.config', remain_text=rt, keep_header=True)
+ simplify_config(serial + '.config', keep_header=True)
return init_dict
@@ -215,7 +219,7 @@ def main():
serial = get_serial(dest_dir, ow_last, ow_spec)
if os.getenv('DELETE_ALL') == 'true':
- delete_all(deploy_dir, dest_dir, wf_dir, ba_dir)
+ delete_all(deploy_dir, dest_dir, wf_dir)
if ds := os.getenv('DELETE_SOME').strip():
delete_some(deploy_dir, dest_dir, wf_dir, ds)
@@ -223,6 +227,8 @@ def main():
move_files(deploy_dir, dest_dir, wf_dir, ba_dir, serial, ow_last)
generate_build_yml(deploy_dir, wf_dir, repo_path, init_dict, serial)
+ print(green(f'Device configuration files have been generated in {deploy_dir}!'))
+
if __name__ == '__main__':
main()