From 575d9da48ba336508f758a36488ea81663dd7aa0 Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 4 Jan 2022 21:18:20 +0800 Subject: [PATCH] enhance autoupdate --- README.md | 4 ++-- scripts/autoupdate-bash.sh | 25 ++++++++++++------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 892e9bd..1202b56 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,11 @@ https://github.com/klever1988/nanopi-openwrt/tags ### 终端内在线升级方法: ```bash -wget -qO- https://github.com/klever1988/nanopi-openwrt/raw/master/scripts/autoupdate.sh | sh +wget -qO- https://github.com/klever1988/nanopi-openwrt/raw/master/scripts/autoupdate-bash.sh | bash ``` slim版 ```bash -wget -qO- https://github.com/klever1988/nanopi-openwrt/raw/master/scripts/autoupdate.sh | ver=-slim sh +wget -qO- https://github.com/klever1988/nanopi-openwrt/raw/master/scripts/autoupdate-bash.sh | ver=-slim bash ``` (脚本由gary lau提供,非常感谢!) diff --git a/scripts/autoupdate-bash.sh b/scripts/autoupdate-bash.sh index b501104..f491337 100644 --- a/scripts/autoupdate-bash.sh +++ b/scripts/autoupdate-bash.sh @@ -1,4 +1,11 @@ #!/bin/bash + +get_latest_release() { + curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api + grep '"tag_name":' | # Get tag line + sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value +} + set -e $1 opkg update || true @@ -17,20 +24,12 @@ board_id=$(cat /etc/board.json | jsonfilter -e '@["model"].id' | sed 's/friendly mount -t tmpfs -o remount,size=850m tmpfs /tmp rm -rf /tmp/upg && mkdir /tmp/upg && cd /tmp/upg -md5sum=`wget https://ghproxy.com/https://github.com/klever1988/nanopi-openwrt/releases/download/$(date +%Y-%m-%d)/$board_id$ver.img.gz -O- | tee >(gzip -dc>$board_id.img) | md5sum | awk '{print $1}'` +latest_release_tag=`get_latest_release klever1988/nanopi-openwrt` +echo -e '\e[92m准备更新到'$latest_release_tag'\e[0m' +md5sum=`wget https://ghproxy.com/https://github.com/klever1988/nanopi-openwrt/releases/download/$latest_release_tag/$board_id$ver.img.gz -O- | tee >(gzip -dc>$board_id.img) | md5sum | awk '{print $1}'` if [ "$md5sum" != "d41d8cd98f00b204e9800998ecf8427e" ]; then - wget https://ghproxy.com/https://github.com/klever1988/nanopi-openwrt/releases/download/$(date +%Y-%m-%d)/$board_id$ver.img.gz.md5 -O md5sum.txt - echo -e '\e[92m今天固件已下载,准备解压\e[0m' -else - echo -e '\e[91m今天的固件还没更新,尝试下载昨天的固件\e[0m' - md5sum=`wget https://ghproxy.com/https://github.com/klever1988/nanopi-openwrt/releases/download/$(date -d "@$(( $(busybox date +%s) - 86400))" +%Y-%m-%d)/$board_id$ver.img.gz -O- | tee >(gzip -dc>$board_id.img) | md5sum | awk '{print $1}'` - if [ "$md5sum" != "d41d8cd98f00b204e9800998ecf8427e" ]; then - wget https://ghproxy.com/https://github.com/klever1988/nanopi-openwrt/releases/download/$(date -d "@$(( $(busybox date +%s) - 86400))" +%Y-%m-%d)/$board_id$ver.img.gz.md5 -O md5sum.txt - echo -e '\e[92m昨天的固件已下载,准备解压\e[0m' - else - echo -e '\e[91m没找到最新的固件,脚本退出\e[0m' - exit 1 - fi + wget https://ghproxy.com/https://github.com/klever1988/nanopi-openwrt/releases/download/$latest_release_tag/$board_id$ver.img.gz.md5 -O md5sum.txt + echo -e '\e[92m'$latest_release_tag'固件已下载\e[0m' fi md5r=`awk '{print $1}' md5sum.txt`