2020-09-19 07:37:55 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# https://github.com/Hyy2001X/AutoBuild-Actions
|
|
|
|
# AutoBuild Module by Hyy2001
|
|
|
|
# AutoUpdate
|
|
|
|
|
2020-10-02 18:04:28 +00:00
|
|
|
Version=V3.6
|
2020-09-27 03:40:52 +00:00
|
|
|
DEFAULT_DEVICE=d-team_newifi-d2
|
2020-09-19 07:37:55 +00:00
|
|
|
Github=https://github.com/Hyy2001X/AutoBuild-Actions
|
2020-09-23 09:43:46 +00:00
|
|
|
|
2020-09-28 14:28:40 +00:00
|
|
|
TIME() {
|
2020-09-25 01:51:26 +00:00
|
|
|
echo -ne "\n[$(date "+%H:%M:%S")] "
|
|
|
|
}
|
|
|
|
|
2020-09-19 07:37:55 +00:00
|
|
|
Github_Tags=$Github/releases/tag/AutoUpdate
|
|
|
|
Github_Download=$Github/releases/download/AutoUpdate
|
|
|
|
cd /etc
|
2020-09-27 03:40:52 +00:00
|
|
|
CURRENT_VERSION=`awk 'NR==1' ./openwrt_info`
|
2020-09-28 14:28:40 +00:00
|
|
|
CURRENT_DEVICE=`jsonfilter -e '@.model.id' < "/etc/board.json" | tr ',' '_'`
|
|
|
|
clear && echo "Openwrt-AutoUpdate Script $Version"
|
2020-10-02 18:04:28 +00:00
|
|
|
if [[ $1 == "" ]];then
|
|
|
|
Upgrade_Option="-q" && TIME && echo "执行: 保留配置升级"
|
2020-09-28 14:28:40 +00:00
|
|
|
else
|
2020-10-02 18:04:28 +00:00
|
|
|
Upgrade_Option="$1"
|
|
|
|
[ "$Upgrade_Option" == "-n" ] && TIME && echo "执行: 不保留配置升级"
|
|
|
|
if [ "$Upgrade_Option" == "-x" ];then
|
|
|
|
Upgrade_Option="-q"
|
2020-10-02 18:07:56 +00:00
|
|
|
Force_Update=1
|
2020-10-02 18:04:28 +00:00
|
|
|
TIME && echo "执行: 保留配置强制升级"
|
|
|
|
fi
|
2020-09-29 06:17:03 +00:00
|
|
|
fi
|
2020-10-02 18:06:37 +00:00
|
|
|
opkg list | awk '{print $1}' > /tmp/Package_list
|
|
|
|
grep "curl" /tmp/Package_list > /dev/null 2>&1
|
|
|
|
if [ ! $? -ne 0 ];then
|
|
|
|
Google_Check=`curl -I -s --connect-timeout 5 www.google.com -w %{http_code} | tail -n1`
|
|
|
|
[ ! "$Google_Check" == 200 ] && TIME && echo "Google 连接失败,可能导致固件下载速度缓慢!"
|
|
|
|
fi
|
|
|
|
grep "wget" /tmp/Package_list > /dev/null 2>&1
|
|
|
|
[ $? -ne 0 ] && TIME && echo "未安装 wget!请先执行[opkg update && opkg install wget]" && exit
|
2020-09-29 06:17:03 +00:00
|
|
|
if [ "$CURRENT_VERSION" == "" ];then
|
2020-09-25 01:51:26 +00:00
|
|
|
echo -e "\n警告:当前固件版本获取失败!"
|
2020-09-19 07:37:55 +00:00
|
|
|
CURRENT_VERSION=未知
|
|
|
|
fi
|
2020-09-29 06:17:03 +00:00
|
|
|
if [ "$CURRENT_DEVICE" == "" ];then
|
2020-09-27 04:27:14 +00:00
|
|
|
echo -e "\n警告:当前设备名称获取失败,使用预设名称[$DEFAULT_DEVICE]"
|
2020-09-27 03:40:52 +00:00
|
|
|
CURRENT_DEVICE=$DEFAULT_DEVICE
|
2020-09-26 17:14:39 +00:00
|
|
|
fi
|
2020-09-19 07:37:55 +00:00
|
|
|
cd /tmp
|
2020-09-25 01:51:26 +00:00
|
|
|
TIME && echo "正在获取云端固件版本..."
|
2020-10-02 15:38:18 +00:00
|
|
|
GET_Version=`wget -q $Github_Tags -O - | egrep -o 'R[0-9]+.[0-9]+.[0-9]+.[0-9]+' | awk 'END {print}'`
|
2020-09-29 06:17:03 +00:00
|
|
|
if [ "$GET_Version" == "" ];then
|
2020-09-28 14:28:40 +00:00
|
|
|
TIME && echo "云端固件版本获取失败,请稍后重试!"
|
2020-09-19 07:37:55 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
echo -e "\n当前固件版本:$CURRENT_VERSION"
|
|
|
|
echo -e "云端固件版本:$GET_Version\n"
|
2020-10-02 18:04:28 +00:00
|
|
|
if [[ ! $Force_Update == 1 ]];then
|
|
|
|
if [ $CURRENT_VERSION == $GET_Version ];then
|
|
|
|
read -p "已是最新版本,是否强制更新固件?[Y/n]:" Choose
|
|
|
|
if [ $Choose == Y ] || [ $Choose == y ];then
|
|
|
|
TIME && echo -e "开始强制更新固件...\n"
|
|
|
|
else
|
|
|
|
TIME && echo "用户已取消强制更新,即将退出更新程序..."
|
|
|
|
sleep 2
|
|
|
|
exit
|
|
|
|
fi
|
2020-09-28 14:28:40 +00:00
|
|
|
fi
|
2020-10-02 18:07:56 +00:00
|
|
|
fi
|
2020-09-26 17:14:39 +00:00
|
|
|
Firmware_Info="AutoBuild-${CURRENT_DEVICE}-Lede-${GET_Version}"
|
2020-09-26 16:57:50 +00:00
|
|
|
Firmware="${Firmware_Info}.bin"
|
2020-09-25 01:51:26 +00:00
|
|
|
Firmware_Detail="${Firmware_Info}.detail"
|
2020-09-19 07:37:55 +00:00
|
|
|
echo "云端固件名称:$Firmware"
|
2020-09-25 01:51:26 +00:00
|
|
|
TIME && echo "正在下载固件,请耐心等待..."
|
|
|
|
wget -q $Github_Download/$Firmware -O $Firmware
|
2020-09-19 07:37:55 +00:00
|
|
|
if [ ! "$?" == 0 ]; then
|
2020-09-25 01:51:26 +00:00
|
|
|
TIME && echo "下载失败,请检查网络后重试!"
|
2020-09-19 07:37:55 +00:00
|
|
|
exit
|
|
|
|
fi
|
2020-09-25 01:51:26 +00:00
|
|
|
TIME && echo "下载成功!固件大小:$(du -h $Firmware | awk '{print $1}')B"
|
|
|
|
TIME && echo "正在下载固件详细信息..."
|
|
|
|
wget -q $Github_Download/$Firmware_Detail -O $Firmware_Detail
|
2020-09-19 07:37:55 +00:00
|
|
|
if [ ! "$?" == 0 ]; then
|
2020-09-25 01:51:26 +00:00
|
|
|
TIME && echo "下载失败,请检查网络后重试!"
|
2020-09-19 07:37:55 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
GET_MD5=`awk -F'[ :]' '/MD5/ {print $2;exit}' $Firmware_Detail`
|
|
|
|
CURRENT_MD5=`md5sum $Firmware | cut -d ' ' -f1`
|
2020-09-25 01:51:26 +00:00
|
|
|
echo -e "\n当前固件MD5:$CURRENT_MD5"
|
|
|
|
echo "云端固件MD5:$GET_MD5"
|
2020-09-19 07:37:55 +00:00
|
|
|
if [ "$GET_MD5" == "" ] || [ "$CURRENT_MD5" == "" ];then
|
2020-09-25 01:51:26 +00:00
|
|
|
echo -e "\nMD5获取失败!"
|
2020-09-19 07:37:55 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
if [ ! "$GET_MD5" == "$CURRENT_MD5" ];then
|
2020-09-29 06:17:03 +00:00
|
|
|
echo -e "\nMD5对比失败,请检查网络后重试!"
|
2020-09-19 07:37:55 +00:00
|
|
|
exit
|
|
|
|
fi
|
2020-09-29 06:17:03 +00:00
|
|
|
TIME && echo "MD5对比通过!"
|
2020-09-19 07:37:55 +00:00
|
|
|
sleep 3
|
2020-09-25 01:51:26 +00:00
|
|
|
TIME && echo -e "开始升级固件,请耐心等待...\n"
|
2020-10-02 18:04:28 +00:00
|
|
|
sysupgrade ${Upgrade_Option} $Firmware
|