Skip to content

Commit

Permalink
修复部分问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chenmozhijin committed Sep 26, 2024
1 parent c72f475 commit 499f004
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
16 changes: 13 additions & 3 deletions build_helper/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import shutil
import tarfile
from datetime import datetime, timedelta, timezone
from multiprocessing.pool import Pool
from typing import TYPE_CHECKING, Any

Expand All @@ -16,7 +17,7 @@
from .utils.network import dl2, get_gh_repo_last_releases, request_get, wait_dl_tasks
from .utils.openwrt import OpenWrt
from .utils.paths import paths
from .utils.repo import compiler
from .utils.repo import compiler, user_repo, get_release_suffix
from .utils.upload import uploader
from .utils.utils import parse_config

Expand Down Expand Up @@ -415,12 +416,21 @@ def prepare_cfg(config: dict[str, Any],
else:
f.write(line + "\n")

config["target"], config["subtarget"] = openwrt.get_target()

with open(os.path.join(openwrt.files, "etc", "openwrt-k_info"), "w", encoding="utf-8") as f:
content = ""
content += f'COMPILE_START_TIME="{datetime.now(timezone(timedelta(hours=8))).strftime('%y.%m.%d-%H')}"\n'
content += f'COMPILER="{compiler}"\n'
content += f'REPOSITORY_URL="https://github.com/{user_repo}"\n'
content += f'TAG_SUFFIX="{get_release_suffix(config)[1]}"\n'
f.write(content)
logger.debug("openwrt-k_info: %s", content)

logger.info("%s生成源代码归档", cfg_name)
shutil.rmtree(os.path.join(openwrt.path, ".git"))
os.makedirs(os.path.join(paths.uploads, cfg_name), exist_ok=True)
tar_path = os.path.join(paths.uploads, cfg_name, "openwrt-source.tar.gz")
openwrt.archive(tar_path)

config["target"], config["subtarget"] = openwrt.get_target()

return cfg_name, config, tar_path
1 change: 1 addition & 0 deletions build_helper/utils/openwrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class OpenWrtBase:
def __init__(self, path: str) -> None:
self.path = path
self.files = os.path.join(path, 'files')

def get_arch(self) -> tuple[str | None, str | None]:
arch = None
Expand Down
8 changes: 6 additions & 2 deletions build_helper/utils/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ def del_cache(key_prefix: str) -> None:
else:
logger.error('Failed to get caches list')

def new_release(cfg: dict, assets: list[str], body: str) -> None:
def get_release_suffix(cfg: dict) -> tuple[str, str]:
release_suffix = f"({cfg["target"]}-{cfg["subtarget"]})-[{cfg["compile"]["openwrt_tag/branch"]}]"
tag_suffix = f"({cfg["target"]}-{cfg["subtarget"]})-({cfg["compile"]["openwrt_tag/branch"]})-{cfg["name"]}"
return release_suffix, tag_suffix

def new_release(cfg: dict, assets: list[str], body: str) -> None:
release_suffix, tag_suffix = get_release_suffix(cfg)
f_release_name = "v" + datetime.now(timezone(timedelta(hours=8))).strftime('%Y.%m.%d') + "-{n}" + release_suffix
f_tag_name = "v" + datetime.now(timezone(timedelta(hours=8))).strftime('%Y.%m.%d') + "-{n}" + tag_suffix

Expand Down Expand Up @@ -106,7 +110,7 @@ def new_release(cfg: dict, assets: list[str], body: str) -> None:


def match_releases(cfg: dict) -> github.GitRelease.GitRelease | None:
suffix = f"({cfg["target"]}-{cfg["subtarget"]})-({cfg["compile"]["openwrt_tag/branch"]})-{cfg["name"]}"
_, suffix = get_release_suffix(cfg)

releases = repo.get_releases()

Expand Down
16 changes: 6 additions & 10 deletions files/usr/share/cmzj/openwrt-k_tool.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (C) 2023 沉默の金
# Copyright (C) 2023-2024 沉默の金

trap 'rm -rf "$TMPDIR"' EXIT
TMPDIR=$(mktemp -d) || exit 1
Expand Down Expand Up @@ -59,8 +59,6 @@ show_info() {
echo "固件编译者:"$(sed -n "/^COMPILER=\"/p" /etc/openwrt-k_info | sed -e "s/COMPILER=\"//g" -e "s/\"//g" )
echo "固件编译仓库地址:"$(sed -n "/REPOSITORY_URL=\"/p" /etc/openwrt-k_info | sed -e "s/REPOSITORY_URL=\"//g" -e "s/\"//g" )
echo "固件编译时间:UTC+8 "$(sed -n "/^COMPILE_START_TIME=\"/p" /etc/openwrt-k_info | sed -e "s/COMPILE_START_TIME=\"//g" -e "s/\"/时/g" -e "s/-/日/" -e "s/\./月/g" -e "s/月/年/" )
echo "固件发布名称:"$(sed -n "/^RELEASE_NAME=\"/p" /etc/openwrt-k_info | sed -e "s/RELEASE_NAME=\"//g" -e "s/\"//g" )
echo "固件标签名称:"$(sed -n "/RELEASE_TAG_NAME=\"/p" /etc/openwrt-k_info | sed -e "s/RELEASE_TAG_NAME=\"//g" -e "s/\"//g" )
elif [ "$(grep -c "Compiled by" /etc/openwrt_release)" -ne '0' ];then
echo "固件编译者:"$(sed -n "/Compiled by /p" /etc/openwrt_release|sed -e "s/.*Compiled by //g" -e "s/'//g" )
fi
Expand Down Expand Up @@ -188,15 +186,14 @@ update_package() {
elif [ "$(grep -c "^REPOSITORY_URL=" /etc/openwrt-k_info)" -eq '0' ]; then
echo "错误:未知的固件编译仓库地址"
exit 1
elif [ "$(grep -c "^RELEASE_TAG_NAME=" /etc/openwrt-k_info)" -eq '0' ]; then
echo "错误:未知的固件标签名称"
elif [ "$(grep -c "^TAG_SUFFIX=" /etc/openwrt-k_info)" -eq '0' ]; then
echo "错误:未知的固件标签前缀"
exit 1
fi
REPOSITORY_URL=$(sed -n "/REPOSITORY_URL=\"/p" /etc/openwrt-k_info | sed -e "s/REPOSITORY_URL=\"//g" -e "s/\"//g")
REPOSITORY=$(echo $REPOSITORY_URL|sed -e "s/https:\/\/github.com\///")
RELEASE_TAG_NAME=$(sed -n "/RELEASE_TAG_NAME=\"/p" /etc/openwrt-k_info | sed -e "s/RELEASE_TAG_NAME=\"//g" -e "s/\"//g")
RELEASE_TAG_MAINNAME=$(echo $RELEASE_TAG_NAME | sed "s/v[0-9]\{1,2\}.[0-9]\{2,2\}.[0-9]\{1,2\}-[0-9]\{2,2\}(/(/")
latest_ver="$(curl -s https://api.github.com/repos/$REPOSITORY/releases 2>/dev/null | grep -E 'tag_name' | grep "$RELEASE_TAG_MAINNAME" | sed -e 's/ "tag_name": "//' -e 's/",//' | sed -n '1p')"
TAG_SUFFIX=$(sed -n "/TAG_SUFFIX=\"/p" /etc/openwrt-k_info | sed -e "s/TAG_SUFFIX=\"//g" -e "s/\"//g")
latest_ver="$(curl -s https://api.github.com/repos/$REPOSITORY/releases 2>/dev/null | grep -E 'tag_name' | grep "$TAG_SUFFIX" | sed -e 's/ "tag_name": "//' -e 's/",//' | sed -n '1p')"
FILE_NAME=$(curl -s "https://api.github.com/repos/$REPOSITORY/releases/tags/$latest_ver"| grep -E 'name'| grep -E '\.manifest'| sed -e 's/ "name": "//' -e 's/",//' | sed -n '1p')
curl -L --retry 3 --connect-timeout 20 $REPOSITORY_URL/releases/download/${latest_ver}/$FILE_NAME -o package.list || download_failed
if ! diff installed.list package.list -y -W 80 -B -b | grep '|' |sed -e "s/^/update:/g" -e 's/|/>/g' -e "/kmod-/d" > update.list; then
Expand Down Expand Up @@ -247,7 +244,7 @@ update_package() {
;;
esac
[[ -d /usr/share/cmzj/download/ ]] && rm -rf /usr/share/cmzj/download/*
curl -L --retry 3 --connect-timeout 20 $REPOSITORY_URL/releases/download/${latest_ver}/package.zip -o $DOWNLOAD_PATH || download_failed
curl -L --retry 3 --connect-timeout 20 $REPOSITORY_URL/releases/download/${latest_ver}/packages.zip -o $DOWNLOAD_PATH || download_failed
unzip -l $DOWNLOAD_PATH |grep "-"|grep ":"|grep " "|sed "s/.*[0-9][0-9]-[0-9]\{1,2\}-[0-9]\{1,5\} [0-9]\{1,2\}:[0-9]\{1,2\} //g"|sed "s/ //g" > newpackage.list
unzip $DOWNLOAD_PATH $(grep "$(cat update_package.list)" newpackage.list | sed ':label;N;s/\n/ /;b label') -d $TMPDIR/update/package
rm -rf /usr/share/cmzj/download $TMPDIR/update/package/download
Expand Down Expand Up @@ -292,7 +289,6 @@ usage() {
echo ""
echo "Commands:"
echo "update <packages|rules|tool> 更新包/规则/本工具"
#echo "update <packages|rules|firmwar|tool> 更新包/规则/固件/本工具"
echo "info 打印固件信息"
}
main

0 comments on commit 499f004

Please sign in to comment.