From a4c4df601dbbf37c8cee18eec0cab8171be41bdf Mon Sep 17 00:00:00 2001 From: Hyy2001X <1804430051@qq.com> Date: Sun, 12 Dec 2021 01:05:38 +0800 Subject: [PATCH] =?UTF-8?q?AutoBuild-Actions:=2020211212=20=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2021/12/12 更新内容 1. 新增固件标签 Default_FLAG, 一键更新固件时会自动检测带该标签的固件版本, e.g. 若固件标签为 Full, 则更新固件时仅可以更新到固件名称中带 Full 标签的版本 补充: 用户自定义变量 Default_FLAG, 支持数字与字母的组合 [0-9a-zA-Z] 例如 [Full Lite Daily1 Test2], 不支持标点符号, 不能为空 当该值为 AUTO 时, 将自动从配置文件名称获取, 格式为 -, e.g. 配置文件名称为 [x86_64-Test 或 d-team_newifi-d2-Lite], 则标签分别为 [Test Lite]; 配置文件若为不规则命名或无标签例如 [x86_64 X86 NEWIFI-D2], 则标签自动设定为 Full 同时支持在手动编译时临时修改, 点击 Run workflow 后修改 固件名称后缀 [可选] 值即可, 优先级高于用户自定义变量 Default_FLAG 固件内支持标签的快速切换, 切换方法 autoupdate --flag <标签名>, 恢复默认 autoupdate --flag reset 2. AutoBuild_Function.sh Firmware_Diy 函数中新增 CONFIG_FILE TARGET_FLAG 等可调用变量 3. 新增一些设备支持 (也许, 我也不知道) 改动内容较大, 建议重新 Fork 本仓库 --- .../workflows/AutoBuild-asus_rt-acrh17.yml | 13 ++- .../workflows/AutoBuild-d-team_newifi-d2.yml | 13 ++- .../workflows/AutoBuild-p2w_r619ac-128m.yml | 13 ++- .github/workflows/AutoBuild-x86_64.yml | 13 ++- .../AutoBuild-xiaomi_redmi-router-ac2100.yml | 13 ++- .github/workflows/AutoBuild-xiaoyu_xy-c5.yml | 13 ++- Scripts/AutoBuild_DiyScript.sh | 25 ++-- Scripts/AutoBuild_Function.sh | 108 +++++++++++------ Scripts/AutoUpdate.sh | 109 +++++++++++------- 9 files changed, 223 insertions(+), 97 deletions(-) diff --git a/.github/workflows/AutoBuild-asus_rt-acrh17.yml b/.github/workflows/AutoBuild-asus_rt-acrh17.yml index b8c00fd..a8316be 100644 --- a/.github/workflows/AutoBuild-asus_rt-acrh17.yml +++ b/.github/workflows/AutoBuild-asus_rt-acrh17.yml @@ -12,11 +12,14 @@ on: workflow_dispatch: inputs: Tempoary_IP: - description: '临时修改 IP 地址 [可选]' + description: '固件 IP 地址 [可选]' default: '' Tempoary_CONFIG: description: '配置文件 [可选]' default: '' + Tempoary_FLAG: + description: '固件名称后缀 [可选]' + default: '' ### 结束 #push: @@ -87,8 +90,16 @@ jobs: fi if [ -n "${{ github.event.inputs.Tempoary_IP }}" ] then + echo "IP: [${{ github.event.inputs.Tempoary_IP }}]" echo "Tempoary_IP=${{ github.event.inputs.Tempoary_IP }}" >> $GITHUB_ENV fi + if [ -n "${{ github.event.inputs.Tempoary_FLAG }}" ] + then + echo "FLAG: [${{ github.event.inputs.Tempoary_FLAG }}]" + echo "Tempoary_FLAG=${{ github.event.inputs.Tempoary_FLAG }}" >> $GITHUB_ENV + else + echo "env Tempoary_FLAG is not detected !" + fi REPO_URL="https://github.com/$(echo ${{ env.DEFAULT_SOURCE }} | cut -d \: -f 1)" REPO_BRANCH=$(echo ${{ env.DEFAULT_SOURCE }} | cut -d \: -f 2) echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV diff --git a/.github/workflows/AutoBuild-d-team_newifi-d2.yml b/.github/workflows/AutoBuild-d-team_newifi-d2.yml index 8a2449e..d34ec88 100644 --- a/.github/workflows/AutoBuild-d-team_newifi-d2.yml +++ b/.github/workflows/AutoBuild-d-team_newifi-d2.yml @@ -12,11 +12,14 @@ on: workflow_dispatch: inputs: Tempoary_IP: - description: '临时修改 IP 地址 [可选]' + description: '固件 IP 地址 [可选]' default: '' Tempoary_CONFIG: description: '配置文件 [可选]' default: '' + Tempoary_FLAG: + description: '固件名称后缀 [可选]' + default: '' ### 结束 #push: @@ -87,8 +90,16 @@ jobs: fi if [ -n "${{ github.event.inputs.Tempoary_IP }}" ] then + echo "IP: [${{ github.event.inputs.Tempoary_IP }}]" echo "Tempoary_IP=${{ github.event.inputs.Tempoary_IP }}" >> $GITHUB_ENV fi + if [ -n "${{ github.event.inputs.Tempoary_FLAG }}" ] + then + echo "FLAG: [${{ github.event.inputs.Tempoary_FLAG }}]" + echo "Tempoary_FLAG=${{ github.event.inputs.Tempoary_FLAG }}" >> $GITHUB_ENV + else + echo "env Tempoary_FLAG is not detected !" + fi REPO_URL="https://github.com/$(echo ${{ env.DEFAULT_SOURCE }} | cut -d \: -f 1)" REPO_BRANCH=$(echo ${{ env.DEFAULT_SOURCE }} | cut -d \: -f 2) echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV diff --git a/.github/workflows/AutoBuild-p2w_r619ac-128m.yml b/.github/workflows/AutoBuild-p2w_r619ac-128m.yml index aa34935..6c8fcd1 100644 --- a/.github/workflows/AutoBuild-p2w_r619ac-128m.yml +++ b/.github/workflows/AutoBuild-p2w_r619ac-128m.yml @@ -12,11 +12,14 @@ on: workflow_dispatch: inputs: Tempoary_IP: - description: '临时修改 IP 地址 [可选]' + description: '固件 IP 地址 [可选]' default: '' Tempoary_CONFIG: description: '配置文件 [可选]' default: '' + Tempoary_FLAG: + description: '固件名称后缀 [可选]' + default: '' ### 结束 #push: @@ -87,8 +90,16 @@ jobs: fi if [ -n "${{ github.event.inputs.Tempoary_IP }}" ] then + echo "IP: [${{ github.event.inputs.Tempoary_IP }}]" echo "Tempoary_IP=${{ github.event.inputs.Tempoary_IP }}" >> $GITHUB_ENV fi + if [ -n "${{ github.event.inputs.Tempoary_FLAG }}" ] + then + echo "FLAG: [${{ github.event.inputs.Tempoary_FLAG }}]" + echo "Tempoary_FLAG=${{ github.event.inputs.Tempoary_FLAG }}" >> $GITHUB_ENV + else + echo "env Tempoary_FLAG is not detected !" + fi REPO_URL="https://github.com/$(echo ${{ env.DEFAULT_SOURCE }} | cut -d \: -f 1)" REPO_BRANCH=$(echo ${{ env.DEFAULT_SOURCE }} | cut -d \: -f 2) echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV diff --git a/.github/workflows/AutoBuild-x86_64.yml b/.github/workflows/AutoBuild-x86_64.yml index 7b235be..74688bc 100644 --- a/.github/workflows/AutoBuild-x86_64.yml +++ b/.github/workflows/AutoBuild-x86_64.yml @@ -12,11 +12,14 @@ on: workflow_dispatch: inputs: Tempoary_IP: - description: '临时修改 IP 地址 [可选]' + description: '固件 IP 地址 [可选]' default: '' Tempoary_CONFIG: description: '配置文件 [可选]' default: '' + Tempoary_FLAG: + description: '固件名称后缀 [可选]' + default: '' ### 结束 #push: @@ -87,8 +90,16 @@ jobs: fi if [ -n "${{ github.event.inputs.Tempoary_IP }}" ] then + echo "IP: [${{ github.event.inputs.Tempoary_IP }}]" echo "Tempoary_IP=${{ github.event.inputs.Tempoary_IP }}" >> $GITHUB_ENV fi + if [ -n "${{ github.event.inputs.Tempoary_FLAG }}" ] + then + echo "FLAG: [${{ github.event.inputs.Tempoary_FLAG }}]" + echo "Tempoary_FLAG=${{ github.event.inputs.Tempoary_FLAG }}" >> $GITHUB_ENV + else + echo "env Tempoary_FLAG is not detected !" + fi REPO_URL="https://github.com/$(echo ${{ env.DEFAULT_SOURCE }} | cut -d \: -f 1)" REPO_BRANCH=$(echo ${{ env.DEFAULT_SOURCE }} | cut -d \: -f 2) echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV diff --git a/.github/workflows/AutoBuild-xiaomi_redmi-router-ac2100.yml b/.github/workflows/AutoBuild-xiaomi_redmi-router-ac2100.yml index 5cca441..5fe368a 100644 --- a/.github/workflows/AutoBuild-xiaomi_redmi-router-ac2100.yml +++ b/.github/workflows/AutoBuild-xiaomi_redmi-router-ac2100.yml @@ -12,11 +12,14 @@ on: workflow_dispatch: inputs: Tempoary_IP: - description: '临时修改 IP 地址 [可选]' + description: '固件 IP 地址 [可选]' default: '' Tempoary_CONFIG: description: '配置文件 [可选]' default: '' + Tempoary_FLAG: + description: '固件名称后缀 [可选]' + default: '' ### 结束 #push: @@ -87,8 +90,16 @@ jobs: fi if [ -n "${{ github.event.inputs.Tempoary_IP }}" ] then + echo "IP: [${{ github.event.inputs.Tempoary_IP }}]" echo "Tempoary_IP=${{ github.event.inputs.Tempoary_IP }}" >> $GITHUB_ENV fi + if [ -n "${{ github.event.inputs.Tempoary_FLAG }}" ] + then + echo "FLAG: [${{ github.event.inputs.Tempoary_FLAG }}]" + echo "Tempoary_FLAG=${{ github.event.inputs.Tempoary_FLAG }}" >> $GITHUB_ENV + else + echo "env Tempoary_FLAG is not detected !" + fi REPO_URL="https://github.com/$(echo ${{ env.DEFAULT_SOURCE }} | cut -d \: -f 1)" REPO_BRANCH=$(echo ${{ env.DEFAULT_SOURCE }} | cut -d \: -f 2) echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV diff --git a/.github/workflows/AutoBuild-xiaoyu_xy-c5.yml b/.github/workflows/AutoBuild-xiaoyu_xy-c5.yml index 7c5d390..96f923a 100644 --- a/.github/workflows/AutoBuild-xiaoyu_xy-c5.yml +++ b/.github/workflows/AutoBuild-xiaoyu_xy-c5.yml @@ -12,11 +12,14 @@ on: workflow_dispatch: inputs: Tempoary_IP: - description: '临时修改 IP 地址 [可选]' + description: '固件 IP 地址 [可选]' default: '' Tempoary_CONFIG: description: '配置文件 [可选]' default: '' + Tempoary_FLAG: + description: '固件名称后缀 [可选]' + default: '' ### 结束 #push: @@ -87,8 +90,16 @@ jobs: fi if [ -n "${{ github.event.inputs.Tempoary_IP }}" ] then + echo "IP: [${{ github.event.inputs.Tempoary_IP }}]" echo "Tempoary_IP=${{ github.event.inputs.Tempoary_IP }}" >> $GITHUB_ENV fi + if [ -n "${{ github.event.inputs.Tempoary_FLAG }}" ] + then + echo "FLAG: [${{ github.event.inputs.Tempoary_FLAG }}]" + echo "Tempoary_FLAG=${{ github.event.inputs.Tempoary_FLAG }}" >> $GITHUB_ENV + else + echo "env Tempoary_FLAG is not detected !" + fi REPO_URL="https://github.com/$(echo ${{ env.DEFAULT_SOURCE }} | cut -d \: -f 1)" REPO_BRANCH=$(echo ${{ env.DEFAULT_SOURCE }} | cut -d \: -f 2) echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV diff --git a/Scripts/AutoBuild_DiyScript.sh b/Scripts/AutoBuild_DiyScript.sh index c257732..2957317 100755 --- a/Scripts/AutoBuild_DiyScript.sh +++ b/Scripts/AutoBuild_DiyScript.sh @@ -6,6 +6,7 @@ Firmware_Diy_Core() { Author=AUTO Author_URL=AUTO + Default_FLAG=AUTO Default_IP="192.168.1.1" Banner_Message="Powered by AutoBuild-Actions" @@ -21,22 +22,24 @@ Firmware_Diy_Core() { Firmware_Diy() { - # 请在该函数内定制固件, 建议使用专业文本编辑器进行修改 + # 请在该函数内定制固件 # 可用预设变量, 其他可用变量请参考运行日志 # ${OP_AUTHOR} OpenWrt 源码作者 # ${OP_REPO} OpenWrt 仓库名称 # ${OP_BRANCH} OpenWrt 源码分支 - # ${TARGET_PROFILE} 设备名称, 例如: d-team_newifi-d2 - # ${TARGET_BOARD} 设备架构, 例如: ramips + # ${TARGET_PROFILE} 设备名称 + # ${TARGET_BOARD} 设备架构 + # ${TARGET_FLAG} 固件名称后缀 # ${Home} OpenWrt 源码位置 - # ${FEEDS_CONF} [feeds.conf.default] 文件 + # ${CONFIG_FILE} 使用的配置文件名称 + # ${FEEDS_CONF} OpenWrt 源码目录下的 feeds.conf.default 文件 # ${CustomFiles} 仓库中的 /CustomFiles 绝对路径 # ${Scripts} 仓库中的 /Scripts 绝对路径 - # ${FEEDS_LUCI} OpenWrt 源码目录下的 package/feeds/luci - # ${FEEDS_PKG} OpenWrt 源码目录下的 package/feeds/packages - # ${BASE_FILES} 俗称替换大法的路径, 位于 package/base-files/files + # ${FEEDS_LUCI} OpenWrt 源码目录下的 package/feeds/luci 目录 + # ${FEEDS_PKG} OpenWrt 源码目录下的 package/feeds/packages 目录 + # ${BASE_FILES} OpenWrt 源码目录下的 package/base-files/files 目录 case "${OP_AUTHOR}/${OP_REPO}:${OP_BRANCH}" in coolsnowwolf/lede:master) @@ -48,6 +51,7 @@ Firmware_Diy() { AddPackage svn other luci-app-socat Lienol/openwrt-package/trunk AddPackage svn other luci-app-eqos kenzok8/openwrt-packages/trunk AddPackage git other OpenClash vernesong master + AddPackage git other luci-app-usb3disable rufengsuixing master # AddPackage git other OpenAppFilter destan19 master # AddPackage svn other luci-app-ddnsto linkease/nas-packages/trunk/luci # AddPackage svn other ddnsto linkease/nas-packages/trunk/network/services @@ -57,15 +61,8 @@ Firmware_Diy() { patch -i ${CustomFiles}/${TARGET_PROFILE}_mac80211.patch package/kernel/mac80211/files/lib/wifi/mac80211.sh Copy ${CustomFiles}/${TARGET_PROFILE}_system ${BASE_FILES}/etc/config system sed -i "/DEVICE_COMPAT_VERSION := 1.1/d" target/linux/ramips/image/mt7621.mk - AddPackage git other luci-app-usb3disable rufengsuixing master ;; x86_64) - cat >> ${Version_File} <> ${GITHUB_ENV} <> ${Version_File} <> ${CONFIG_TEMP} < 指定 x86 设备下载 引导的固件 (e.g. UEFI BIOS) -C 更改 Github 地址为提供的 --api 打印 Github API 内容 + --flag 更改固件标签为提供的 + --flag reset 恢复默认的固件标签 --help 打印 AutoUpdate 帮助信息 --log < | del> <打印 | 删除> AutoUpdate 历史运行日志 --log --path 更改 AutoUpdate 运行日志路径为提供的绝对路径 @@ -45,7 +47,6 @@ function SHELL_HELP() { --chk 检查 AutoUpdate 运行环境 --clean 清理 AutoUpdate 缓存 --fw-log < | *> 打印 <当前 | 指定> 版本的固件更新日志 - --fw-list 打印所有云端固件名称 --list 打印当前系统信息 --var 打印用户指定的环境变量 --verbose 打印详细下载信息 * @@ -313,6 +314,12 @@ function LOAD_VARIABLE() { [[ ! ${TARGET_PROFILE} ]] && eval TARGET_PROFILE="$(jq .model.id /etc/board.json 2> /dev/null)" [[ ! ${TARGET_PROFILE} || ${TARGET_PROFILE} == null ]] && ECHO r "当前设备名称获取失败!" && EXIT 1 [[ ! ${OP_VERSION} ]] && OP_VERSION="未知" + if [[ $(LIST_ENV 1) =~ TARGET_FLAG ]] + then + [[ -z ${TARGET_FLAG} ]] && TARGET_FLAG="Full" + else + unset TARGET_FLAG + fi DISTRIB_TARGET="$(GET_VARIABLE DISTRIB_TARGET /etc/openwrt_release)" TARGET_BOARD="$(echo ${DISTRIB_TARGET} | cut -d '/' -f1)" TARGET_SUBTARGET="$(echo ${DISTRIB_TARGET} | cut -d '/' -f2)" @@ -374,6 +381,29 @@ function CHANGE_BOOT() { esac } +function CHANGE_FLAG() { + case $1 in + reset) + EDIT_VARIABLE rm ${Custom_Variable} TARGET_FLAG + ECHO y "固件标签已恢复为默认!" + ECHO y "当前固件标签: [$(GET_VARIABLE TARGET_FLAG ${Default_Variable})]" + EXIT 0 + ;; + *) + if [[ ! $1 =~ (\"|=|-|_|\.|\#|\|) && $1 =~ [a-zA-Z0-9] ]] + then + EDIT_VARIABLE edit ${Custom_Variable} TARGET_FLAG $1 + ECHO r "警告: 修改此设置后更新固件后可能导致无法检测到更新!" + ECHO y "固件标签已指定为: [$1]" + EXIT 0 + else + ECHO r "错误的参数: [$1], 当前仅支持 [a-zA-Z0-9] 且不能包含 <\" = - _ # |> 等特殊字符!" + EXIT 1 + fi + ;; + esac +} + function UPDATE_SCRIPT() { if [[ ! -d $1 ]];then mkdir -p $1 2> /dev/null || { @@ -492,6 +522,34 @@ function ANALYZE_API() { fi } +function GET_FW_INFO() { + local Info Type Result + [[ ! -s ${API_File} ]] && { + ECHO r "未检测到 API 文件!" + EXIT 1 + } + Info=$(grep "AutoBuild-${OP_REPO}-${TARGET_PROFILE}" ${API_File} | grep "${x86_Boot_Method}" | grep "${TARGET_FLAG}" | awk 'BEGIN {MAX = 0} {if ($6+0 > MAX+0) {MAX=$6 ;content=$0} } END {print content}') + Result="$(echo "${Info}" | awk '{print $"'${1}'"}' 2> /dev/null)" + case $1 in + 1) Type="固件名称";; + 2) Type="固件格式";; + 3) Type="下载次数";; + 4) Type="校验信息";; + 5) Type="固件版本";; + 6) Type="发布日期";; + 7) Type="固件体积";; + 8) Type="固件链接";; + *) Type="未定义信息";; + esac + [[ ! ${Result} == "-" ]] && { + LOGGER "${Type}: ${Result}" + echo -e "${Result}" + } || { + LOGGER "${Type}获取失败!" + return 1 + } +} + function GET_CLOUD_LOG() { local Version log_Test [[ ! $(cat ${API_File} 2> /dev/null) =~ Update_Logs.json ]] && { @@ -524,39 +582,6 @@ function GET_CLOUD_LOG() { fi } -function GET_FW_INFO() { - local Info Type Result - [[ ! -s ${API_File} ]] && { - ECHO r "未检测到 API 文件!" - EXIT 1 - } - if [[ $1 == "-a" ]];then - Info=$(grep "AutoBuild-${OP_REPO}-${TARGET_PROFILE}" ${API_File} | grep "${x86_Boot_Method}" | uniq) - shift - else - Info=$(grep "AutoBuild-${OP_REPO}-${TARGET_PROFILE}" ${API_File} | grep "${x86_Boot_Method}" | awk 'BEGIN {MAX = 0} {if ($6+0 > MAX+0) {MAX=$6 ;content=$0} } END {print content}') - fi - Result="$(echo "${Info}" | awk '{print $"'${1}'"}' 2> /dev/null)" - case $1 in - 1) Type="固件名称";; - 2) Type="固件格式";; - 3) Type="下载次数";; - 4) Type="校验信息";; - 5) Type="固件版本";; - 6) Type="发布日期";; - 7) Type="固件体积";; - 8) Type="固件链接";; - *) Type="未定义信息";; - esac - [[ ! ${Result} == "-" ]] && { - LOGGER "获取${Type}: ${Result}" - echo -e "${Result}" - } || { - LOGGER "[GET_FW_INFO] ${Type}获取失败!" - return 1 - } -} - function UPGRADE() { TITLE [[ $* =~ -f && $* =~ -F ]] && SHELL_HELP @@ -1153,17 +1178,22 @@ function AutoUpdate_Main() { ;; --env-list) shift - [[ ! $* ]] && LIST_ENV 0 && EXIT 0 case "$1" in 1 | 2) LIST_ENV $1 ;; *) - SHELL_HELP + LIST_ENV 0 ;; esac EXIT ;; + --flag) + shift + [[ -z $* ]] && SHELL_HELP + CHANGE_FLAG $1 + EXIT + ;; -V) shift [[ ! $* ]] && echo "${OP_VERSION}" && EXIT 0 @@ -1250,11 +1280,6 @@ function AutoUpdate_Main() { LOG $* EXIT ;; - --fw-list) - ANALYZE_API - GET_FW_INFO -a 1 - EXIT - ;; *) SHELL_HELP EXIT