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-06-06 06:05:58 +00:00
|
|
|
# Depends on bash wget curl x86:gzip
|
2020-09-19 07:37:55 +00:00
|
|
|
|
2021-06-06 06:05:58 +00:00
|
|
|
TITLE() {
|
|
|
|
clear && echo "Openwrt-AutoUpdate Script by Hyy2001 ${Version}"
|
|
|
|
}
|
2020-09-23 09:43:46 +00:00
|
|
|
|
2021-06-06 06:05:58 +00:00
|
|
|
SHELL_HELP() {
|
2021-06-08 06:22:26 +00:00
|
|
|
case $1 in
|
|
|
|
1)
|
|
|
|
TITLE
|
|
|
|
shift
|
|
|
|
TIME r "错误的输入: [$0 $*]"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
TITLE
|
|
|
|
;;
|
|
|
|
esac
|
2021-06-06 06:05:58 +00:00
|
|
|
cat <<EOF
|
2021-04-29 12:35:12 +00:00
|
|
|
|
2021-06-07 08:27:27 +00:00
|
|
|
使用方法: $0 [<path=>] [-P] [-n] [-f] [-u]
|
2021-06-06 06:05:58 +00:00
|
|
|
$0 [<更新脚本>] [-x/-x <path=>/-x <url=>]
|
2021-04-29 12:35:12 +00:00
|
|
|
|
2021-06-06 06:05:58 +00:00
|
|
|
更新固件:
|
2021-05-01 06:27:02 +00:00
|
|
|
-n 更新固件 [不保留配置]
|
2021-06-12 10:37:10 +00:00
|
|
|
-f 跳过版本号验证,并强制刷写固件 [保留配置]
|
2021-05-01 06:27:02 +00:00
|
|
|
-u 适用于定时更新 LUCI 的参数 [保留配置]
|
2021-06-12 10:37:10 +00:00
|
|
|
-? <path=> 更新固件 (保存固件到用户指定的目录)
|
2021-04-29 12:35:12 +00:00
|
|
|
|
2021-05-16 12:58:30 +00:00
|
|
|
更新脚本:
|
2021-05-06 13:12:01 +00:00
|
|
|
-x 更新 AutoUpdate.sh 脚本
|
2021-06-07 08:27:27 +00:00
|
|
|
-x <path=> 更新 AutoUpdate.sh 脚本 (保存脚本到用户指定的目录)
|
2021-06-06 06:05:58 +00:00
|
|
|
-x <url=> 更新 AutoUpdate.sh 脚本 (使用用户提供的脚本地址更新)
|
2021-05-06 13:12:01 +00:00
|
|
|
|
2021-06-06 06:05:58 +00:00
|
|
|
其他参数:
|
2021-06-12 10:37:10 +00:00
|
|
|
-F,--force 强制刷写固件 (可附加)
|
|
|
|
-T,--test 测试模式 (可附加)
|
|
|
|
-P,--proxy 强制使用 [FastGit] 加速 (可附加)
|
2021-06-08 06:22:26 +00:00
|
|
|
-C <Github URL> 更改 Github 地址
|
2021-06-12 09:28:06 +00:00
|
|
|
-B <UEFI/Legacy> 指定 x86_64 设备下载 UEFI 或 Legacy 引导的固件 (危险)
|
2021-06-12 10:37:10 +00:00
|
|
|
-H,--help 打印 AutoUpdate 帮助信息
|
|
|
|
-L,--list 打印当前系统信息
|
|
|
|
-U 检查版本更新
|
2021-06-07 08:27:27 +00:00
|
|
|
--corn <task=> <time> 设置定时任务
|
2021-06-12 10:37:10 +00:00
|
|
|
--corn-del 删除所有 AutoUpdate 定时任务
|
|
|
|
--bak <path> <name> 备份 Openwrt 配置文件到用户指定的目录
|
2021-06-07 08:27:27 +00:00
|
|
|
--clean 清理固件下载缓存
|
2021-06-12 10:37:10 +00:00
|
|
|
--check 检查 AutoUpdate 依赖软件包
|
|
|
|
--var <variable> 打印用户指定的 <variable>
|
|
|
|
--var-del <variable> 删除用户指定的 <variable>
|
|
|
|
--log 打印 AutoUpdate 历史运行日志
|
|
|
|
--log-path <path> 更改 AutoUpdate 运行日志保存目录
|
2021-06-07 08:27:27 +00:00
|
|
|
|
2021-04-29 12:35:12 +00:00
|
|
|
EOF
|
2021-06-06 06:05:58 +00:00
|
|
|
exit 0
|
2021-04-05 01:44:55 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 06:05:58 +00:00
|
|
|
SHOW_VARIABLE() {
|
|
|
|
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-08 06:22:26 +00:00
|
|
|
固件作者: ${Author}
|
2021-06-06 06:05:58 +00:00
|
|
|
默认设备: ${Default_Device}
|
|
|
|
软件架构: ${TARGET_SUBTARGET}
|
|
|
|
固件版本: ${CURRENT_Version}
|
|
|
|
作者仓库: ${Github}
|
|
|
|
源码仓库: https://github.com/${Openwrt_Author}/${Openwrt_Repo_Name}:${Openwrt_Branch}
|
|
|
|
Release API: ${Github_Tag_URL}
|
2021-06-08 06:22:26 +00:00
|
|
|
固件格式-框架: $(GET_VARIABLE AutoBuild_Firmware= ${Default_Variable})
|
|
|
|
固件名称-框架: $(GET_VARIABLE Egrep_Firmware= ${Default_Variable})
|
2021-06-06 06:05:58 +00:00
|
|
|
默认下载地址: ${Github_Release_URL}
|
2021-06-08 06:22:26 +00:00
|
|
|
固件保存位置: ${FW_SAVE_PATH}
|
2021-06-06 06:05:58 +00:00
|
|
|
固件格式: ${Firmware_Type}
|
2021-06-08 15:37:17 +00:00
|
|
|
log 文件: ${log_Path}/AutoUpdate.log
|
2021-04-29 12:35:12 +00:00
|
|
|
EOF
|
2021-06-06 06:05:58 +00:00
|
|
|
[[ ${TARGET_PROFILE} == x86_64 ]] && {
|
|
|
|
echo "引导模式: ${x86_64_Boot}"
|
2021-04-30 14:20:27 +00:00
|
|
|
}
|
2021-05-01 06:27:02 +00:00
|
|
|
exit 0
|
2020-09-25 01:51:26 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 08:27:27 +00:00
|
|
|
RANDOM() {
|
|
|
|
openssl rand -base64 $1 | md5sum | cut -c 1-$1
|
|
|
|
}
|
|
|
|
|
2021-04-05 01:44:55 +00:00
|
|
|
TIME() {
|
2021-06-08 15:37:17 +00:00
|
|
|
[[ ! -d ${log_Path} ]] && mkdir -p "${log_Path}"
|
|
|
|
[[ ! -f ${log_Path}/AutoUpdate.log ]] && touch "${log_Path}/AutoUpdate.log"
|
2021-06-06 06:05:58 +00:00
|
|
|
[[ -z $1 ]] && {
|
2021-05-17 09:01:24 +00:00
|
|
|
echo -ne "\n\e[36m[$(date "+%H:%M:%S")]\e[0m "
|
2021-05-13 09:12:35 +00:00
|
|
|
} || {
|
2021-05-17 09:01:24 +00:00
|
|
|
case $1 in
|
2021-06-06 06:05:58 +00:00
|
|
|
r) Color="\e[31m";;
|
|
|
|
g) Color="\e[32m";;
|
|
|
|
b) Color="\e[34m";;
|
|
|
|
y) Color="\e[33m";;
|
|
|
|
x) Color="\e[36m";;
|
2021-05-17 09:01:24 +00:00
|
|
|
esac
|
|
|
|
[[ $# -lt 2 ]] && {
|
2021-06-06 06:05:58 +00:00
|
|
|
echo -e "\n\e[36m[$(date "+%H:%M:%S")]\e[0m $1"
|
2021-06-08 15:37:17 +00:00
|
|
|
echo "[$(date "+%Y-%m-%d-%H:%M:%S")] $1" >> ${log_Path}/AutoUpdate.log
|
2021-05-17 09:01:24 +00:00
|
|
|
} || {
|
2021-06-06 06:05:58 +00:00
|
|
|
echo -e "\n\e[36m[$(date "+%H:%M:%S")]\e[0m ${Color}$2\e[0m"
|
2021-06-08 15:37:17 +00:00
|
|
|
echo "[$(date "+%Y-%m-%d-%H:%M:%S")] $2" >> ${log_Path}/AutoUpdate.log
|
2021-05-17 09:01:24 +00:00
|
|
|
}
|
2021-05-13 09:12:35 +00:00
|
|
|
}
|
2021-02-21 12:23:35 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 06:05:58 +00:00
|
|
|
CHECK_PKG() {
|
|
|
|
which $1 > /dev/null 2>&1
|
|
|
|
[[ $? == 0 ]] && echo true || echo false
|
2021-04-30 14:20:27 +00:00
|
|
|
}
|
2021-05-13 09:12:35 +00:00
|
|
|
|
2021-06-06 06:05:58 +00:00
|
|
|
LOAD_VARIABLE() {
|
|
|
|
while [[ $1 ]];do
|
|
|
|
[[ -f $1 ]] && {
|
|
|
|
chmod 777 $1
|
|
|
|
source $1
|
|
|
|
}
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
[[ -z ${TARGET_PROFILE} && -n ${Default_Device} ]] && TARGET_PROFILE="${Default_Device}"
|
|
|
|
[[ -z ${TARGET_PROFILE} ]] && TARGET_PROFILE="$(jsonfilter -e '@.model.id' < /etc/board.json | tr ',' '_')"
|
|
|
|
[[ -z ${TARGET_PROFILE} ]] && TIME r "获取设备名称失败,无法执行更新!" && exit 1
|
|
|
|
[[ -z ${CURRENT_Version} ]] && CURRENT_Version=未知
|
2021-06-08 06:22:26 +00:00
|
|
|
[[ -z ${FW_SAVE_PATH} ]] && FW_SAVE_PATH=/tmp/Downloads
|
2021-06-06 06:05:58 +00:00
|
|
|
Github_Release_URL="${Github}/releases/download/AutoUpdate"
|
|
|
|
FW_Author="${Github##*com/}"
|
|
|
|
Github_Tag_URL="https://api.github.com/repos/${FW_Author}/releases/latest"
|
|
|
|
Github_Proxy_URL="https://download.fastgit.org"
|
|
|
|
FW_NoProxy_URL="https://github.com/${FW_Author}/releases/download/AutoUpdate"
|
|
|
|
FW_Proxy_URL="${Github_Proxy_URL}/${FW_Author}/releases/download/AutoUpdate"
|
|
|
|
case ${TARGET_PROFILE} in
|
|
|
|
x86_64)
|
|
|
|
case ${Firmware_Type} in
|
|
|
|
img.gz | img)
|
|
|
|
[[ -z ${x86_64_Boot} ]] && {
|
|
|
|
[ -d /sys/firmware/efi ] && {
|
|
|
|
x86_64_Boot=UEFI
|
|
|
|
} || x86_64_Boot=Legacy
|
|
|
|
}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
TIME r "暂不支持当前固件格式!"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2021-03-24 14:06:20 +00:00
|
|
|
;;
|
2021-06-06 06:05:58 +00:00
|
|
|
*)
|
|
|
|
[[ -z ${Firmware_Type} ]] && Firmware_Type=bin
|
2021-03-24 14:06:20 +00:00
|
|
|
esac
|
2021-06-06 06:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EDIT_VARIABLE() {
|
2021-06-08 06:22:26 +00:00
|
|
|
local Mode=$1
|
|
|
|
shift
|
2021-06-06 06:05:58 +00:00
|
|
|
[[ ! -f $1 ]] && TIME r "未检测到定义文件: [$1] !" && exit 1
|
2021-06-08 06:22:26 +00:00
|
|
|
case "${Mode}" in
|
|
|
|
edit)
|
|
|
|
[[ $# != 3 ]] && SHELL_HELP 1 $*
|
|
|
|
if [[ -z $(GET_VARIABLE ${2}= $1) ]];then
|
|
|
|
echo -e "\n$2=$3" >> $1
|
|
|
|
else
|
|
|
|
sed -i "s?$(GET_VARIABLE ${2}= $1)?$3?g" $1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
rm)
|
|
|
|
[[ $# != 2 ]] && SHELL_HELP 1 $*
|
|
|
|
sed -i "/${2}=/d" $1
|
|
|
|
;;
|
|
|
|
esac
|
2021-06-06 06:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CHANGE_GITHUB() {
|
|
|
|
[[ ! $1 =~ https://github.com/ ]] && {
|
2021-06-08 06:22:26 +00:00
|
|
|
TIME r "ERROR Github URL: $1"
|
|
|
|
TIME r "错误的 Github 地址,示例: https://github.com/Hyy2001X/AutoBuild-Actions"
|
2021-06-06 06:05:58 +00:00
|
|
|
exit 1
|
|
|
|
}
|
2021-06-08 03:05:51 +00:00
|
|
|
UCI_Github_URL=$(uci get autoupdate.@common[0].github 2>/dev/null)
|
2021-06-06 06:05:58 +00:00
|
|
|
[[ -n ${UCI_Github_URL} && ! ${UCI_Github_URL} == $1 ]] && {
|
2021-06-08 03:05:51 +00:00
|
|
|
uci set autoupdate.@common[0].github=$1
|
2021-06-06 06:05:58 +00:00
|
|
|
uci commit autoupdate
|
|
|
|
TIME y "UCI 设置已更新!"
|
|
|
|
}
|
|
|
|
[[ ! ${Github} == $1 ]] && {
|
2021-06-08 06:22:26 +00:00
|
|
|
EDIT_VARIABLE edit ${Custom_Variable} Github $1
|
|
|
|
TIME y "Github 地址已修改为: $1"
|
2021-05-06 13:12:01 +00:00
|
|
|
} || {
|
2021-06-06 06:05:58 +00:00
|
|
|
TIME y "当前输入的地址与原地址相同,无需修改!"
|
2021-05-06 13:12:01 +00:00
|
|
|
}
|
2021-06-06 06:05:58 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
CHANGE_BOOT() {
|
2021-06-08 06:22:26 +00:00
|
|
|
[[ -z $1 ]] && SHELL_HELP 1 $*
|
2021-06-06 06:05:58 +00:00
|
|
|
case "$1" in
|
|
|
|
UEFI | Legacy)
|
2021-06-08 06:22:26 +00:00
|
|
|
EDIT_VARIABLE edit ${Custom_Variable} x86_64_Boot $1
|
2021-06-12 10:37:10 +00:00
|
|
|
echo "ON" > /force_dump
|
2021-06-12 09:28:06 +00:00
|
|
|
TIME r "警告: 更换引导方式后更新固件后可能导致设备无法正常启动!"
|
2021-06-12 10:40:45 +00:00
|
|
|
TIME y "已创建临时文件 /force_dump"
|
|
|
|
TIME y "固件引导格式已指定为: [$1],AutoUpdate 将在下一次更新时执行强制刷写固件!"
|
2020-12-23 14:28:57 +00:00
|
|
|
;;
|
2021-06-06 06:05:58 +00:00
|
|
|
*)
|
|
|
|
TIME r "错误的参数: [$1],当前支持的选项: [UEFI/Legacy] !"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
GET_VARIABLE() {
|
2021-06-08 06:22:26 +00:00
|
|
|
[[ $# != 2 ]] && SHELL_HELP 1 $*
|
2021-06-06 06:05:58 +00:00
|
|
|
[[ ! -f $2 ]] && TIME "未检测到定义文件: [$2] !" && exit 1
|
2021-06-08 15:37:17 +00:00
|
|
|
echo -e "$(grep "$1" $2 | cut -c$(echo $1 | wc -c)-200 | awk 'NR==1')"
|
2021-06-06 06:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UPDATE_SCRIPT() {
|
2021-06-08 06:22:26 +00:00
|
|
|
[[ $# != 2 ]] && SHELL_HELP 1 $*
|
2021-06-06 06:05:58 +00:00
|
|
|
TIME b "脚本保存目录: $1"
|
|
|
|
TIME b "下载地址: $2"
|
|
|
|
TIME "开始更新 AutoUpdate 脚本,请耐心等待..."
|
|
|
|
[ ! -d "$1" ] && mkdir -p $1
|
|
|
|
wget -q --tries 3 --timeout 5 $2 -O /tmp/AutoUpdate.sh
|
|
|
|
if [[ $? == 0 ]];then
|
|
|
|
mv -f /tmp/AutoUpdate.sh $1
|
|
|
|
[[ ! $? == 0 ]] && TIME r "AutoUpdate 脚本更新失败!" && exit 1
|
|
|
|
chmod +x $1/AutoUpdate.sh
|
|
|
|
NEW_Version=$(egrep -o "V[0-9].+" $1/AutoUpdate.sh | awk 'END{print}')
|
|
|
|
Banner_Version=$(egrep -o "V[0-9]+.[0-9].+" /etc/banner)
|
|
|
|
[[ -n "${Banner_Version}" ]] && sed -i "s?${Banner_Version}?${NEW_Version}?g" /etc/banner
|
|
|
|
TIME y "[${Version}] > [${NEW_Version}] AutoUpdate 脚本更新成功!"
|
|
|
|
else
|
|
|
|
TIME r "AutoUpdate 脚本更新失败,请检查网络后重试!"
|
|
|
|
fi
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_DEPENDS() {
|
|
|
|
TITLE
|
|
|
|
local PKG
|
|
|
|
echo -e "\n软件包 状态"
|
|
|
|
for PKG in $(echo $*)
|
|
|
|
do
|
|
|
|
if [[ ${PKG} =~ : ]];then
|
|
|
|
[[ $(echo ${PKG} | cut -d ":" -f1) == ${TARGET_BOARD} ]] && {
|
|
|
|
PKG="$(echo ${PKG} | cut -d ":" -f2)"
|
|
|
|
echo -e "${PKG} $(CHECK_PKG ${PKG})"
|
2021-05-17 09:01:24 +00:00
|
|
|
}
|
2021-01-25 10:08:09 +00:00
|
|
|
else
|
2021-06-06 06:05:58 +00:00
|
|
|
echo -e "${PKG} $(CHECK_PKG ${PKG})"
|
2021-01-25 10:08:09 +00:00
|
|
|
fi
|
2021-06-06 06:05:58 +00:00
|
|
|
done
|
|
|
|
TIME y "测试结束,若某项结果为 false,请手动安装该软件包!"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_UPDATES() {
|
2021-06-08 06:22:26 +00:00
|
|
|
local Size X
|
2021-06-06 06:05:58 +00:00
|
|
|
TIME "正在获取版本更新..."
|
2021-06-08 06:22:26 +00:00
|
|
|
[ ! -d ${FW_SAVE_PATH} ] && mkdir -p ${FW_SAVE_PATH}
|
|
|
|
wget -q --timeout 5 ${Github_Tag_URL} -O ${FW_SAVE_PATH}/Github_Tags
|
|
|
|
[[ ! $? == 0 ]] || [[ ! -f ${FW_SAVE_PATH}/Github_Tags ]] && {
|
|
|
|
[[ $1 == check ]] && echo "获取失败" > /tmp/Cloud_Version
|
2021-06-06 06:05:58 +00:00
|
|
|
TIME r "检查更新失败,请稍后重试!"
|
|
|
|
exit 1
|
|
|
|
}
|
2021-06-08 06:22:26 +00:00
|
|
|
eval X=$(GET_VARIABLE Egrep_Firmware= ${Default_Variable})
|
|
|
|
FW_Name=$(egrep -o "${X}" ${FW_SAVE_PATH}/Github_Tags | awk 'END {print}')
|
|
|
|
[[ -z ${FW_Name} ]] && TIME "云端固件名称获取失败!" && exit 1
|
2021-06-06 06:05:58 +00:00
|
|
|
CLOUD_Firmware_Version=$(echo ${FW_Name} | egrep -o "R[0-9].*20[0-9]+")
|
|
|
|
SHA5BIT=$(echo ${FW_Name} | egrep -o "[a-zA-Z0-9]+.${Firmware_Type}" | sed -r "s/(.*).${Firmware_Type}/\1/")
|
2021-06-08 06:22:26 +00:00
|
|
|
let Size="$(grep -n "${FW_Name}" ${FW_SAVE_PATH}/Github_Tags | tail -1 | cut -d : -f 1)-4"
|
|
|
|
let CLOUD_Firmware_Size="$(sed -n "${Size}p" ${FW_SAVE_PATH}/Github_Tags | egrep -o "[0-9]+" | awk '{print ($1)/1048576}' | awk -F. '{print $1}')+1"
|
|
|
|
[[ $1 == check ]] && {
|
2021-06-06 06:05:58 +00:00
|
|
|
echo -e "\n当前固件版本: ${CURRENT_Version}\n$([[ ! ${CLOUD_Firmware_Version} == ${CURRENT_Version} ]] && echo "云端固件版本: ${CLOUD_Firmware_Version} [可更新]" || echo "云端固件版本: ${CLOUD_Firmware_Version} [无需更新]")\n"
|
|
|
|
if [[ "${CURRENT_Version}" == "${CLOUD_Firmware_Version}" ]];then
|
|
|
|
Checked_Type=" [已是最新]"
|
2021-05-16 12:58:30 +00:00
|
|
|
else
|
2021-06-06 06:05:58 +00:00
|
|
|
Checked_Type=" [可更新]"
|
2021-05-16 12:58:30 +00:00
|
|
|
fi
|
2021-06-08 06:22:26 +00:00
|
|
|
echo "${CLOUD_Firmware_Version} /${x86_64_Boot}${Checked_Type}" > /tmp/Cloud_Version
|
|
|
|
}
|
|
|
|
rm ${FW_SAVE_PATH}/Github_Tags
|
2021-06-06 06:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PREPARE_UPGRADES() {
|
|
|
|
TITLE
|
2021-06-12 10:37:10 +00:00
|
|
|
while [[ $1 ]];do
|
|
|
|
[[ $1 == -T || $1 == --test ]] && {
|
2021-06-06 06:05:58 +00:00
|
|
|
Test_Mode=1
|
|
|
|
TAIL_MSG=" [Test Mode]"
|
2021-06-12 10:37:10 +00:00
|
|
|
} ||
|
|
|
|
[[ $1 == -P || $1 == --proxy ]] && {
|
2021-06-06 06:05:58 +00:00
|
|
|
Proxy_Mode=1
|
|
|
|
Proxy_Echo="[FastGit] "
|
|
|
|
} || {
|
|
|
|
Proxy_Mode=0
|
|
|
|
unset Proxy_Echo
|
|
|
|
}
|
2021-06-12 10:37:10 +00:00
|
|
|
[[ $1 =~ path= ]] && {
|
2021-06-06 06:05:58 +00:00
|
|
|
[ -z "$(echo ${Z} | cut -d "=" -f2)" ] && TIME r "保存路径不能为空!" && exit 1
|
|
|
|
FW_SAVE_PATH=$(echo ${Z} | cut -d "=" -f2)
|
|
|
|
TIME g "使用自定义固件保存位置: ${FW_SAVE_PATH}"
|
|
|
|
}
|
2021-06-12 10:37:10 +00:00
|
|
|
[[ $1 == -F || $1 == --force ]] && Force_Write=1
|
|
|
|
case $1 in
|
|
|
|
-n | -f | -u)
|
|
|
|
Option="$1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2021-06-06 06:05:58 +00:00
|
|
|
done
|
|
|
|
REMOVE_FW_CACHE quiet ${FW_SAVE_PATH}
|
2021-06-09 01:49:09 +00:00
|
|
|
Upgrade_Option="${Upgrade_Command} -q"
|
2021-06-12 10:37:10 +00:00
|
|
|
case ${Option} in
|
2021-06-06 06:05:58 +00:00
|
|
|
-n)
|
2021-06-12 10:37:10 +00:00
|
|
|
Upgrade_Option="${Upgrade_Command} -q -n"
|
2021-06-06 06:05:58 +00:00
|
|
|
MSG="更新固件 (不保留配置)"
|
2021-05-06 02:43:50 +00:00
|
|
|
;;
|
2021-06-06 06:05:58 +00:00
|
|
|
-f)
|
|
|
|
Force_Mode=1
|
2021-06-12 09:28:06 +00:00
|
|
|
Upgrade_Option="${Upgrade_Command} -q -F"
|
2021-06-06 06:05:58 +00:00
|
|
|
MSG="强制更新固件 (保留配置)"
|
|
|
|
;;
|
|
|
|
-u)
|
|
|
|
AutoUpdate_Mode=1
|
2021-06-12 10:37:10 +00:00
|
|
|
MSG="LUCI 定时更新 (保留配置)"
|
2020-12-21 14:16:18 +00:00
|
|
|
;;
|
2021-06-06 06:05:58 +00:00
|
|
|
*)
|
|
|
|
Upgrade_Option="${Upgrade_Command} -q"
|
2021-06-12 09:28:06 +00:00
|
|
|
MSG="更新固件 (保留配置)"
|
2020-12-21 14:16:18 +00:00
|
|
|
esac
|
2021-06-12 10:37:10 +00:00
|
|
|
[ -f /force_dump ] && Force_Write=1
|
|
|
|
[[ ${Force_Write} == 1 && ! ${Force_Mode} == 1 ]] && {
|
|
|
|
MSG_2=" [强制刷写]"
|
|
|
|
Upgrade_Option="${Upgrade_Option} -F"
|
|
|
|
}
|
|
|
|
TIME g "执行: ${Proxy_Echo}${MSG}${TAIL_MSG}${MSG_2}"
|
2021-06-06 06:05:58 +00:00
|
|
|
if [[ $(CHECK_PKG curl) == true && ${Proxy_Mode} == 0 ]];then
|
|
|
|
Google_Check=$(curl -I -s --connect-timeout 3 google.com -w %{http_code} | tail -n1)
|
|
|
|
[[ ! ${Google_Check} == 301 ]] && {
|
2021-05-13 09:12:35 +00:00
|
|
|
TIME r "Google 连接失败,尝试使用 [FastGit] 镜像加速!"
|
2021-06-06 06:05:58 +00:00
|
|
|
Proxy_Mode=1
|
2021-05-12 13:15:10 +00:00
|
|
|
}
|
|
|
|
fi
|
2021-06-08 06:22:26 +00:00
|
|
|
CHECK_UPDATES continue
|
2021-06-06 06:05:58 +00:00
|
|
|
[[ -z ${CLOUD_Firmware_Version} ]] && {
|
|
|
|
TIME r "云端固件信息获取失败!"
|
2021-04-30 14:20:27 +00:00
|
|
|
exit 1
|
|
|
|
}
|
2021-06-06 06:05:58 +00:00
|
|
|
[[ ${Proxy_Mode} == 1 ]] && {
|
2021-06-08 15:37:17 +00:00
|
|
|
FW_URL="${FW_Proxy_URL}"
|
2021-06-06 06:05:58 +00:00
|
|
|
} || FW_URL="${FW_NoProxy_URL}"
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
固件作者: ${FW_Author%/*}
|
|
|
|
设备名称: $(uname -n) / ${TARGET_PROFILE}
|
|
|
|
$([[ ${TARGET_PROFILE} == x86_64 ]] && echo "固件格式: ${Firmware_Type} / ${x86_64_Boot}" || echo "固件格式: ${Firmware_Type}")
|
|
|
|
|
|
|
|
当前固件版本: ${CURRENT_Version}
|
|
|
|
$([[ ! ${CLOUD_Firmware_Version} == ${CURRENT_Version} ]] && echo "云端固件版本: ${CLOUD_Firmware_Version} [可更新]" || echo "云端固件版本: ${CLOUD_Firmware_Version} [无需更新]")
|
|
|
|
云端固件体积: ${CLOUD_Firmware_Size}MB
|
|
|
|
|
|
|
|
云端固件名称: ${FW_Name}
|
|
|
|
固件下载地址: ${FW_URL}
|
|
|
|
EOF
|
|
|
|
if [[ ${CURRENT_Version} == ${CLOUD_Firmware_Version} ]];then
|
|
|
|
[[ ${AutoUpdate_Mode} == 1 ]] && {
|
|
|
|
TIME y "已是最新版本,无需更新!"
|
2021-04-30 14:20:27 +00:00
|
|
|
exit 0
|
|
|
|
}
|
2021-06-06 06:05:58 +00:00
|
|
|
[[ ! ${Force_Mode} == 1 ]] && {
|
|
|
|
TIME && read -p "已是最新版本,是否重新刷写固件?[Y/n]:" Choose
|
|
|
|
} || Choose=Y
|
|
|
|
[[ ! ${Choose} =~ [Yy] ]] && exit 0
|
|
|
|
TIME g "开始强制更新固件..."
|
2020-09-28 14:28:40 +00:00
|
|
|
fi
|
2021-06-06 06:05:58 +00:00
|
|
|
Retry_Times=5
|
|
|
|
TIME "正在下载固件,请耐心等待..."
|
|
|
|
while [[ ${Retry_Times} -ge 0 ]];do
|
|
|
|
if [[ ! ${PROXY_Mode} == 1 ]];then
|
|
|
|
[[ ${Retry_Times} == 4 ]] && {
|
|
|
|
TIME g "尝试使用 [FastGit] 镜像加速下载固件!"
|
|
|
|
FW_URL="${FW_Proxy_URL}"
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
[[ ${Retry_Times} == 2 ]] && {
|
|
|
|
FW_URL="${FW_NoProxy_URL}"
|
|
|
|
}
|
|
|
|
if [[ ${Retry_Times} == 0 ]];then
|
|
|
|
TIME r "固件下载失败,请检查网络后重试!"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
wget -q --tries 3 --timeout 5 "${FW_URL}/${FW_Name}" -O ${FW_SAVE_PATH}/${FW_Name}
|
|
|
|
[[ $? == 0 ]] && TIME y "固件下载成功!" && break
|
|
|
|
fi
|
|
|
|
Retry_Times=$((${Retry_Times} - 1))
|
|
|
|
TIME r "下载失败,剩余尝试次数: ${Retry_Times} 次"
|
|
|
|
done
|
|
|
|
case "${Firmware_Type}" in
|
|
|
|
img.gz)
|
|
|
|
gzip -d -q -f -c ${FW_SAVE_PATH}/${FW_Name} > ${FW_SAVE_PATH}/$(echo ${FW_Name} | sed -r 's/(.*).gz/\1/')
|
|
|
|
FW_Name="$(echo ${FW_Name} | sed -r 's/(.*).gz/\1/')"
|
|
|
|
[[ $? == 0 ]] && {
|
|
|
|
TIME y "解压成功,固件已解压到: ${FW_SAVE_PATH}/${FW_Name}!"
|
|
|
|
} || {
|
|
|
|
TIME r "固件解压失败,请检查相关依赖或更换固件保存目录!"
|
|
|
|
exit 1
|
2021-05-17 09:01:24 +00:00
|
|
|
}
|
2021-06-06 06:05:58 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
[[ ! ${Test_Mode} == 1 ]] && {
|
|
|
|
sleep 3
|
2021-06-09 08:31:34 +00:00
|
|
|
chmod 777 ${FW_SAVE_PATH}/${FW_Name}
|
2021-06-09 01:49:09 +00:00
|
|
|
DO_UPGRADE ${Upgrade_Option} ${FW_SAVE_PATH}/${FW_Name}
|
2021-04-30 14:20:27 +00:00
|
|
|
} || {
|
2021-06-12 09:28:06 +00:00
|
|
|
TIME b "[Test Mode] 执行: ${Upgrade_Option} ${FW_SAVE_PATH}/${FW_Name}"
|
2021-06-06 06:05:58 +00:00
|
|
|
TIME b "[Test Mode] 测试模式运行完毕!"
|
|
|
|
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
|
|
|
|
|
|
|
DO_UPGRADE() {
|
|
|
|
TIME g "正在更新固件,更新期间请耐心等待..."
|
|
|
|
sleep 1
|
|
|
|
$*
|
|
|
|
[[ $? -ne 0 ]] && {
|
|
|
|
TIME r "固件刷写失败,请尝试手动更新固件!"
|
|
|
|
exit 1
|
|
|
|
} || exit 0
|
2021-05-13 10:40:16 +00:00
|
|
|
}
|
2021-06-06 06:05:58 +00:00
|
|
|
|
|
|
|
REMOVE_FW_CACHE() {
|
|
|
|
[[ -z $2 ]] && RM_PATH=${FW_SAVE_PATH}
|
|
|
|
rm -rf ${RM_PATH}/AutoBuild-${TARGET_PROFILE}-* \
|
|
|
|
${RM_PATH}/Github_Tags
|
|
|
|
case "$1" in
|
|
|
|
quiet)
|
|
|
|
:
|
|
|
|
;;
|
|
|
|
normal)
|
|
|
|
TIME y "固件下载缓存清理完成!"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2021-06-12 10:37:10 +00:00
|
|
|
export Version=V6.0.7
|
2021-06-08 15:37:17 +00:00
|
|
|
export log_Path=/tmp
|
2021-06-06 06:05:58 +00:00
|
|
|
export Upgrade_Command=sysupgrade
|
2021-06-08 06:22:26 +00:00
|
|
|
export Default_Variable=/etc/AutoBuild/Default_Variable
|
|
|
|
export Custom_Variable=/etc/AutoBuild/Custom_Variable
|
|
|
|
|
|
|
|
[ ! -f ${Custom_Variable} ] && touch ${Custom_Variable}
|
|
|
|
LOAD_VARIABLE ${Default_Variable} ${Custom_Variable}
|
2021-06-06 06:05:58 +00:00
|
|
|
|
|
|
|
[[ -z $* ]] && PREPARE_UPGRADES $*
|
|
|
|
[[ $* =~ path= && ! $* =~ -x && ! $* =~ -U ]] && PREPARE_UPGRADES $*
|
|
|
|
|
|
|
|
while [[ $1 ]];do
|
|
|
|
case "$1" in
|
|
|
|
--clean)
|
|
|
|
REMOVE_FW_CACHE normal $*
|
|
|
|
;;
|
|
|
|
--check)
|
|
|
|
CHECK_DEPENDS curl wget x86:gzip
|
|
|
|
;;
|
|
|
|
-H | --help)
|
2021-06-08 06:22:26 +00:00
|
|
|
SHELL_HELP 0 1 $*
|
2021-06-06 06:05:58 +00:00
|
|
|
;;
|
|
|
|
-L | --list)
|
2021-06-08 06:22:26 +00:00
|
|
|
SHOW_VARIABLE
|
2021-06-06 06:05:58 +00:00
|
|
|
;;
|
|
|
|
-C)
|
|
|
|
CHANGE_GITHUB $2
|
|
|
|
;;
|
|
|
|
-B)
|
|
|
|
[[ ! ${TARGET_PROFILE} == x86_64 ]] && TIME r "该参数仅适用于 x86_64 设备!" && exit 1
|
|
|
|
CHANGE_BOOT $2
|
|
|
|
;;
|
|
|
|
-x)
|
|
|
|
while [[ $1 ]];do
|
|
|
|
[[ $1 == -P || $1 == --proxy ]] && Proxy_Mode=1
|
|
|
|
if [[ ${Proxy_Mode} == 1 && $1 =~ url= ]];then
|
|
|
|
TIME r "参数冲突: [$0 $*],[-P,--proxy] 与 [url=] 不能同时存在!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [[ ! $1 =~ url= ]];then
|
|
|
|
Script_URL=https://raw.githubusercontent.com/Hyy2001X/AutoBuild-Actions/master/Scripts/AutoUpdate.sh
|
|
|
|
else
|
|
|
|
[[ $1 =~ url= ]] && {
|
|
|
|
[[ -z $(echo $1 | cut -d "=" -f2) ]] && TIME r "脚本地址不能为空!" && exit 1
|
|
|
|
Script_URL="$(echo $1 | cut -d "=" -f2)"
|
|
|
|
TIME "使用自定义脚本地址: ${Script_URL}"
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
[[ $1 =~ path= ]] && {
|
|
|
|
[ -z "$(echo $1 | cut -d "=" -f2)" ] && TIME r "保存路径不能为空!" && exit 1
|
2021-06-08 06:22:26 +00:00
|
|
|
SH_SAVE_PATH="$(echo $1 | cut -d "=" -f2)"
|
2021-06-06 06:05:58 +00:00
|
|
|
}
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
[[ ${Proxy_Mode} == 1 ]] && Script_URL=https://raw.fastgit.org/Hyy2001X/AutoBuild-Actions/master/Scripts/AutoUpdate.sh
|
|
|
|
[[ -z ${SH_SAVE_PATH} ]] && SH_SAVE_PATH=/bin
|
|
|
|
UPDATE_SCRIPT ${SH_SAVE_PATH} ${Script_URL}
|
|
|
|
;;
|
2021-06-12 10:37:10 +00:00
|
|
|
-n | -f | -u | -T | --test | -P | --proxy | -F | --force)
|
2021-06-06 06:05:58 +00:00
|
|
|
PREPARE_UPGRADES $*
|
|
|
|
;;
|
|
|
|
--corn)
|
2021-06-08 06:22:26 +00:00
|
|
|
[[ $# != 3 ]] && SHELL_HELP 1 $*
|
2021-06-06 06:05:58 +00:00
|
|
|
shift
|
|
|
|
while [[ $1 ]];do
|
|
|
|
[[ $1 =~ task= ]] && Task="$(echo $1 | cut -d "=" -f2)"
|
|
|
|
Time="$1"
|
|
|
|
shift
|
|
|
|
done
|
2021-06-08 06:22:26 +00:00
|
|
|
[[ -z ${Task} || -z ${Time} ]] && SHELL_HELP 1 $*
|
2021-06-06 06:05:58 +00:00
|
|
|
echo -e "\n${Time} bash $0 $Task" >> /etc/crontabs/root
|
|
|
|
/etc/init.d/cron restart
|
|
|
|
TIME y "已设置计划任务: [${Time} bash $0 $Task]"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
--corn-del)
|
|
|
|
[ ! -f /etc/crontabs/root ] && exit 1
|
|
|
|
sed -i '/AutoUpdate/d' /etc/crontabs/root >/dev/null 2>&1
|
|
|
|
TIME y "已删除所有 AutoUpdate 相关计划任务!"
|
|
|
|
/etc/init.d/cron restart
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-U)
|
2021-06-08 06:22:26 +00:00
|
|
|
CHECK_UPDATES check
|
|
|
|
exit 0
|
2021-06-06 06:05:58 +00:00
|
|
|
;;
|
|
|
|
--var)
|
|
|
|
shift
|
2021-06-08 06:22:26 +00:00
|
|
|
[[ $# != 1 ]] && SHELL_HELP 1 $*
|
|
|
|
SHOW_VARIABLE=$(GET_VARIABLE "$1=" ${Custom_Variable})
|
|
|
|
[[ -z ${SHOW_VARIABLE} ]] && SHOW_VARIABLE=$(GET_VARIABLE "$1=" ${Default_Variable})
|
2021-06-06 06:05:58 +00:00
|
|
|
echo "${SHOW_VARIABLE}"
|
|
|
|
exit
|
|
|
|
;;
|
2021-06-08 06:22:26 +00:00
|
|
|
--var-del)
|
|
|
|
shift
|
|
|
|
[[ $# != 1 ]] && SHELL_HELP 1 $*
|
|
|
|
EDIT_VARIABLE rm ${Custom_Variable} $1
|
|
|
|
;;
|
2021-06-07 08:27:27 +00:00
|
|
|
--bak)
|
|
|
|
shift
|
|
|
|
[[ $# -lt 1 || $# -gt 2 ]] && TIME r "格式错误,示例: [bash $0 --bak /mnt/sda1 Openwrt_Backups.tar.gz]" && exit 1
|
|
|
|
[[ $# == 2 ]] && {
|
|
|
|
[[ ! -d $1 ]] && mkdir -p $1
|
|
|
|
FILE="$1/$2"
|
|
|
|
if [[ -f ${FILE} ]];then
|
|
|
|
FILE="${FILE}-$(RANDOM 5)"
|
|
|
|
fi
|
|
|
|
} || {
|
|
|
|
[[ ! -d $1 ]] && mkdir -p $1
|
|
|
|
FILE="$1/Openwrt-Backups-$(date +%Y-%m-%d)-$(RANDOM 5)"
|
|
|
|
}
|
|
|
|
[[ ! ${FILE} =~ tar.gz ]] && FILE="${FILE}.tar.gz"
|
|
|
|
TIME "Saving config files to [${FILE}] ..."
|
|
|
|
sysupgrade -b "${FILE}" >/dev/null 2>&1
|
|
|
|
[ $? == 0 ] && {
|
|
|
|
TIME y "备份成功!"
|
|
|
|
} || TIME r "备份文件创建失败,请更换保存目录!"
|
|
|
|
exit
|
|
|
|
;;
|
2021-06-08 06:22:26 +00:00
|
|
|
--log)
|
2021-06-12 04:53:18 +00:00
|
|
|
[[ -f ${log_Path}/AutoUpdate.log ]] && {
|
|
|
|
TITLE && echo
|
|
|
|
cat ${log_Path}/AutoUpdate.log
|
|
|
|
}
|
|
|
|
|
2021-06-08 06:22:26 +00:00
|
|
|
;;
|
|
|
|
--log-path)
|
|
|
|
shift
|
|
|
|
[[ -z $* ]] && SHELL_HELP 1 $*
|
2021-06-08 15:37:17 +00:00
|
|
|
EDIT_VARIABLE rm ${Custom_Variable} log_Path
|
|
|
|
EDIT_VARIABLE edit ${Custom_Variable} log_Path $1
|
2021-06-08 06:22:26 +00:00
|
|
|
[[ ! -d $1 ]] && mkdir -p $1
|
|
|
|
TIME y "AutoUpdate 日志位置已修改为: $1/AutoUpdate.log"
|
|
|
|
;;
|
2021-06-06 06:05:58 +00:00
|
|
|
*)
|
2021-06-08 06:22:26 +00:00
|
|
|
SHELL_HELP 1 $*
|
2021-06-06 06:05:58 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2021-06-08 06:22:26 +00:00
|
|
|
done
|