2020-09-19 07:37:55 +00:00
|
|
|
|
#!/bin/bash
|
2021-06-06 06:05:58 +00:00
|
|
|
|
# AutoBuild Module by Hyy2001 <https://github.com/Hyy2001X/AutoBuild-Actions>
|
2020-12-09 14:15:04 +00:00
|
|
|
|
# AutoUpdate for Openwrt
|
2021-08-10 12:15:15 +00:00
|
|
|
|
# Dependences: bash wget-ssl/wget/uclient-fetch curl openssl jsonfilter
|
2020-09-19 07:37:55 +00:00
|
|
|
|
|
2021-10-06 04:09:48 +00:00
|
|
|
|
Version=V6.6.3
|
2021-07-21 07:37:29 +00:00
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function TITLE() {
|
|
|
|
|
clear && echo "Openwrt-AutoUpdate Script by Hyy2001 ${Version}"
|
2021-06-06 06:05:58 +00:00
|
|
|
|
}
|
2020-09-23 09:43:46 +00:00
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function SHELL_HELP() {
|
2021-06-13 09:46:34 +00:00
|
|
|
|
TITLE
|
2021-06-06 06:05:58 +00:00
|
|
|
|
cat <<EOF
|
2021-04-29 12:35:12 +00:00
|
|
|
|
|
2021-08-10 04:35:48 +00:00
|
|
|
|
使用方法: bash $0 [-n] [-f] [-u] [-F] [-P] [-D <Downloader>] [--path <PATH>]
|
|
|
|
|
bash $0 [-x] [--path <PATH>] [--url <URL>]
|
2021-04-29 12:35:12 +00:00
|
|
|
|
|
2021-06-06 06:05:58 +00:00
|
|
|
|
更新固件:
|
2021-07-21 07:37:29 +00:00
|
|
|
|
-n 不保留配置更新固件 *
|
|
|
|
|
-u 适用于定时更新 LUCI 的参数 *
|
|
|
|
|
-f 跳过版本号、SHA256 校验,并强制刷写固件 (危险) *
|
|
|
|
|
-F, --force-write 强制刷写固件 *
|
|
|
|
|
-P, --proxy 优先开启镜像加速下载固件 *
|
2021-08-10 04:35:48 +00:00
|
|
|
|
-D <Downloader> 使用指定的下载器 <wget-ssl | wget | curl | uclient-fetch> *
|
2021-08-09 16:50:51 +00:00
|
|
|
|
--decompress 解压 img.gz 固件后再更新固件 *
|
|
|
|
|
--skip-verify 跳过固件 SHA256 校验 (危险) *
|
|
|
|
|
--path <PATH> 保存固件到提供的绝对路径 <PATH> *
|
2021-04-29 12:35:12 +00:00
|
|
|
|
|
2021-05-16 12:58:30 +00:00
|
|
|
|
更新脚本:
|
2021-07-12 15:38:14 +00:00
|
|
|
|
-x 更新 AutoUpdate.sh 脚本
|
2021-08-09 16:50:51 +00:00
|
|
|
|
-x --path <PATH> 更新 AutoUpdate.sh 脚本 (保存脚本到提供的绝对路径 <PATH>) *
|
2021-08-10 04:35:48 +00:00
|
|
|
|
-x --url <URL> 更新 AutoUpdate.sh 脚本 (使用提供的地址 <URL> 更新脚本) *
|
2021-05-06 13:12:01 +00:00
|
|
|
|
|
2021-06-06 06:05:58 +00:00
|
|
|
|
其他参数:
|
2021-07-21 07:37:29 +00:00
|
|
|
|
-B, --boot-mode <TYPE> 指定 x86 设备下载 <TYPE> 引导的固件 (e.g. UEFI Legacy)
|
2021-08-09 16:50:51 +00:00
|
|
|
|
-C <Github URL> 更改 Github 地址为提供的 <Github URL>
|
2021-07-21 07:37:29 +00:00
|
|
|
|
-H, --help 打印 AutoUpdate 帮助信息
|
|
|
|
|
-L, --log < | del> <打印 | 删除> AutoUpdate 历史运行日志
|
2021-08-10 04:35:48 +00:00
|
|
|
|
--log --path <PATH> 更改 AutoUpdate 运行日志路径为提供的绝对路径 <PATH>
|
2021-08-10 12:15:15 +00:00
|
|
|
|
-O 打印云端可用固件名称
|
2021-08-10 04:35:48 +00:00
|
|
|
|
-P <F | G> 使用 <FastGit | Ghproxy> 镜像加速 *
|
|
|
|
|
--backup --path <PATH> 备份当前系统配置文件并移动到提供的绝对路径 <PATH> (可选)
|
2021-08-09 16:50:51 +00:00
|
|
|
|
--check 检查 AutoUpdate 运行环境
|
2021-07-21 07:37:29 +00:00
|
|
|
|
--clean 清理 AutoUpdate 缓存
|
2021-08-09 16:50:51 +00:00
|
|
|
|
--fw-log < | [Cc]loud | *> 打印 <当前 | 云端 | 指定版本> 版本的固件更新日志
|
2021-07-21 07:37:29 +00:00
|
|
|
|
--list 打印当前系统信息
|
2021-08-09 16:50:51 +00:00
|
|
|
|
--var <VARIABLE> 打印用户指定的环境变量 <VARIABLE>
|
|
|
|
|
--verbose 打印详细的下载信息 *
|
|
|
|
|
-v < | [Cc]loud> 打印 <当前 | 云端> AutoUpdate.sh 版本
|
|
|
|
|
-V < | [Cc]loud> 打印 <当前 | 云端> 固件版本
|
|
|
|
|
|
2021-07-24 06:37:09 +00:00
|
|
|
|
脚本、固件更新问题反馈请前往 ${Github}, 并附上 AutoUpdate 运行日志与系统信息 (见上方)
|
2021-06-07 08:27:27 +00:00
|
|
|
|
|
2021-04-29 12:35:12 +00:00
|
|
|
|
EOF
|
2021-06-25 13:48:54 +00:00
|
|
|
|
EXIT
|
2021-04-05 01:44:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function SHOW_VARIABLE() {
|
2021-06-06 06:05:58 +00:00
|
|
|
|
TITLE
|
|
|
|
|
cat <<EOF
|
2021-04-29 12:35:12 +00:00
|
|
|
|
|
2021-06-06 06:05:58 +00:00
|
|
|
|
设备名称: $(uname -n) / ${TARGET_PROFILE}
|
2021-06-23 05:55:52 +00:00
|
|
|
|
固件版本: ${CURRENT_Version}
|
2021-07-24 06:37:09 +00:00
|
|
|
|
内核版本: $(uname -r)
|
2021-07-16 16:14:38 +00:00
|
|
|
|
其他参数: ${TARGET_BOARD} / ${TARGET_SUBTARGET}
|
2021-06-08 06:22:26 +00:00
|
|
|
|
固件作者: ${Author}
|
2021-08-09 16:50:51 +00:00
|
|
|
|
作者仓库: ${Github}
|
|
|
|
|
Github Release: ${Github_Release}
|
|
|
|
|
Github API: ${Github_API}
|
|
|
|
|
Github Raw: ${Github_Raw}
|
|
|
|
|
OpenWrt Source: https://github.com/${OP_Maintainer}/${OP_REPO_NAME}:${OP_BRANCH}
|
|
|
|
|
固件格式: ${Firmware_Format}
|
|
|
|
|
运行路径: ${Running_Path}
|
|
|
|
|
日志路径: ${Log_Path}/AutoUpdate.log
|
2021-04-29 12:35:12 +00:00
|
|
|
|
EOF
|
2021-07-16 16:14:38 +00:00
|
|
|
|
[[ ${TARGET_BOARD} == x86 ]] && {
|
2021-07-21 07:37:29 +00:00
|
|
|
|
echo "固件引导模式: ${x86_Boot}"
|
2021-04-30 14:20:27 +00:00
|
|
|
|
}
|
2021-07-21 07:37:29 +00:00
|
|
|
|
echo
|
2021-07-22 06:30:08 +00:00
|
|
|
|
LIST_ENV 0
|
|
|
|
|
echo
|
2021-06-13 09:46:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-10 12:15:15 +00:00
|
|
|
|
function RM() {
|
|
|
|
|
rm -f $1 2> /dev/null
|
2021-10-06 04:09:48 +00:00
|
|
|
|
[[ $? == 0 ]] && LOGGER "[RM] [$1] 删除成功!" || LOGGER "[RM] [$1] 不存在或删除失败!"
|
2021-07-04 04:39:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function LIST_ENV() {
|
2021-06-28 03:13:30 +00:00
|
|
|
|
local X
|
|
|
|
|
cat /etc/AutoBuild/*_Variable | grep -v '#' | while read X;do
|
|
|
|
|
[[ ${X} =~ "=" ]] && {
|
2021-07-16 16:14:38 +00:00
|
|
|
|
case "$1" in
|
2021-06-28 03:13:30 +00:00
|
|
|
|
1 | 2)
|
2021-08-10 12:15:15 +00:00
|
|
|
|
[[ -n $(echo ${X} | cut -d "=" -f1) ]] && echo "${X}" | cut -d "=" -f$1
|
2021-06-28 03:13:30 +00:00
|
|
|
|
;;
|
|
|
|
|
0)
|
2021-07-16 16:14:38 +00:00
|
|
|
|
echo "${X}"
|
2021-06-28 03:13:30 +00:00
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function CHECK_ENV() {
|
2021-07-22 06:30:08 +00:00
|
|
|
|
while [[ $1 ]];do
|
2021-10-06 04:09:48 +00:00
|
|
|
|
[[ $(LIST_ENV 1) =~ $1 ]] && LOGGER "[CHECK_ENV] Checking env $1 ... true" || ECHO r "[CHECK_ENV] Checking env $1 ... false"
|
2021-07-22 06:30:08 +00:00
|
|
|
|
shift
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function EXIT() {
|
2021-10-02 05:29:03 +00:00
|
|
|
|
case $1 in
|
2021-10-03 12:14:53 +00:00
|
|
|
|
1)
|
2021-10-02 05:29:03 +00:00
|
|
|
|
REMOVE_CACHE
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2021-08-09 16:50:51 +00:00
|
|
|
|
LOGGER "[${COMMAND}] 运行结束 $1"
|
2021-07-16 16:14:38 +00:00
|
|
|
|
exit
|
2020-09-25 01:51:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function ECHO() {
|
|
|
|
|
local Color Quiet_Mode
|
2021-06-06 06:05:58 +00:00
|
|
|
|
[[ -z $1 ]] && {
|
2021-06-22 14:14:56 +00:00
|
|
|
|
echo -ne "\n${Grey}[$(date "+%H:%M:%S")]${White} "
|
2021-05-13 09:12:35 +00:00
|
|
|
|
} || {
|
2021-08-09 16:50:51 +00:00
|
|
|
|
while [[ $1 ]];do
|
2021-08-10 12:15:15 +00:00
|
|
|
|
case "$1" in
|
2021-08-09 16:50:51 +00:00
|
|
|
|
r | g | b | y | x)
|
|
|
|
|
case "$1" in
|
|
|
|
|
r) Color="${Red}";;
|
|
|
|
|
g) Color="${Green}";;
|
|
|
|
|
b) Color="${Blue}";;
|
|
|
|
|
y) Color="${Yellow}";;
|
|
|
|
|
x) Color="${Grey}";;
|
|
|
|
|
esac
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
quiet)
|
|
|
|
|
Quiet_Mode=1
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
Message="$1"
|
|
|
|
|
break
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
[[ ! ${Quiet_Mode} == 1 ]] && {
|
|
|
|
|
echo -e "\n${Grey}[$(date "+%H:%M:%S")]${White}${Color} ${Message}${White}"
|
|
|
|
|
LOGGER "${Message}"
|
|
|
|
|
} || LOGGER "[Quiet Mode] ${Message}"
|
2021-05-13 09:12:35 +00:00
|
|
|
|
}
|
2021-02-21 12:23:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function LOGGER() {
|
2021-08-10 16:48:03 +00:00
|
|
|
|
if [[ ! $* =~ (-H|--help|-L|--log) ]];then
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ ! -d ${Log_Path} ]] && mkdir -p ${Log_Path}
|
|
|
|
|
[[ ! -f ${Log_Path}/AutoUpdate.log ]] && touch ${Log_Path}/AutoUpdate.log
|
|
|
|
|
echo "[$(date "+%Y-%m-%d-%H:%M:%S")] [$$] $*" >> ${Log_Path}/AutoUpdate.log
|
|
|
|
|
fi
|
2021-06-25 13:48:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function CHECK_PKG() {
|
2021-06-06 06:05:58 +00:00
|
|
|
|
which $1 > /dev/null 2>&1
|
2021-08-10 12:15:15 +00:00
|
|
|
|
[[ $? == 0 ]] && echo true || echo false
|
2021-04-30 14:20:27 +00:00
|
|
|
|
}
|
2021-05-13 09:12:35 +00:00
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function RANDOM() {
|
2021-07-04 11:04:07 +00:00
|
|
|
|
local Result=$(openssl rand -base64 $1 | md5sum | cut -c 1-$1)
|
2021-07-21 07:37:29 +00:00
|
|
|
|
[[ -n ${Result} ]] && echo "${Result}"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
LOGGER "[RANDOM] $1 Bit 计算结果: [${Result}]"
|
2021-06-18 13:53:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function GET_SHA256SUM() {
|
2021-06-23 11:01:05 +00:00
|
|
|
|
[[ ! -f $1 && ! -s $1 ]] && {
|
2021-10-06 04:09:48 +00:00
|
|
|
|
LOGGER "[GET_SHA256SUM] 未检测到文件 [$1],无法计算 SHA256 值!"
|
2021-06-23 11:01:05 +00:00
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
2021-07-04 11:04:07 +00:00
|
|
|
|
local Result=$(sha256sum $1 | cut -c1-$2)
|
2021-07-21 07:37:29 +00:00
|
|
|
|
[[ -n ${Result} ]] && echo "${Result}"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
LOGGER "[GET_SHA256SUM] 计算结果: [${Result}]"
|
2021-06-23 11:01:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function GET_VARIABLE() {
|
2021-06-18 13:53:57 +00:00
|
|
|
|
[[ $# != 2 ]] && SHELL_HELP
|
2021-06-25 13:48:54 +00:00
|
|
|
|
[[ ! -f $2 ]] && ECHO "未检测到定义文件: [$2] !" && EXIT 1
|
2021-07-04 11:04:07 +00:00
|
|
|
|
local Result="$(grep "$1=" $2 | grep -v "#" | awk 'NR==1' | sed -r "s/$1=(.*)/\1/")"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ -n ${Result} ]] && {
|
|
|
|
|
echo "${Result}"
|
|
|
|
|
LOGGER "[GET_VARIABLE] 获取到环境变量 $1=[${Result}]"
|
|
|
|
|
} || {
|
|
|
|
|
LOGGER "[GET_VARIABLE] 环境变量 [$1] 获取失败!"
|
|
|
|
|
}
|
2021-06-18 13:53:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function LOAD_VARIABLE() {
|
2021-06-06 06:05:58 +00:00
|
|
|
|
while [[ $1 ]];do
|
|
|
|
|
[[ -f $1 ]] && {
|
|
|
|
|
chmod 777 $1
|
|
|
|
|
source $1
|
2021-10-06 04:09:48 +00:00
|
|
|
|
} || LOGGER "[LOAD_VARIABLE] 未检测到环境变量列表: [$1]"
|
2021-06-06 06:05:58 +00:00
|
|
|
|
shift
|
|
|
|
|
done
|
|
|
|
|
[[ -z ${TARGET_PROFILE} ]] && TARGET_PROFILE="$(jsonfilter -e '@.model.id' < /etc/board.json | tr ',' '_')"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ -z ${TARGET_PROFILE} ]] && ECHO r "获取设备名称失败!" && EXIT 1
|
|
|
|
|
[[ -z ${Github} ]] && ECHO "Github URL 获取失败!" && EXIT 1
|
2021-07-24 06:37:09 +00:00
|
|
|
|
[[ -z ${CURRENT_Version} ]] && CURRENT_Version="未知"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
Firmware_Author="${Github##*com/}"
|
|
|
|
|
Github_Release="${Github}/releases/download/AutoUpdate"
|
|
|
|
|
Github_Raw="https://raw.githubusercontent.com/${Firmware_Author}/master"
|
|
|
|
|
Github_API="https://api.github.com/repos/${Firmware_Author}/releases/latest"
|
2021-07-16 16:14:38 +00:00
|
|
|
|
case "${TARGET_BOARD}" in
|
|
|
|
|
x86)
|
2021-08-09 16:50:51 +00:00
|
|
|
|
case "${Firmware_Format}" in
|
2021-06-06 06:05:58 +00:00
|
|
|
|
img.gz | img)
|
2021-07-16 16:14:38 +00:00
|
|
|
|
[[ -z ${x86_Boot} ]] && {
|
2021-06-06 06:05:58 +00:00
|
|
|
|
[ -d /sys/firmware/efi ] && {
|
2021-07-16 16:14:38 +00:00
|
|
|
|
x86_Boot=UEFI
|
|
|
|
|
} || x86_Boot=Legacy
|
2021-06-06 06:05:58 +00:00
|
|
|
|
}
|
|
|
|
|
;;
|
|
|
|
|
*)
|
2021-07-13 05:24:30 +00:00
|
|
|
|
ECHO r "[${TARGET_PROFILE}] 设备暂不支持当前固件格式!"
|
2021-06-13 09:46:34 +00:00
|
|
|
|
EXIT 1
|
2021-06-06 06:05:58 +00:00
|
|
|
|
;;
|
|
|
|
|
esac
|
2021-03-24 14:06:20 +00:00
|
|
|
|
;;
|
2021-06-06 06:05:58 +00:00
|
|
|
|
*)
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ -z ${Firmware_Format} ]] && Firmware_Format=bin
|
2021-03-24 14:06:20 +00:00
|
|
|
|
esac
|
2021-06-06 06:05:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function EDIT_VARIABLE() {
|
2021-06-13 09:46:34 +00:00
|
|
|
|
local Mode="$1"
|
2021-06-08 06:22:26 +00:00
|
|
|
|
shift
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ ! -f $1 ]] && ECHO r "未检测到环境变量文件: [$1] !" && EXIT 1
|
2021-06-08 06:22:26 +00:00
|
|
|
|
case "${Mode}" in
|
|
|
|
|
edit)
|
2021-07-04 11:04:07 +00:00
|
|
|
|
[[ $# != 3 ]] && SHELL_HELP
|
2021-06-27 15:46:56 +00:00
|
|
|
|
[[ -z $(GET_VARIABLE $2 $1) ]] && {
|
2021-08-09 16:50:51 +00:00
|
|
|
|
LOGGER "[EDIT_VARIABLE] 新增环境变量 [$2=$3]"
|
2021-06-08 06:22:26 +00:00
|
|
|
|
echo -e "\n$2=$3" >> $1
|
2021-07-04 11:04:07 +00:00
|
|
|
|
} || {
|
|
|
|
|
sed -i "s?$(GET_VARIABLE $2 $1)?$3?g" $1
|
|
|
|
|
}
|
2021-06-13 13:33:16 +00:00
|
|
|
|
;;
|
2021-06-08 06:22:26 +00:00
|
|
|
|
rm)
|
2021-06-13 13:33:16 +00:00
|
|
|
|
[[ $# != 2 ]] && SHELL_HELP
|
2021-08-09 16:50:51 +00:00
|
|
|
|
LOGGER "[EDIT_VARIABLE] 从 $1 删除环境变量 [$2] ..."
|
2021-06-13 13:33:16 +00:00
|
|
|
|
sed -i "/$2/d" $1
|
2021-06-08 06:22:26 +00:00
|
|
|
|
;;
|
|
|
|
|
esac
|
2021-06-06 06:05:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function CHANGE_GITHUB() {
|
2021-06-06 06:05:58 +00:00
|
|
|
|
[[ ! $1 =~ https://github.com/ ]] && {
|
2021-08-09 16:50:51 +00:00
|
|
|
|
ECHO r "Github 地址输入有误,正确示例: https://github.com/Hyy2001X/AutoBuild-Actions"
|
2021-06-13 09:46:34 +00:00
|
|
|
|
EXIT 1
|
2021-06-06 06:05:58 +00:00
|
|
|
|
}
|
2021-08-09 16:50:51 +00:00
|
|
|
|
UCI_Github=$(uci get autoupdate.@common[0].github 2> /dev/null)
|
|
|
|
|
[[ -n ${UCI_Github} && ! ${UCI_Github} == $1 ]] && {
|
|
|
|
|
uci set autoupdate.@common[0].github=$1 2> /dev/null
|
|
|
|
|
LOGGER "[CHANGE_GITHUB] UCI 配置已设定为 [$1]"
|
2021-06-06 06:05:58 +00:00
|
|
|
|
}
|
|
|
|
|
[[ ! ${Github} == $1 ]] && {
|
2021-06-08 06:22:26 +00:00
|
|
|
|
EDIT_VARIABLE edit ${Custom_Variable} Github $1
|
2021-06-25 13:48:54 +00:00
|
|
|
|
ECHO y "Github 地址已修改为: $1"
|
2021-08-01 15:54:22 +00:00
|
|
|
|
REMOVE_CACHE
|
2021-05-06 13:12:01 +00:00
|
|
|
|
}
|
2021-06-13 09:46:34 +00:00
|
|
|
|
EXIT 0
|
2021-06-06 06:05:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function CHANGE_BOOT() {
|
2021-06-13 09:46:34 +00:00
|
|
|
|
[[ -z $1 ]] && SHELL_HELP
|
2021-06-06 06:05:58 +00:00
|
|
|
|
case "$1" in
|
|
|
|
|
UEFI | Legacy)
|
2021-07-16 16:14:38 +00:00
|
|
|
|
EDIT_VARIABLE edit ${Custom_Variable} x86_Boot $1
|
2021-06-25 13:48:54 +00:00
|
|
|
|
ECHO r "警告: 更换引导方式后更新固件后可能导致设备无法正常启动!"
|
2021-07-21 07:37:29 +00:00
|
|
|
|
ECHO y "固件引导格式已指定为: [$1]"
|
2021-07-06 12:32:29 +00:00
|
|
|
|
EXIT 0
|
2020-12-23 14:28:57 +00:00
|
|
|
|
;;
|
2021-06-06 06:05:58 +00:00
|
|
|
|
*)
|
2021-07-21 07:37:29 +00:00
|
|
|
|
ECHO r "错误的参数: [$1],支持的启动方式: [UEFI/Legacy]"
|
2021-06-13 09:46:34 +00:00
|
|
|
|
EXIT 1
|
2021-06-06 06:05:58 +00:00
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function UPDATE_SCRIPT() {
|
2021-07-13 05:24:30 +00:00
|
|
|
|
[[ -f $1 ]] && {
|
|
|
|
|
ECHO r "AutoUpdate 脚本保存路径有误,请重新输入!"
|
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
2021-08-09 16:50:51 +00:00
|
|
|
|
if [[ ! -d $1 ]];then
|
|
|
|
|
mkdir -p $1 2> /dev/null || {
|
2021-10-03 12:14:53 +00:00
|
|
|
|
ECHO r "脚本存放路径 [$1] 创建失败!"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
|
|
|
|
fi
|
|
|
|
|
DOWNLOADER --file-name AutoUpdate.sh --no-url-name --dl ${DOWNLOADERS} --url "$2" --path /tmp --timeout 5 --type 脚本
|
|
|
|
|
if [[ -s /tmp/AutoUpdate.sh ]];then
|
|
|
|
|
chmod +x /tmp/AutoUpdate.sh
|
|
|
|
|
Script_Version=$(egrep -o "V[0-9]+.[0-9].+" /tmp/AutoUpdate.sh | awk 'NR==1')
|
2021-06-06 06:05:58 +00:00
|
|
|
|
Banner_Version=$(egrep -o "V[0-9]+.[0-9].+" /etc/banner)
|
2021-08-09 16:50:51 +00:00
|
|
|
|
mv -f /tmp/AutoUpdate.sh $1
|
|
|
|
|
ECHO "脚本保存路径: [$1]"
|
2021-07-24 06:37:09 +00:00
|
|
|
|
[[ -n ${Banner_Version} && $1 == /bin ]] && sed -i "s?${Banner_Version}?${Script_Version}?g" /etc/banner
|
2021-08-09 16:50:51 +00:00
|
|
|
|
ECHO y "[${Banner_Version} > ${Script_Version}] AutoUpdate 脚本更新成功!"
|
2021-10-02 05:29:03 +00:00
|
|
|
|
REMOVE_CACHE
|
2021-06-18 13:53:57 +00:00
|
|
|
|
EXIT 0
|
2021-06-06 06:05:58 +00:00
|
|
|
|
else
|
2021-08-10 04:35:48 +00:00
|
|
|
|
ECHO r "AutoUpdate 脚本更新失败!"
|
2021-06-18 13:53:57 +00:00
|
|
|
|
EXIT 1
|
2021-06-06 06:05:58 +00:00
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function CHECK_DEPENDS() {
|
2021-06-06 06:05:58 +00:00
|
|
|
|
TITLE
|
2021-07-24 06:37:09 +00:00
|
|
|
|
local PKG Tab
|
2021-06-28 03:13:30 +00:00
|
|
|
|
echo -e "\n软件包 检测结果"
|
2021-06-13 09:46:34 +00:00
|
|
|
|
while [[ $1 ]];do
|
|
|
|
|
if [[ $1 =~ : ]];then
|
|
|
|
|
[[ $(echo $1 | cut -d ":" -f1) == ${TARGET_BOARD} ]] && {
|
2021-07-21 07:37:29 +00:00
|
|
|
|
PKG="$(echo "$1" | cut -d ":" -f2)"
|
|
|
|
|
[[ $(echo "${PKG}" | wc -c) -gt 8 ]] && Tab=" " || Tab=" "
|
2021-06-28 03:13:30 +00:00
|
|
|
|
echo -e "${PKG}${Tab}$(CHECK_PKG ${PKG})"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
LOGGER "[CHECK_DEPENDS] 检查软件包: [${PKG}] ... $(CHECK_PKG ${PKG})"
|
2021-05-17 09:01:24 +00:00
|
|
|
|
}
|
2021-01-25 10:08:09 +00:00
|
|
|
|
else
|
2021-07-21 07:37:29 +00:00
|
|
|
|
[[ $(echo "$1" | wc -c) -gt 8 ]] && Tab=" " || Tab=" "
|
2021-06-28 03:13:30 +00:00
|
|
|
|
echo -e "$1${Tab}$(CHECK_PKG $1)"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
LOGGER "[CHECK_DEPENDS] 检查软件包: [$1] ... $(CHECK_PKG $1)"
|
2021-01-25 10:08:09 +00:00
|
|
|
|
fi
|
2021-06-13 09:46:34 +00:00
|
|
|
|
shift
|
2021-06-06 06:05:58 +00:00
|
|
|
|
done
|
2021-08-09 16:50:51 +00:00
|
|
|
|
ECHO y "AutoUpdate 依赖检测结束,请尝试手动安装测结果为 [false] 的项目!"
|
2021-06-06 06:05:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function FW_VERSION_CHECK() {
|
2021-08-10 12:15:15 +00:00
|
|
|
|
[[ $# -gt 1 ]] && echo false && return
|
2021-07-19 12:21:58 +00:00
|
|
|
|
[[ $1 =~ R[1-9.]{2}.+-[0-9]{8} ]] && {
|
2021-08-10 12:15:15 +00:00
|
|
|
|
echo true
|
2021-08-09 16:50:51 +00:00
|
|
|
|
LOGGER "[FW_VERSION_CHECK] 检查固件版本号: [$1] ... true"
|
2021-07-19 12:21:58 +00:00
|
|
|
|
} || {
|
2021-08-10 12:15:15 +00:00
|
|
|
|
echo false
|
2021-08-09 16:50:51 +00:00
|
|
|
|
LOGGER "[FW_VERSION_CHECK] 检查固件版本号: [$1] ... false"
|
2021-07-19 12:21:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function GET_FW_LOG() {
|
2021-07-21 07:37:29 +00:00
|
|
|
|
local Result
|
2021-08-10 12:15:15 +00:00
|
|
|
|
[[ ! $(cat ${API_File}) =~ Update_Logs.json ]] && return 1
|
2021-06-22 14:14:56 +00:00
|
|
|
|
case "$1" in
|
2021-07-16 16:14:38 +00:00
|
|
|
|
[Ll]ocal)
|
2021-06-22 14:14:56 +00:00
|
|
|
|
FW_Version="${CURRENT_Version}"
|
|
|
|
|
;;
|
2021-07-16 16:14:38 +00:00
|
|
|
|
[Cc]loud)
|
2021-08-10 12:15:15 +00:00
|
|
|
|
FW_Version="$(GET_CLOUD_INFO version)"
|
2021-06-22 14:14:56 +00:00
|
|
|
|
;;
|
|
|
|
|
-v)
|
|
|
|
|
shift
|
|
|
|
|
FW_Version="$1"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2021-08-10 12:15:15 +00:00
|
|
|
|
[[ $(CHECK_TIME ${Running_Path}/Update_Logs.json 2) == false ]] && {
|
|
|
|
|
DOWNLOADER --path ${Running_Path} --file-name Update_Logs.json --dl ${DOWNLOADERS} --url "$(URL_X ${Github_Release} G@@1)" --timeout 3 --type 固件更新日志 --quiet
|
|
|
|
|
}
|
|
|
|
|
[[ -s ${Running_Path}/Update_Logs.json ]] && {
|
2021-08-09 16:50:51 +00:00
|
|
|
|
Result=$(jsonfilter -e '@["'"""${TARGET_PROFILE}"""'"]["'"""${FW_Version}"""'"]' < ${Running_Path}/Update_Logs.json 2> /dev/null)
|
2021-07-21 07:37:29 +00:00
|
|
|
|
[[ -n ${Result} ]] && {
|
|
|
|
|
echo -e "\n${Grey}${FW_Version} for ${TARGET_PROFILE} 更新日志:"
|
|
|
|
|
echo -e "\n${Green}${Result}${White}"
|
|
|
|
|
}
|
2021-07-16 16:14:38 +00:00
|
|
|
|
}
|
2021-06-22 14:14:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-10 12:15:15 +00:00
|
|
|
|
function CHECK_TIME() {
|
|
|
|
|
[[ -s $1 && -n $(find $1 -type f -mmin -$2) ]] && {
|
|
|
|
|
LOGGER "[CHECK_TIME] 文件: [$1] 距离修改时间小于 $2 分钟!"
|
|
|
|
|
echo true
|
|
|
|
|
} || {
|
2021-08-10 16:48:03 +00:00
|
|
|
|
LOGGER "[CHECK_TIME] 文件: [$1] 验证失败!"
|
2021-08-10 12:15:15 +00:00
|
|
|
|
RM $1
|
|
|
|
|
echo false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 04:09:48 +00:00
|
|
|
|
function ANALYSIS_API() {
|
2021-10-01 04:37:57 +00:00
|
|
|
|
local url name date size version
|
2021-08-10 12:15:15 +00:00
|
|
|
|
local API_Dump=${Running_Path}/API_Dump
|
|
|
|
|
[[ $(CHECK_TIME ${API_File} 1) == false ]] && {
|
|
|
|
|
DOWNLOADER --path ${Running_Path} --file-name API_Dump --dl ${DOWNLOADERS} --url "$(URL_X ${Github_Release}/API G@@1 F@@1) ${Github_API}@@1 " --no-url-name --timeout 3 --type 固件信息 --quiet
|
|
|
|
|
[[ ! $? == 0 || -z $(cat ${API_Dump} 2> /dev/null) ]] && {
|
|
|
|
|
ECHO r "Github API 请求错误,请检查网络后重试!"
|
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
|
|
|
|
RM ${API_File} && touch -a ${API_File}
|
2021-10-06 04:09:48 +00:00
|
|
|
|
LOGGER "[ANALYSIS_API] 开始解析 Github API ..."
|
2021-08-10 12:15:15 +00:00
|
|
|
|
local i=1;while :;do
|
2021-10-06 04:09:48 +00:00
|
|
|
|
name=$(jsonfilter -e '@["assets"]' < ${API_Dump} | jsonfilter -e '@['"""$i"""'].name' 2> /dev/null)
|
2021-08-10 12:15:15 +00:00
|
|
|
|
[[ ! $? == 0 ]] && break
|
2021-10-06 04:09:48 +00:00
|
|
|
|
if [[ ${name} =~ "AutoBuild-${OP_REPO_NAME}-${TARGET_PROFILE}" ]]
|
2021-10-01 04:37:57 +00:00
|
|
|
|
then
|
|
|
|
|
version=$(echo ${name} | egrep -o "R[0-9.]+-[0-9]+")
|
2021-10-06 04:09:48 +00:00
|
|
|
|
url=$(jsonfilter -e '@["assets"]' < ${API_Dump} | jsonfilter -e '@['"""$i"""'].browser_download_url' 2> /dev/null)
|
|
|
|
|
size=$(jsonfilter -e '@["assets"]' < ${API_Dump} | jsonfilter -e '@['"""$i"""'].size' 2> /dev/null | awk '{a=$1/1048576} {printf("%.2f\n",a)}')
|
2021-10-01 04:37:57 +00:00
|
|
|
|
date=$(echo ${version} | cut -d '-' -f2)
|
|
|
|
|
printf "%-75s %-20s %-10s %-15s %s\n" ${name} ${version} ${date} ${size}MB ${url} >> ${API_File}
|
|
|
|
|
fi
|
2021-08-10 12:15:15 +00:00
|
|
|
|
i=$(($i + 1))
|
|
|
|
|
done
|
|
|
|
|
}
|
2021-10-06 04:09:48 +00:00
|
|
|
|
awk -F ' ' '{print NF}' ${API_File} | while read X;do
|
|
|
|
|
[[ ${X} != 5 ]] && LOGGER "[ANALYSIS_API] API 解析异常: ${X}"
|
|
|
|
|
done
|
2021-08-10 12:15:15 +00:00
|
|
|
|
[[ -z $(cat ${API_File} 2> /dev/null) ]] && {
|
2021-10-06 04:09:48 +00:00
|
|
|
|
ECHO r "Github API 解析失败!"
|
2021-06-13 09:46:34 +00:00
|
|
|
|
EXIT 1
|
2021-10-06 04:09:48 +00:00
|
|
|
|
} || LOGGER "[ANALYSIS_API] Github API 解析成功!"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-10 12:15:15 +00:00
|
|
|
|
function GET_CLOUD_INFO() {
|
|
|
|
|
local Info
|
2021-10-06 04:09:48 +00:00
|
|
|
|
[[ ! -s ${API_File} ]] && {
|
|
|
|
|
LOGGER "[GET_CLOUD_INFO] 未检测到 API 文件!"
|
2021-10-03 12:14:53 +00:00
|
|
|
|
return
|
|
|
|
|
}
|
2021-08-10 12:15:15 +00:00
|
|
|
|
if [[ $1 =~ (All|all|-a) ]];then
|
2021-10-01 04:37:57 +00:00
|
|
|
|
Info=$(grep "AutoBuild-${OP_REPO_NAME}-${TARGET_PROFILE}" ${API_File} | grep "${x86_Boot}" | uniq)
|
2021-08-10 12:15:15 +00:00
|
|
|
|
shift
|
|
|
|
|
else
|
2021-10-01 04:37:57 +00:00
|
|
|
|
Info=$(grep "AutoBuild-${OP_REPO_NAME}-${TARGET_PROFILE}" ${API_File} | grep "${x86_Boot}" | awk 'BEGIN {MAX = 0} {if ($3+0 > MAX+0) {MAX=$3 ;content=$0} } END {print content}')
|
2021-08-10 12:15:15 +00:00
|
|
|
|
fi
|
|
|
|
|
case "$1" in
|
|
|
|
|
name)
|
|
|
|
|
echo "${Info}" | awk '{print $1}'
|
2021-07-21 07:37:29 +00:00
|
|
|
|
;;
|
2021-08-10 12:15:15 +00:00
|
|
|
|
version)
|
|
|
|
|
echo "${Info}" | awk '{print $2}'
|
|
|
|
|
;;
|
2021-10-01 04:37:57 +00:00
|
|
|
|
date)
|
2021-08-10 12:15:15 +00:00
|
|
|
|
echo "${Info}" | awk '{print $3}'
|
|
|
|
|
;;
|
2021-10-01 04:37:57 +00:00
|
|
|
|
size)
|
2021-08-10 12:15:15 +00:00
|
|
|
|
echo "${Info}" | awk '{print $4}'
|
2021-07-21 07:37:29 +00:00
|
|
|
|
;;
|
2021-10-01 04:37:57 +00:00
|
|
|
|
url)
|
|
|
|
|
echo "${Info}" | awk '{print $5}'
|
|
|
|
|
;;
|
2021-07-21 07:37:29 +00:00
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function CHECK_UPDATES() {
|
2021-08-10 12:15:15 +00:00
|
|
|
|
local Version
|
|
|
|
|
Version="$(GET_CLOUD_INFO version)"
|
|
|
|
|
[[ $(FW_VERSION_CHECK ${Version}) == false ]] && {
|
2021-07-21 07:37:29 +00:00
|
|
|
|
ECHO r "固件版本合法性校验失败!"
|
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
2021-08-10 12:15:15 +00:00
|
|
|
|
[[ ${Version} == ${CURRENT_Version} ]] && {
|
2021-06-22 14:14:56 +00:00
|
|
|
|
CURRENT_Type="${Yellow} [已是最新]${White}"
|
|
|
|
|
Upgrade_Stopped=1
|
|
|
|
|
} || {
|
2021-08-10 12:15:15 +00:00
|
|
|
|
[[ $(echo ${Version} | cut -d "-" -f2) -gt $(echo ${CURRENT_Version} | cut -d "-" -f2) ]] && CURRENT_Type="${Green} [可更新]${White}"
|
|
|
|
|
[[ $(echo ${Version} | cut -d "-" -f2) -lt $(echo ${CURRENT_Version} | cut -d "-" -f2) ]] && {
|
2021-07-21 07:37:29 +00:00
|
|
|
|
CHECKED_Type="${Red} [旧版本]${White}"
|
2021-06-22 14:14:56 +00:00
|
|
|
|
Upgrade_Stopped=2
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-06 06:05:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function UPGRADE() {
|
2021-06-06 06:05:58 +00:00
|
|
|
|
TITLE
|
2021-06-27 15:46:56 +00:00
|
|
|
|
[[ $* =~ -f && $* =~ -F ]] && SHELL_HELP
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ $(NETWORK_CHECK 223.5.5.5 2) == false ]] && {
|
|
|
|
|
ECHO r "网络连接错误,请稍后再试!"
|
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
2021-08-10 12:15:15 +00:00
|
|
|
|
Firmware_Path="${Running_Path}"
|
2021-07-19 12:21:58 +00:00
|
|
|
|
Upgrade_Option="sysupgrade -q"
|
2021-07-06 12:32:29 +00:00
|
|
|
|
MSG="更新固件"
|
2021-06-12 10:37:10 +00:00
|
|
|
|
while [[ $1 ]];do
|
2021-07-06 12:32:29 +00:00
|
|
|
|
case "$1" in
|
|
|
|
|
-T | --test)
|
2021-06-06 06:05:58 +00:00
|
|
|
|
Test_Mode=1
|
2021-07-06 12:32:29 +00:00
|
|
|
|
Special_Commands="${Special_Commands} [测试模式]"
|
|
|
|
|
;;
|
2021-07-21 07:37:29 +00:00
|
|
|
|
-P | --proxy)
|
2021-08-10 12:15:15 +00:00
|
|
|
|
case "$2" in
|
2021-08-09 16:50:51 +00:00
|
|
|
|
F | G)
|
|
|
|
|
Proxy_Type="$2"
|
2021-07-30 15:04:23 +00:00
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
*)
|
2021-08-09 16:50:51 +00:00
|
|
|
|
Proxy_Type="All"
|
2021-07-30 15:04:23 +00:00
|
|
|
|
;;
|
|
|
|
|
esac
|
2021-08-09 16:50:51 +00:00
|
|
|
|
Special_Commands="${Special_Commands} [镜像加速 ${Proxy_Type}]"
|
|
|
|
|
;;
|
|
|
|
|
-D)
|
|
|
|
|
DOWNLOADERS="$2"
|
|
|
|
|
Special_Commands="${Special_Commands} [${DOWNLOADERS}]"
|
|
|
|
|
shift
|
2021-07-06 12:32:29 +00:00
|
|
|
|
;;
|
2021-07-21 07:37:29 +00:00
|
|
|
|
-F | --force-write)
|
2021-07-06 12:32:29 +00:00
|
|
|
|
[[ -n ${Force_Mode} ]] && SHELL_HELP
|
|
|
|
|
Only_Force_Write=1
|
|
|
|
|
Special_Commands="${Special_Commands} [强制刷写]"
|
|
|
|
|
Upgrade_Option="${Upgrade_Option} -F"
|
|
|
|
|
;;
|
2021-08-09 16:50:51 +00:00
|
|
|
|
--decompress)
|
|
|
|
|
Special_Commands="${Special_Commands} [解压固件]"
|
|
|
|
|
Decompress_Mode=1
|
2021-07-06 12:32:29 +00:00
|
|
|
|
;;
|
|
|
|
|
-f)
|
|
|
|
|
[[ -n ${Only_Force_Write} ]] && SHELL_HELP
|
|
|
|
|
Force_Mode=1
|
|
|
|
|
Special_Commands="${Special_Commands} [强制模式]"
|
|
|
|
|
Upgrade_Option="${Upgrade_Option} -F"
|
|
|
|
|
;;
|
|
|
|
|
-n)
|
|
|
|
|
Upgrade_Option="${Upgrade_Option} -n"
|
|
|
|
|
Special_MSG=" (不保留配置)"
|
2021-06-12 10:37:10 +00:00
|
|
|
|
;;
|
2021-08-09 16:50:51 +00:00
|
|
|
|
--path)
|
2021-08-10 12:15:15 +00:00
|
|
|
|
Firmware_Path="$2"
|
|
|
|
|
ECHO g "使用自定义固件保存路径: [${Firmware_Path}]"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
--skip-verify)
|
|
|
|
|
Skip_Verify=1
|
|
|
|
|
Special_Commands="${Special_Commands} [跳过 SHA256 验证]"
|
|
|
|
|
;;
|
2021-07-06 12:32:29 +00:00
|
|
|
|
-u)
|
|
|
|
|
AutoUpdate_Mode=1
|
|
|
|
|
Special_Commands="${Special_Commands} [定时更新]"
|
|
|
|
|
;;
|
2021-07-12 15:38:14 +00:00
|
|
|
|
--verbose)
|
2021-07-16 16:14:38 +00:00
|
|
|
|
Special_Commands="${Special_Commands} [详细信息]"
|
2021-07-06 12:32:29 +00:00
|
|
|
|
;;
|
|
|
|
|
*)
|
2021-08-09 16:50:51 +00:00
|
|
|
|
LOGGER "跳过未知参数: [$1] ..."
|
|
|
|
|
shift
|
2021-06-12 10:37:10 +00:00
|
|
|
|
esac
|
|
|
|
|
shift
|
2021-06-06 06:05:58 +00:00
|
|
|
|
done
|
2021-08-09 16:50:51 +00:00
|
|
|
|
LOGGER "固件更新指令: [${Upgrade_Option}]"
|
2021-07-06 12:32:29 +00:00
|
|
|
|
[[ -n "${Special_Commands}" ]] && ECHO g "特殊指令:${Special_Commands} / ${Upgrade_Option}"
|
|
|
|
|
ECHO g "执行: ${MSG}${Special_MSG}"
|
2021-07-30 15:04:23 +00:00
|
|
|
|
if [[ $(CHECK_PKG curl) == true && -z ${Proxy_Type} ]];then
|
2021-06-06 06:05:58 +00:00
|
|
|
|
Google_Check=$(curl -I -s --connect-timeout 3 google.com -w %{http_code} | tail -n1)
|
2021-08-09 16:50:51 +00:00
|
|
|
|
LOGGER "Google 连接检查结果: [${Google_Check}]"
|
2021-06-27 15:46:56 +00:00
|
|
|
|
[[ ${Google_Check} != 301 ]] && {
|
2021-10-03 12:14:53 +00:00
|
|
|
|
ECHO r "Google 连接失败,优先使用镜像加速下载!"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
Proxy_Type="All"
|
2021-05-12 13:15:10 +00:00
|
|
|
|
}
|
|
|
|
|
fi
|
2021-08-10 12:15:15 +00:00
|
|
|
|
ECHO "正在检查版本更新 ..."
|
2021-10-06 04:09:48 +00:00
|
|
|
|
ANALYSIS_API
|
2021-07-21 07:37:29 +00:00
|
|
|
|
CHECK_UPDATES
|
2021-08-10 12:15:15 +00:00
|
|
|
|
CLOUD_FW_Version="$(GET_CLOUD_INFO version)"
|
|
|
|
|
CLOUD_FW_Name="$(GET_CLOUD_INFO name)"
|
|
|
|
|
CLOUD_FW_Size="$(GET_CLOUD_INFO size)"
|
|
|
|
|
CLOUD_FW_Url="$(GET_CLOUD_INFO url)"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ -z ${CLOUD_FW_Name} ]] && {
|
|
|
|
|
ECHO r "云端固件名称获取失败!"
|
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
|
|
|
|
[[ -z ${CLOUD_FW_Version} ]] && {
|
|
|
|
|
ECHO r "云端固件版本获取失败!"
|
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
2021-06-06 06:05:58 +00:00
|
|
|
|
cat <<EOF
|
|
|
|
|
|
2021-07-24 06:37:09 +00:00
|
|
|
|
设备名称: ${TARGET_PROFILE}
|
|
|
|
|
内核版本: $(uname -r)
|
2021-08-09 16:50:51 +00:00
|
|
|
|
$([[ ${TARGET_BOARD} == x86 ]] && echo "固件格式: ${Firmware_Format} / ${x86_Boot}" || echo "固件格式: ${Firmware_Format}")
|
2021-06-06 06:05:58 +00:00
|
|
|
|
|
2021-06-22 14:14:56 +00:00
|
|
|
|
$(echo -e "当前固件版本: ${CURRENT_Version}${CURRENT_Type}")
|
2021-07-21 07:37:29 +00:00
|
|
|
|
$(echo -e "云端固件版本: ${CLOUD_FW_Version}${CHECKED_Type}")
|
2021-06-06 06:05:58 +00:00
|
|
|
|
|
2021-07-21 07:37:29 +00:00
|
|
|
|
云端固件名称: ${CLOUD_FW_Name}
|
2021-08-10 12:15:15 +00:00
|
|
|
|
云端固件体积: ${CLOUD_FW_Size}
|
2021-06-06 06:05:58 +00:00
|
|
|
|
EOF
|
2021-10-03 12:14:53 +00:00
|
|
|
|
LOGGER "当前固件版本: ${CURRENT_Version}"
|
|
|
|
|
LOGGER "云端固件版本: ${CLOUD_FW_Version}"
|
|
|
|
|
LOGGER "云端固件名称: ${CLOUD_FW_Name}"
|
|
|
|
|
LOGGER "云端固件体积: ${CLOUD_FW_Size}"
|
2021-07-21 07:37:29 +00:00
|
|
|
|
GET_FW_LOG -v ${CLOUD_FW_Version}
|
2021-06-22 14:14:56 +00:00
|
|
|
|
case "${Upgrade_Stopped}" in
|
|
|
|
|
1 | 2)
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ ${AutoUpdate_Mode} == 1 ]] && ECHO y "当前固件已是最新版本,无需更新!" && EXIT 0
|
2021-06-22 14:14:56 +00:00
|
|
|
|
[[ ${Upgrade_Stopped} == 1 ]] && MSG="已是最新版本" || MSG="云端固件版本为旧版"
|
2021-06-06 06:05:58 +00:00
|
|
|
|
[[ ! ${Force_Mode} == 1 ]] && {
|
2021-10-06 04:09:48 +00:00
|
|
|
|
LOGGER "当前${MSG}"
|
2021-06-25 13:48:54 +00:00
|
|
|
|
ECHO && read -p "${MSG},是否继续更新固件?[Y/n]:" Choose
|
2021-06-06 06:05:58 +00:00
|
|
|
|
} || Choose=Y
|
2021-10-06 04:09:48 +00:00
|
|
|
|
[[ ! ${Choose} =~ [Yy] ]] && {
|
|
|
|
|
LOGGER "用户已取消固件更新!"
|
|
|
|
|
EXIT 0
|
|
|
|
|
}
|
2021-06-22 14:14:56 +00:00
|
|
|
|
;;
|
|
|
|
|
esac
|
2021-08-09 16:50:51 +00:00
|
|
|
|
local URL
|
2021-08-10 12:15:15 +00:00
|
|
|
|
case "${Proxy_Type}" in
|
2021-08-09 16:50:51 +00:00
|
|
|
|
F | G)
|
2021-08-10 12:15:15 +00:00
|
|
|
|
URL="$(URL_X ${CLOUD_FW_Url} ${Proxy_Type}@@5)"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
;;
|
|
|
|
|
All)
|
2021-08-10 12:15:15 +00:00
|
|
|
|
URL="$(URL_X ${CLOUD_FW_Url} G@@2 F@@2 X@@1)"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
;;
|
|
|
|
|
*)
|
2021-08-10 12:15:15 +00:00
|
|
|
|
URL="$(URL_X ${CLOUD_FW_Url} X@@2 G@@2 F@@1)"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
;;
|
|
|
|
|
esac
|
2021-08-10 12:15:15 +00:00
|
|
|
|
DOWNLOADER --file-name ${CLOUD_FW_Name} --no-url-name --dl ${DOWNLOADERS} --url ${URL} --path ${Firmware_Path} --timeout 5 --type 固件
|
|
|
|
|
[[ ! -s ${Firmware_Path}/${CLOUD_FW_Name} ]] && EXIT 1
|
2021-08-09 16:50:51 +00:00
|
|
|
|
if [[ ! Force_Mode == 1 ]];then
|
2021-08-10 12:15:15 +00:00
|
|
|
|
LOCAL_SHA256=$(GET_SHA256SUM ${Firmware_Path}/${CLOUD_FW_Name} 5)
|
|
|
|
|
CLOUD_SHA256=$(echo ${CLOUD_FW_Name} | egrep -o "[0-9a-z]+.${Firmware_Format}" | sed -r "s/(.*).${Firmware_Format}/\1/")
|
2021-07-21 07:37:29 +00:00
|
|
|
|
[[ ${LOCAL_SHA256} != ${CLOUD_SHA256} ]] && {
|
2021-08-09 16:50:51 +00:00
|
|
|
|
ECHO r "SHA256 校验失败,请检查网络后重试!"
|
|
|
|
|
REMOVE_CACHE
|
2021-07-01 14:39:50 +00:00
|
|
|
|
EXIT 1
|
2021-08-09 16:50:51 +00:00
|
|
|
|
}
|
|
|
|
|
LOGGER "固件 SHA256 比对通过!"
|
2021-07-01 14:39:50 +00:00
|
|
|
|
fi
|
2021-08-09 16:50:51 +00:00
|
|
|
|
case "${Firmware_Format}" in
|
2021-06-06 06:05:58 +00:00
|
|
|
|
img.gz)
|
2021-08-09 16:50:51 +00:00
|
|
|
|
if [[ ${Decompress_Mode} == 1 ]];then
|
|
|
|
|
ECHO "正在解压 [${Firmware_Format}] 固件 ..."
|
2021-08-10 12:15:15 +00:00
|
|
|
|
gzip -d -q -f -c ${Firmware_Path}/${CLOUD_FW_Name} > ${Firmware_Path}/$(echo ${CLOUD_FW_Name} | sed -r 's/(.*).gz/\1/')
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ ! $? == 0 ]] && {
|
|
|
|
|
ECHO r "固件解压失败!"
|
|
|
|
|
EXIT 1
|
|
|
|
|
} || {
|
2021-08-10 12:15:15 +00:00
|
|
|
|
CLOUD_FW_Name="$(echo ${CLOUD_FW_Name} | sed -r 's/(.*).gz/\1/')"
|
|
|
|
|
LOGGER "固件解压成功,固件已解压到: [${Firmware_Path}/${CLOUD_FW_Name}]"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2021-10-03 12:14:53 +00:00
|
|
|
|
[[ $(CHECK_PKG gzip) == true ]] && {
|
|
|
|
|
LOGGER "卸载软件包 [gzip] ..."
|
|
|
|
|
opkg remove gzip > /dev/null 2>&1
|
|
|
|
|
}
|
2021-08-09 16:50:51 +00:00
|
|
|
|
fi
|
2021-06-06 06:05:58 +00:00
|
|
|
|
;;
|
|
|
|
|
esac
|
2021-06-27 15:46:56 +00:00
|
|
|
|
[[ ${Test_Mode} != 1 ]] && {
|
2021-08-10 12:15:15 +00:00
|
|
|
|
DO_UPGRADE ${Upgrade_Option} ${Firmware_Path}/${CLOUD_FW_Name}
|
2021-04-30 14:20:27 +00:00
|
|
|
|
} || {
|
2021-08-10 12:15:15 +00:00
|
|
|
|
ECHO x "[测试模式] ${Upgrade_Option} ${Firmware_Path}/${CLOUD_FW_Name}"
|
2021-06-13 09:46:34 +00:00
|
|
|
|
EXIT 0
|
2021-04-30 14:20:27 +00:00
|
|
|
|
}
|
2021-05-16 12:58:30 +00:00
|
|
|
|
}
|
2021-06-06 06:05:58 +00:00
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function DOWNLOADER() {
|
|
|
|
|
local DL_Downloader DL_Name DL_URL DL_Path DL_Retries DL_Timeout DL_Type DL_Final Quiet_Mode No_URL_Name Print_Mode DL_Retires_All DL_URL_Final
|
|
|
|
|
while [[ $1 ]];do
|
2021-08-10 12:15:15 +00:00
|
|
|
|
case "$1" in
|
2021-08-09 16:50:51 +00:00
|
|
|
|
--dl)
|
|
|
|
|
shift
|
|
|
|
|
while [[ $1 ]];do
|
|
|
|
|
case "$1" in
|
|
|
|
|
wget-ssl | curl | wget | uclient-fetch)
|
|
|
|
|
[[ $(CHECK_PKG $1) == true ]] && {
|
|
|
|
|
DL_Downloader="$1"
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
*)
|
2021-10-06 04:09:48 +00:00
|
|
|
|
LOGGER "[DOWNLOADER] 跳过未知下载器: [$1] ..."
|
2021-08-09 16:50:51 +00:00
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
while [[ $1 ]];do
|
|
|
|
|
[[ $1 =~ '--' ]] && break
|
|
|
|
|
[[ ! $1 =~ '--' ]] && shift
|
|
|
|
|
done
|
|
|
|
|
[[ -z ${DL_Downloader} ]] && {
|
2021-10-03 12:14:53 +00:00
|
|
|
|
ECHO r "没有可用的下载器!"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
|
|
|
|
;;
|
|
|
|
|
--file-name)
|
|
|
|
|
shift
|
|
|
|
|
DL_Name="$1"
|
|
|
|
|
while [[ $1 ]];do
|
|
|
|
|
[[ $1 =~ '--' ]] && break
|
|
|
|
|
[[ ! $1 =~ '--' ]] && shift
|
|
|
|
|
done
|
|
|
|
|
;;
|
|
|
|
|
--url)
|
|
|
|
|
shift
|
|
|
|
|
DL_URL=($(echo $@ | egrep -o "https://.*@@[0-9]+|https://.*@@[0-9]+|ftp://.*@@[0-9]+"))
|
2021-08-10 04:35:48 +00:00
|
|
|
|
[[ -z ${DL_URL[*]} ]] && {
|
|
|
|
|
DL_URL=($1)
|
|
|
|
|
DL_URL_Count="${#DL_URL[@]}"
|
|
|
|
|
DL_Retires_All="${DL_URL_Count}"
|
|
|
|
|
} || {
|
|
|
|
|
DL_Retires_All="$(echo ${DL_URL[*]} | egrep -o "@@[0-9]+" | egrep -o "[0-9]+" | awk '{Sum += $1};END {print Sum}')"
|
|
|
|
|
DL_URL_Count="${#DL_URL[@]}"
|
|
|
|
|
}
|
2021-10-06 04:09:48 +00:00
|
|
|
|
LOGGER "[DOWNLOADER] URL 数量: [${DL_URL_Count}] 总重试次数: [${DL_Retires_All}]"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
while [[ $1 ]];do
|
|
|
|
|
[[ $1 =~ '--' ]] && break
|
|
|
|
|
[[ ! $1 =~ '--' ]] && shift
|
|
|
|
|
done
|
|
|
|
|
;;
|
|
|
|
|
--no-url-name)
|
|
|
|
|
shift
|
2021-10-06 04:09:48 +00:00
|
|
|
|
LOGGER "[DOWNLOADER] Enabled No-Url-Filename Mode"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
No_URL_Name=1
|
|
|
|
|
;;
|
|
|
|
|
--path)
|
|
|
|
|
shift
|
|
|
|
|
DL_Path="$1"
|
|
|
|
|
if [[ ! -d ${DL_Path} ]];then
|
|
|
|
|
mkdir -p ${DL_Path} 2> /dev/null || {
|
2021-10-05 15:24:22 +00:00
|
|
|
|
ECHO r "目标下载路径 [${DL_Path}] 创建失败!"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
fi
|
|
|
|
|
while [[ $1 ]];do
|
|
|
|
|
[[ $1 =~ '--' ]] && break
|
|
|
|
|
[[ ! $1 =~ '--' ]] && shift
|
|
|
|
|
done
|
|
|
|
|
;;
|
|
|
|
|
--timeout)
|
|
|
|
|
shift
|
|
|
|
|
[[ ! $1 =~ [1-9] ]] && {
|
2021-10-06 04:09:48 +00:00
|
|
|
|
LOGGER "[DOWNLOADER] 参数: [$1] 不是正确的数字!"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
shift
|
|
|
|
|
} || {
|
|
|
|
|
DL_Timeout="$1"
|
|
|
|
|
while [[ $1 ]];do
|
|
|
|
|
[[ $1 =~ '--' ]] && break
|
|
|
|
|
[[ ! $1 =~ '--' ]] && shift
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
;;
|
|
|
|
|
--type)
|
|
|
|
|
shift
|
|
|
|
|
DL_Type="$1"
|
|
|
|
|
while [[ $1 ]];do
|
|
|
|
|
[[ $1 =~ '--' ]] && break
|
|
|
|
|
[[ ! $1 =~ '--' ]] && shift
|
|
|
|
|
done
|
|
|
|
|
;;
|
|
|
|
|
--quiet)
|
|
|
|
|
shift
|
|
|
|
|
Quiet_Mode=quiet
|
|
|
|
|
;;
|
|
|
|
|
--print)
|
|
|
|
|
shift
|
|
|
|
|
Print_Mode=1
|
|
|
|
|
Quiet_Mode=quiet
|
|
|
|
|
;;
|
|
|
|
|
*)
|
2021-10-06 04:09:48 +00:00
|
|
|
|
LOGGER "[DOWNLOADER] 跳过未知参数: [$1] ..."
|
2021-08-09 16:50:51 +00:00
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
2021-08-10 12:15:15 +00:00
|
|
|
|
case "${DL_Downloader}" in
|
2021-08-09 16:50:51 +00:00
|
|
|
|
wget | wget-ssl)
|
|
|
|
|
DL_Template="wget-ssl --quiet --no-check-certificate --no-dns-cache -x -4 --tries 1 --timeout 5 -O"
|
|
|
|
|
;;
|
|
|
|
|
curl)
|
|
|
|
|
DL_Template="curl --silent --insecure -L -k --connect-timeout 5 --retry 1 -o"
|
|
|
|
|
;;
|
|
|
|
|
uclient-fetch)
|
|
|
|
|
DL_Template="uclient-fetch --quiet --no-check-certificate -4 --timeout 5 -O"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
[[ ${Test_Mode} == 1 || ${Verbose_Mode} == 1 ]] && {
|
|
|
|
|
DL_Template="${DL_Template/ --quiet / }"
|
|
|
|
|
DL_Template="${DL_Template/ --silent / }"
|
|
|
|
|
}
|
|
|
|
|
[[ -n ${DL_Timeout} ]] && DL_Template="${DL_Template/-timeout 5/-timeout ${DL_Timeout}}"
|
|
|
|
|
local E=0 u;while [[ ${E} != ${DL_URL_Count} ]];do
|
|
|
|
|
DL_URL_Cache="${DL_URL[$E]}"
|
|
|
|
|
DL_Retries="${DL_URL_Cache##*@@}"
|
2021-08-10 04:35:48 +00:00
|
|
|
|
[[ -z ${DL_Retries} || ! ${DL_Retries} == [0-9] ]] && DL_Retries=1
|
2021-08-09 16:50:51 +00:00
|
|
|
|
DL_URL_Final="${DL_URL_Cache%*@@*}"
|
2021-10-06 04:09:48 +00:00
|
|
|
|
LOGGER "[DOWNLOADER] 当前 URL: [${DL_URL_Final}] URL 重试次数: [${DL_Retries}]"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
for u in $(seq ${DL_Retries});do
|
|
|
|
|
sleep 1
|
|
|
|
|
[[ -z ${Failed} ]] && {
|
|
|
|
|
ECHO ${Quiet_Mode} "正在下载${DL_Type},请耐心等待 ..."
|
|
|
|
|
} || {
|
|
|
|
|
ECHO ${Quiet_Mode} "尝试重新下载${DL_Type},剩余重试次数: [${DL_Retires_All}]"
|
|
|
|
|
}
|
|
|
|
|
if [[ -z ${DL_Name} ]];then
|
|
|
|
|
DL_Name="${DL_URL_Final##*/}"
|
|
|
|
|
DL_Final="${DL_Template} ${DL_Path}/${DL_Name} ${DL_URL_Final}"
|
|
|
|
|
else
|
|
|
|
|
[[ ${No_URL_Name} == 1 ]] && {
|
|
|
|
|
DL_Final="${DL_Template} ${DL_Path}/${DL_Name} ${DL_URL_Final}"
|
|
|
|
|
} || DL_Final="${DL_Template} ${DL_Path}/${DL_Name} ${DL_URL_Final}/${DL_Name}"
|
|
|
|
|
fi
|
|
|
|
|
[[ -f ${DL_Path}/${DL_Name} ]] && {
|
2021-08-10 12:15:15 +00:00
|
|
|
|
RM ${DL_Path}/${DL_Name}
|
2021-08-09 16:50:51 +00:00
|
|
|
|
}
|
2021-10-06 04:09:48 +00:00
|
|
|
|
LOGGER "[DOWNLOADER] 执行下载: [${DL_Final}]"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
${DL_Final}
|
|
|
|
|
if [[ $? == 0 && -s ${DL_Path}/${DL_Name} ]];then
|
|
|
|
|
ECHO y ${Quiet_Mode} "${DL_Type}下载成功!"
|
|
|
|
|
[[ ${Print_Mode} == 1 ]] && {
|
|
|
|
|
cat ${DL_Path}/${DL_Name} 2> /dev/null
|
2021-08-10 12:15:15 +00:00
|
|
|
|
RM ${DL_Path}/${DL_Name}
|
2021-08-09 16:50:51 +00:00
|
|
|
|
}
|
|
|
|
|
touch -a ${DL_Path}/${DL_Name} 2> /dev/null
|
|
|
|
|
return 0
|
|
|
|
|
else
|
|
|
|
|
[[ -z ${Failed} ]] && local Failed=1
|
|
|
|
|
DL_Retires_All=$((${DL_Retires_All} - 1))
|
|
|
|
|
if [[ ${u} == ${DL_Retries} ]];then
|
|
|
|
|
break 1
|
|
|
|
|
else
|
|
|
|
|
ECHO r ${Quiet_Mode} "下载失败!"
|
|
|
|
|
u=$((${u} + 1))
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
E=$((${E} + 1))
|
|
|
|
|
done
|
2021-08-10 12:15:15 +00:00
|
|
|
|
RM ${DL_Path}/${DL_Name}
|
2021-08-09 16:50:51 +00:00
|
|
|
|
ECHO r ${Quiet_Mode} "${DL_Type}下载失败,请检查网络后重试!"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function DO_UPGRADE() {
|
|
|
|
|
ECHO r "警告: 固件更新期间请不要断开电源或尝试重启设备!"
|
2021-07-24 06:37:09 +00:00
|
|
|
|
sleep 3
|
2021-07-07 19:48:51 +00:00
|
|
|
|
ECHO g "正在更新固件,请耐心等待 ..."
|
2021-06-06 06:05:58 +00:00
|
|
|
|
$*
|
|
|
|
|
[[ $? -ne 0 ]] && {
|
2021-08-09 16:50:51 +00:00
|
|
|
|
ECHO r "固件刷写失败,请尝试使用 autoupdate -F 指令再次更新固件!"
|
|
|
|
|
ECHO r "脚本与固件更新问题请前往 [${Github}] 进行反馈, 请附上 AutoUpdate 运行日志与系统信息"
|
2021-06-13 09:46:34 +00:00
|
|
|
|
EXIT 1
|
|
|
|
|
} || EXIT 0
|
2021-05-13 10:40:16 +00:00
|
|
|
|
}
|
2021-06-06 06:05:58 +00:00
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
function REMOVE_CACHE() {
|
|
|
|
|
rm -rf ${Running_Path}/API \
|
|
|
|
|
${Running_Path}/Update_Logs \
|
2021-08-10 12:15:15 +00:00
|
|
|
|
${Running_Path}/API_Dump 2> /dev/null
|
2021-10-06 04:09:48 +00:00
|
|
|
|
LOGGER "[REMOVE_CACHE] AutoUpdate 缓存清理完成!"
|
2021-06-06 06:05:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-10 04:35:48 +00:00
|
|
|
|
function LOG() {
|
2021-06-23 11:01:05 +00:00
|
|
|
|
[[ -z $1 ]] && {
|
2021-07-21 07:37:29 +00:00
|
|
|
|
[[ -s ${Log_Path}/AutoUpdate.log ]] && {
|
2021-06-23 11:01:05 +00:00
|
|
|
|
TITLE && echo
|
2021-07-21 07:37:29 +00:00
|
|
|
|
cat ${Log_Path}/AutoUpdate.log
|
2021-08-10 04:35:48 +00:00
|
|
|
|
EXIT 0
|
2021-06-23 11:01:05 +00:00
|
|
|
|
}
|
|
|
|
|
} || {
|
|
|
|
|
while [[ $1 ]];do
|
2021-07-16 16:14:38 +00:00
|
|
|
|
case "$1" in
|
2021-08-09 16:50:51 +00:00
|
|
|
|
--path)
|
|
|
|
|
[[ $2 == ${Log_Path} ]] && {
|
2021-07-13 05:24:30 +00:00
|
|
|
|
ECHO y "AutoUpdate 日志保存路径相同,无需修改!"
|
|
|
|
|
EXIT 0
|
|
|
|
|
}
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ -f $2 ]] && {
|
2021-07-13 05:24:30 +00:00
|
|
|
|
ECHO r "AutoUpdate 日志保存路径有误,请重新输入!"
|
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
2021-07-21 07:37:29 +00:00
|
|
|
|
EDIT_VARIABLE rm ${Custom_Variable} Log_Path
|
2021-08-09 16:50:51 +00:00
|
|
|
|
EDIT_VARIABLE edit ${Custom_Variable} Log_Path $2
|
|
|
|
|
[[ ! -d $2 ]] && mkdir -p $2
|
|
|
|
|
[[ -f $2/AutoUpdate.log ]] && mv ${Log_Path}/AutoUpdate.log $2
|
|
|
|
|
Log_Path="$2"
|
|
|
|
|
ECHO y "AutoUpdate 日志保存路径已修改为: [$2]!"
|
|
|
|
|
;;
|
|
|
|
|
del | rm | clean)
|
2021-08-10 12:15:15 +00:00
|
|
|
|
RM ${Log_Path}/AutoUpdate.log
|
2021-08-09 16:50:51 +00:00
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
SHELL_HELP
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2021-06-25 13:48:54 +00:00
|
|
|
|
EXIT 0
|
2021-06-23 11:01:05 +00:00
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-08 06:22:26 +00:00
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
URL_X() {
|
|
|
|
|
#URL_X https://raw.githubusercontent.com/Hyy2001X/AutoBuild-Actions/master/Scripts/AutoUpdate.sh F@@1 G@@1 X@@1
|
|
|
|
|
local URL=$1 Type URL_Final
|
|
|
|
|
[[ ${URL} =~ raw.githubusercontent.com ]] && Type=raw
|
|
|
|
|
[[ ${URL} =~ releases/download ]] && Type=release
|
|
|
|
|
[[ ${URL} =~ codeload.github.com ]] && Type=codeload
|
2021-07-19 12:21:58 +00:00
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
case "${Type}" in
|
|
|
|
|
raw)
|
|
|
|
|
FastGit=https://raw.fastgit.org/$(echo ${URL##*com/})
|
|
|
|
|
Ghproxy=https://ghproxy.com/${URL}
|
2021-07-21 07:37:29 +00:00
|
|
|
|
;;
|
2021-08-09 16:50:51 +00:00
|
|
|
|
release)
|
|
|
|
|
FastGit=https://download.fastgit.org/$(echo ${URL##*com/})
|
|
|
|
|
Ghproxy=https://ghproxy.com/${URL}
|
2021-07-21 07:37:29 +00:00
|
|
|
|
;;
|
2021-08-09 16:50:51 +00:00
|
|
|
|
codeload)
|
|
|
|
|
FastGit=https://download.fastgit.org/$(echo ${URL##*com/})
|
|
|
|
|
Ghproxy=https://ghproxy.com/${URL}
|
2021-07-21 07:37:29 +00:00
|
|
|
|
;;
|
2021-08-09 16:50:51 +00:00
|
|
|
|
esac
|
|
|
|
|
while [[ $1 ]];do
|
|
|
|
|
local URL_Cache=$1 URL_Final
|
2021-08-10 12:15:15 +00:00
|
|
|
|
case "$1" in
|
2021-08-09 16:50:51 +00:00
|
|
|
|
F@@*)
|
|
|
|
|
URL_Final="${URL_Cache/F/${FastGit}}"
|
2021-07-04 04:39:16 +00:00
|
|
|
|
;;
|
2021-08-09 16:50:51 +00:00
|
|
|
|
G@@*)
|
|
|
|
|
URL_Final="${URL_Cache/G/${Ghproxy}}"
|
|
|
|
|
;;
|
|
|
|
|
X@@*)
|
|
|
|
|
URL_Final="${URL_Cache/X/${URL}}"
|
2021-07-06 12:32:29 +00:00
|
|
|
|
;;
|
2021-07-21 07:37:29 +00:00
|
|
|
|
esac
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ -n ${URL_Final} ]] && {
|
|
|
|
|
echo "${URL_Final}"
|
|
|
|
|
LOGGER "[URL_X] ${URL_Final}"
|
|
|
|
|
}
|
|
|
|
|
unset URL_Final
|
2021-07-21 07:37:29 +00:00
|
|
|
|
shift
|
2021-08-09 16:50:51 +00:00
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function NETWORK_CHECK() {
|
|
|
|
|
ping $1 -c 1 -W $2 > /dev/null 2>&1
|
2021-08-10 12:15:15 +00:00
|
|
|
|
[[ $? == 0 ]] && echo true || echo false
|
2021-08-09 16:50:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function AutoUpdate_Main() {
|
2021-08-10 16:48:03 +00:00
|
|
|
|
LOGGER "[${COMMAND}] 开始运行"
|
2021-08-10 04:35:48 +00:00
|
|
|
|
if [[ ! $1 =~ (-H|--help) ]];then
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ ! -f ${Default_Variable} ]] && {
|
|
|
|
|
ECHO r "脚本运行环境检测失败,无法正常运行脚本!"
|
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
|
|
|
|
[[ ! -f ${Custom_Variable} ]] && touch ${Custom_Variable}
|
|
|
|
|
LOAD_VARIABLE ${Default_Variable} ${Custom_Variable}
|
|
|
|
|
[[ ! -d ${Running_Path} ]] && {
|
|
|
|
|
mkdir -p ${Running_Path}
|
|
|
|
|
[[ ! $? == 0 ]] && {
|
2021-10-03 12:14:53 +00:00
|
|
|
|
ECHO r "脚本运行路径 [${Running_Path}] 创建失败!"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
[[ -z $* ]] && UPGRADE $*
|
|
|
|
|
|
|
|
|
|
local Input=($@) E=0 F Custom_Path Custom_URL
|
|
|
|
|
while :;do
|
|
|
|
|
F="${Input[${E}]}"
|
|
|
|
|
case "${F}" in
|
|
|
|
|
-T)
|
|
|
|
|
Test_Mode=1
|
2021-06-13 07:27:14 +00:00
|
|
|
|
;;
|
2021-08-09 16:50:51 +00:00
|
|
|
|
--verbose)
|
|
|
|
|
Verbose_Mode=1
|
|
|
|
|
;;
|
|
|
|
|
--path)
|
|
|
|
|
Custom_Path="${Input[$((${E} + 1))]}"
|
|
|
|
|
[[ -z ${Custom_Path} ]] && {
|
|
|
|
|
ECHO r "请输入正确的路径!"
|
|
|
|
|
}
|
|
|
|
|
;;
|
|
|
|
|
--url)
|
|
|
|
|
Custom_URL="${Input[$((${E} + 1))]}"
|
2021-08-10 04:35:48 +00:00
|
|
|
|
[[ -z ${Custom_URL} || ! ${Custom_URL} =~ (https://*|http://*|ftp://*) ]] && {
|
|
|
|
|
ECHO r "链接格式错误,请输入正确的链接!"
|
|
|
|
|
EXIT 1
|
2021-08-09 16:50:51 +00:00
|
|
|
|
}
|
|
|
|
|
;;
|
|
|
|
|
-D)
|
2021-08-10 12:15:15 +00:00
|
|
|
|
case "${Input[$((${E} + 1))]}" in
|
2021-08-09 16:50:51 +00:00
|
|
|
|
wget | curl | wget-ssl | uclient-fetch)
|
|
|
|
|
DOWNLOADERS=${Input[$((${E} + 1))]}
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
ECHO r "暂不支持当前下载器: [${Input[$((${E} + 1))]}]"
|
|
|
|
|
EXIT 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2021-06-28 03:13:30 +00:00
|
|
|
|
;;
|
2021-07-21 07:37:29 +00:00
|
|
|
|
esac
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ ${E} == ${#Input[@]} ]] && break
|
|
|
|
|
E=$((${E} + 1))
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
while [[ $1 ]];do
|
2021-07-21 07:37:29 +00:00
|
|
|
|
case "$1" in
|
2021-08-09 16:50:51 +00:00
|
|
|
|
-n | -f | -u | -T | -P | --proxy | -F | --force-write | --verbose | --decompress | --skip-verify | -D | --path)
|
|
|
|
|
UPGRADE $*
|
|
|
|
|
EXIT 2
|
2021-06-13 09:46:34 +00:00
|
|
|
|
;;
|
2021-08-09 16:50:51 +00:00
|
|
|
|
--backup)
|
|
|
|
|
local FILE="backup-$(uname -n)-$(date +%Y-%m-%d)-$(RANDOM 5).tar.gz"
|
|
|
|
|
shift
|
|
|
|
|
[[ $# -gt 1 ]] && SHELL_HELP
|
|
|
|
|
[[ -z $1 ]] && {
|
|
|
|
|
FILE=$(pwd)/${FILE}
|
2021-07-21 07:37:29 +00:00
|
|
|
|
} || {
|
2021-08-09 16:50:51 +00:00
|
|
|
|
if [[ ! -d $1 ]];then
|
|
|
|
|
mkdir -p $1 || {
|
2021-10-03 12:14:53 +00:00
|
|
|
|
ECHO r "备份存放路径 [$1] 创建失败!"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
|
|
|
|
fi
|
|
|
|
|
FILE=$1/${FILE}
|
|
|
|
|
}
|
|
|
|
|
ECHO "正在备份系统文件到 [${FILE}] ..."
|
|
|
|
|
sysupgrade -b "${FILE}" > /dev/null 2>&1
|
|
|
|
|
[[ $? == 0 ]] && {
|
|
|
|
|
ECHO y "备份文件创建成功!"
|
|
|
|
|
EXIT 0
|
|
|
|
|
} || {
|
|
|
|
|
ECHO r "备份文件 [${FILE}] 创建失败!"
|
|
|
|
|
EXIT 1
|
2021-07-06 12:32:29 +00:00
|
|
|
|
}
|
2021-06-13 09:46:34 +00:00
|
|
|
|
;;
|
2021-08-09 16:50:51 +00:00
|
|
|
|
--clean)
|
|
|
|
|
shift && [[ -n $* ]] && SHELL_HELP
|
|
|
|
|
REMOVE_CACHE
|
2021-07-06 12:32:29 +00:00
|
|
|
|
EXIT 0
|
2021-06-13 09:46:34 +00:00
|
|
|
|
;;
|
2021-08-09 16:50:51 +00:00
|
|
|
|
--check)
|
|
|
|
|
shift && [[ -n $* ]] && SHELL_HELP
|
2021-08-10 12:15:15 +00:00
|
|
|
|
CHECK_DEPENDS bash uclient-fetch curl wget openssl jsonfilter
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ $(NETWORK_CHECK 223.5.5.5 2) == false ]] && {
|
|
|
|
|
ECHO r "网络连接错误!"
|
|
|
|
|
} || ECHO y "网络连接正常!"
|
|
|
|
|
CHECK_ENV ${ENV_DEPENDS}
|
2021-07-21 07:37:29 +00:00
|
|
|
|
EXIT 0
|
2021-08-09 16:50:51 +00:00
|
|
|
|
;;
|
|
|
|
|
--env-list)
|
|
|
|
|
shift
|
|
|
|
|
[[ -z $* ]] && LIST_ENV 0 && EXIT 0
|
2021-07-16 16:14:38 +00:00
|
|
|
|
case "$1" in
|
2021-08-09 16:50:51 +00:00
|
|
|
|
1 | 2)
|
|
|
|
|
LIST_ENV $1
|
2021-06-22 14:14:56 +00:00
|
|
|
|
;;
|
2021-08-09 16:50:51 +00:00
|
|
|
|
*)
|
|
|
|
|
SHELL_HELP
|
2021-06-22 14:14:56 +00:00
|
|
|
|
;;
|
2021-08-09 16:50:51 +00:00
|
|
|
|
esac
|
|
|
|
|
EXIT 2
|
|
|
|
|
;;
|
|
|
|
|
-V)
|
|
|
|
|
shift
|
|
|
|
|
[[ -z $* ]] && echo "${CURRENT_Version}" && EXIT 1
|
|
|
|
|
case "$1" in
|
|
|
|
|
[Cc]loud)
|
2021-08-10 04:35:48 +00:00
|
|
|
|
shift
|
2021-10-06 04:09:48 +00:00
|
|
|
|
ANALYSIS_API
|
2021-08-10 12:15:15 +00:00
|
|
|
|
GET_CLOUD_INFO $* version
|
2021-07-24 06:37:09 +00:00
|
|
|
|
;;
|
2021-07-21 07:37:29 +00:00
|
|
|
|
*)
|
|
|
|
|
SHELL_HELP
|
2021-07-06 12:32:29 +00:00
|
|
|
|
;;
|
|
|
|
|
esac
|
2021-08-09 16:50:51 +00:00
|
|
|
|
EXIT 2
|
|
|
|
|
;;
|
|
|
|
|
--fw-log)
|
2021-06-13 09:46:34 +00:00
|
|
|
|
shift
|
2021-10-06 04:09:48 +00:00
|
|
|
|
ANALYSIS_API
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ -z $* ]] && GET_FW_LOG local
|
|
|
|
|
case "$1" in
|
|
|
|
|
[Cc]loud)
|
|
|
|
|
GET_FW_LOG $1
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
[[ -z $* ]] && EXIT 0
|
|
|
|
|
[[ ! $(FW_VERSION_CHECK $1) == true ]] && {
|
|
|
|
|
ECHO r "固件版本号合法性检查失败!"
|
|
|
|
|
EXIT 1
|
|
|
|
|
} || {
|
|
|
|
|
GET_FW_LOG -v $1
|
|
|
|
|
}
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
EXIT 2
|
|
|
|
|
;;
|
|
|
|
|
--list)
|
|
|
|
|
shift
|
|
|
|
|
SHOW_VARIABLE
|
|
|
|
|
EXIT 0
|
|
|
|
|
;;
|
|
|
|
|
--var)
|
|
|
|
|
local Result
|
|
|
|
|
shift
|
|
|
|
|
[[ $# != 1 ]] && SHELL_HELP
|
|
|
|
|
Result=$(GET_VARIABLE "$1" ${Custom_Variable})
|
|
|
|
|
[[ -z ${Result} ]] && Result=$(GET_VARIABLE "$1" ${Default_Variable})
|
|
|
|
|
[[ -n ${Result} ]] && echo "${Result}"
|
|
|
|
|
EXIT 2
|
|
|
|
|
;;
|
|
|
|
|
-v)
|
|
|
|
|
shift
|
|
|
|
|
[[ -z $* ]] && echo ${Version} && EXIT 0
|
|
|
|
|
case "$1" in
|
|
|
|
|
[Cc]loud)
|
2021-08-10 04:35:48 +00:00
|
|
|
|
Script_URL="$(URL_X ${Github_Raw}/Scripts/AutoUpdate.sh G@@1)"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
DOWNLOADER --dl ${DOWNLOADERS} --url ${Script_URL} --path /tmp --print | egrep -o "V[0-9].+"
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
SHELL_HELP
|
|
|
|
|
esac
|
|
|
|
|
EXIT 2
|
|
|
|
|
;;
|
|
|
|
|
-x)
|
|
|
|
|
shift
|
2021-08-10 04:35:48 +00:00
|
|
|
|
Script_URL="$(URL_X ${Github_Raw}/Scripts/AutoUpdate.sh G@@1 F@@1 X@@1)"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ $(NETWORK_CHECK 223.5.5.5 2) == false ]] && {
|
|
|
|
|
ECHO r "网络连接错误,请稍后再试!"
|
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
|
|
|
|
Script_Path=/bin
|
|
|
|
|
[[ -n ${Custom_Path} ]] && Script_Path=${Custom_Path}
|
|
|
|
|
[[ -n ${Custom_URL} ]] && Script_URL=${Custom_URL}
|
|
|
|
|
UPDATE_SCRIPT ${Script_Path} ${Script_URL}
|
|
|
|
|
EXIT 2
|
|
|
|
|
;;
|
|
|
|
|
-B | --boot-mode)
|
|
|
|
|
shift
|
|
|
|
|
[[ ${TARGET_BOARD} != x86 ]] && EXIT 1
|
|
|
|
|
CHANGE_BOOT $1
|
|
|
|
|
EXIT 2
|
|
|
|
|
;;
|
|
|
|
|
-C)
|
|
|
|
|
shift
|
|
|
|
|
CHANGE_GITHUB $1
|
|
|
|
|
EXIT 2
|
|
|
|
|
;;
|
|
|
|
|
-H | --help)
|
|
|
|
|
SHELL_HELP
|
|
|
|
|
EXIT 2
|
|
|
|
|
;;
|
|
|
|
|
-L | --log)
|
|
|
|
|
shift
|
2021-08-10 04:35:48 +00:00
|
|
|
|
LOG $*
|
2021-08-10 12:15:15 +00:00
|
|
|
|
EXIT 2
|
|
|
|
|
;;
|
|
|
|
|
-O)
|
2021-10-06 04:09:48 +00:00
|
|
|
|
ANALYSIS_API
|
2021-08-10 12:15:15 +00:00
|
|
|
|
GET_CLOUD_INFO -a name
|
|
|
|
|
EXIT 0
|
2021-08-09 16:50:51 +00:00
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
SHELL_HELP
|
2021-08-10 12:15:15 +00:00
|
|
|
|
EXIT 1
|
2021-08-09 16:50:51 +00:00
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
2021-06-13 09:46:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-02 16:38:26 +00:00
|
|
|
|
KILL_OTHER() {
|
|
|
|
|
local i;for i in $(ps | grep -v grep | grep $1 | grep -v $$ | awk '{print $1}');do
|
|
|
|
|
kill -9 ${i} 2> /dev/null
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KILL_OTHER AutoUpdate.sh
|
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
Running_Path=/tmp/AutoUpdate
|
2021-07-21 07:37:29 +00:00
|
|
|
|
Log_Path=/tmp
|
2021-08-10 12:15:15 +00:00
|
|
|
|
API_File=${Running_Path}/API
|
2021-06-23 05:55:52 +00:00
|
|
|
|
Default_Variable=/etc/AutoBuild/Default_Variable
|
|
|
|
|
Custom_Variable=/etc/AutoBuild/Custom_Variable
|
2021-08-10 12:15:15 +00:00
|
|
|
|
ENV_DEPENDS="Author Github TARGET_PROFILE TARGET_BOARD TARGET_SUBTARGET Firmware_Format CURRENT_Version OP_Maintainer OP_BRANCH OP_REPO_NAME"
|
2021-08-09 16:50:51 +00:00
|
|
|
|
DOWNLOADERS="wget-ssl curl wget uclient-fetch"
|
2021-06-23 05:55:52 +00:00
|
|
|
|
|
|
|
|
|
White="\e[0m"
|
|
|
|
|
Yellow="\e[33m"
|
|
|
|
|
Red="\e[31m"
|
|
|
|
|
Blue="\e[34m"
|
|
|
|
|
Grey="\e[36m"
|
|
|
|
|
Green="\e[32m"
|
2021-06-22 14:14:56 +00:00
|
|
|
|
|
2021-08-09 16:50:51 +00:00
|
|
|
|
[[ -n $* ]] && COMMAND="$0 $*" || COMMAND="$0"
|
2021-06-23 02:36:03 +00:00
|
|
|
|
AutoUpdate_Main $*
|