mirror of
https://github.com/kenzok8/small-package
synced 2025-09-18 18:51:16 +08:00
update 03-24 09:09
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI support for EasyUpdate From sundaqiang
|
||||
LUCI_DEPENDS:=+bash
|
||||
LUCI_DEPENDS:=+bash +curl
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_VERSION:=1.0
|
||||
PKG_RELEASE:=20211125
|
||||
|
@ -27,6 +27,7 @@ function index()
|
||||
entry({"admin", "services", "easyupdate", "getver"}, call("getver")).leaf = true
|
||||
entry({"admin", "services", "easyupdate", "download"}, call("download")).leaf = true
|
||||
entry({"admin", "services", "easyupdate", "getlog"}, call("getlog")).leaf = true
|
||||
entry({"admin", "services", "easyupdate", "check"}, call("check")).leaf = true
|
||||
entry({"admin", "services", "easyupdate", "flash"}, call("flash")).leaf = true
|
||||
end
|
||||
|
||||
@ -66,23 +67,34 @@ end
|
||||
|
||||
function download()
|
||||
local e={}
|
||||
luci.sys.exec("/usr/bin/easyupdate.sh -d")
|
||||
e.code=1
|
||||
ret=luci.sys.exec("/usr/bin/easyupdate.sh -d")
|
||||
e.data=ret:match("openwrt.+%.img%.gz")
|
||||
e.code=1
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
|
||||
function getlog()
|
||||
local e = {}
|
||||
e.code=1
|
||||
e.data=nixio.fs.readfile ("/tmp/easyupdate.log")
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
|
||||
function check()
|
||||
local e = {}
|
||||
local f = luci.http.formvalue('file')
|
||||
e.code=1
|
||||
e.data=luci.sys.exec("/usr/bin/easyupdate.sh -k " .. f)
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
|
||||
function flash()
|
||||
local e={}
|
||||
local f = luci.http.formvalue('file')
|
||||
luci.sys.exec("/usr/bin/easyupdate.sh -f " .. f)
|
||||
luci.sys.exec("/usr/bin/easyupdate.sh -f /tmp/" .. f)
|
||||
e.code=1
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
|
@ -109,6 +109,14 @@ function getver() {
|
||||
}
|
||||
}
|
||||
);
|
||||
XHR.get('<%=url([[admin]], [[services]], [[easyupdate]], [[check]])%>', {file: ''}, (x, r) => {
|
||||
if (r.code == 1 && r.data.indexOf("OK") > -1) {
|
||||
const tb = document.getElementById('update');
|
||||
tb.setAttribute('file', r.data.slice(0,r.data.indexOf(".img.gz")) + ".img.gz");
|
||||
tb.value = '<%:Firmware Upgrade%>'
|
||||
tb.setAttribute('flash', 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
getver()
|
||||
function check_version() {
|
||||
@ -149,23 +157,31 @@ function check_version() {
|
||||
tb.disabled = true;
|
||||
XHR.get('<%=url([[admin]], [[services]], [[easyupdate]], [[download]])%>', null, (x, r) => {
|
||||
if (r.code == 1) {
|
||||
tb.setAttribute('file', r.data);
|
||||
XHR.poll(1, '<%=url([[admin]], [[services]], [[easyupdate]], [[getlog]])%>', null,(x, r) => {
|
||||
if (r.data.indexOf(" error") > -1 || r.data.indexOf("Connection reset") > -1){
|
||||
if (r.data.indexOf("transfer closed") > -1 || r.data.indexOf("Could not resolve host") > -1){
|
||||
XHR.halt()
|
||||
update_status_message('warning', r.data);
|
||||
document.getElementById('update_apply_overlay').addEventListener("click", (e)=>{
|
||||
update_status_message()
|
||||
})
|
||||
}else{
|
||||
if (r.data.indexOf("Download completed") > -1 ){
|
||||
XHR.halt()
|
||||
setTimeout(() => {
|
||||
update_status_message();
|
||||
tb.value = '<%:Firmware Upgrade%>'
|
||||
tb.setAttribute('flash', 1);
|
||||
const file = r.data.match(/Writing to '([^\s]+img.gz)'/);
|
||||
tb.setAttribute('file', file[1]);
|
||||
},3000);
|
||||
if (/100\s.+M\s+100.+--:--:--/.test(r.data)){
|
||||
XHR.get('<%=url([[admin]], [[services]], [[easyupdate]], [[check]])%>', {file: tb.getAttribute("file")}, (x, r) => {
|
||||
XHR.halt()
|
||||
if (r.code == 1 && r.data.indexOf("OK") > -1) {
|
||||
setTimeout(() => {
|
||||
update_status_message();
|
||||
tb.value = '<%:Firmware Upgrade%>'
|
||||
tb.setAttribute('flash', 1);
|
||||
},3000);
|
||||
}else{
|
||||
update_status_message('warning', r.data);
|
||||
document.getElementById('update_apply_overlay').addEventListener("click", (e)=>{
|
||||
update_status_message()
|
||||
})
|
||||
}
|
||||
});
|
||||
}else{
|
||||
update_status_message('notice', r.data);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ function getCloudVer() {
|
||||
checkEnv
|
||||
github=$(uci get easyupdate.main.github)
|
||||
github=(${github//// })
|
||||
uclient-fetch -qO- "https://api.github.com/repos/${github[2]}/${github[3]}/releases/latest" | jsonfilter -e '@.tag_name' | sed -e 's/OpenWrt_//'
|
||||
curl "https://api.github.com/repos/${github[2]}/${github[3]}/releases/latest" | jsonfilter -e '@.tag_name' | sed -e 's/OpenWrt_//'
|
||||
}
|
||||
|
||||
function downCloudVer() {
|
||||
@ -48,7 +48,7 @@ function downCloudVer() {
|
||||
fi
|
||||
writeLog "Whether EFI firmware is available(是否EFI固件):$suffix"
|
||||
writeLog 'Get the cloud firmware link(获取云端固件链接)'
|
||||
url=$(uclient-fetch -qO- "https://api.github.com/repos/${github[2]}/${github[3]}/releases/latest" | jsonfilter -e '@.assets[*].browser_download_url' | sed -n "/$suffix/p")
|
||||
url=$(curl "https://api.github.com/repos/${github[2]}/${github[3]}/releases/latest" | jsonfilter -e '@.assets[*].browser_download_url' | sed -n "/$suffix/p")
|
||||
writeLog "Cloud firmware link(云端固件链接):$url"
|
||||
writeLog 'Get whether to use Chinese mirror(读取是否使用中国镜像)'
|
||||
proxy=$(uci get easyupdate.main.proxy)
|
||||
@ -60,9 +60,10 @@ function downCloudVer() {
|
||||
res='no'
|
||||
fi
|
||||
writeLog "Whether to use Chinese mirror(是否使用中国镜像):$res"
|
||||
writeLog 'Start downloading firmware, log output in /tmp/easyupdate.log(开始下载固件,日志输出在/tmp/easyupdate.log)'
|
||||
fileName=(${url//// })
|
||||
uclient-fetch -O "/tmp/${fileName[7]}" "$proxy$url" >/tmp/easyupdate.log 2>&1 &
|
||||
curl -o "/tmp/${fileName[7]}-sha256" "$proxy${url/${fileName[7]}/sha256sums}"
|
||||
curl -o "/tmp/${fileName[7]}" "$proxy$url" >/tmp/easyupdate.log 2>&1 &
|
||||
writeLog 'Start downloading firmware, log output in /tmp/easyupdate.log(开始下载固件,日志输出在/tmp/easyupdate.log)'
|
||||
}
|
||||
|
||||
function flashFirmware() {
|
||||
@ -85,6 +86,18 @@ function flashFirmware() {
|
||||
fi
|
||||
}
|
||||
|
||||
function checkSha() {
|
||||
if [[ -z "$file" ]]; then
|
||||
for filename in $(ls /tmp)
|
||||
do
|
||||
if [[ "${filename#*.}" = "img.gz" && "${filename:0:7}" = "openwrt" ]]; then
|
||||
file=$filename
|
||||
fi
|
||||
done
|
||||
fi
|
||||
cd /tmp && sha256sum -c <(grep $file $file-sha256)
|
||||
}
|
||||
|
||||
function updateCloud() {
|
||||
checkEnv
|
||||
writeLog 'Get the local firmware version(获取本地固件版本)'
|
||||
@ -97,43 +110,56 @@ function updateCloud() {
|
||||
cFirVer=$(date -d "${cFirVer:0:4}-${cFirVer:4:2}-${cFirVer:6:2} ${cFirVer:9:2}:${cFirVer:11:2}:${cFirVer:13:2}" +%s)
|
||||
if [ $cFirVer -gt $lFirVer ]; then
|
||||
writeLog 'Need to be updated(需要更新)'
|
||||
downCloudVer
|
||||
i=0
|
||||
while [ $i -le 100 ]; do
|
||||
log=$(cat /tmp/easyupdate.log)
|
||||
str=' error'
|
||||
if [[ $log =~ $str ]]; then
|
||||
writeLog 'Download error(下载出错)'
|
||||
i=101
|
||||
break
|
||||
else
|
||||
str='Connection reset'
|
||||
checkShaRet=$(checkSha)
|
||||
if [[ $checkShaRet =~ 'OK' ]]; then
|
||||
writeLog 'Check completes(检查完成)'
|
||||
file=${checkShaRet:0:-4}
|
||||
flashFirmware
|
||||
else
|
||||
downCloudVer
|
||||
i=0
|
||||
while [ $i -le 100 ]; do
|
||||
log=$(cat /tmp/easyupdate.log)
|
||||
str='transfer closed'
|
||||
if [[ $log =~ $str ]]; then
|
||||
writeLog 'Download error(下载出错)'
|
||||
i=101
|
||||
break
|
||||
else
|
||||
str='Download completed'
|
||||
str='Could not resolve host'
|
||||
if [[ $log =~ $str ]]; then
|
||||
writeLog 'Download completes(下载完成)'
|
||||
i=100
|
||||
writeLog 'Download error(下载出错)'
|
||||
i=101
|
||||
break
|
||||
else
|
||||
echo $log | sed -n '$p'
|
||||
if [[ $i -eq 99 ]]; then
|
||||
writeLog 'Download the timeout(下载超时)'
|
||||
str='100\s.+M\s+100.+--:--:--'
|
||||
if [[ $log =~ $str ]]; then
|
||||
writeLog 'Download completes(下载完成)'
|
||||
i=100
|
||||
break
|
||||
else
|
||||
echo $log | sed -n '$p'
|
||||
if [[ $i -eq 99 ]]; then
|
||||
writeLog 'Download the timeout(下载超时)'
|
||||
break
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
let i++
|
||||
sleep 3
|
||||
done
|
||||
if [[ $i -eq 100 ]]; then
|
||||
writeLog 'Prepare flash firmware(准备刷写固件)'
|
||||
checkShaRet=$(checkSha)
|
||||
if [[ $checkShaRet =~ 'OK' ]]; then
|
||||
writeLog 'Check completes(检查完成)'
|
||||
file=${checkShaRet:0:-4}
|
||||
flashFirmware
|
||||
else
|
||||
writeLog 'Check error(检查出错)'
|
||||
fi
|
||||
fi
|
||||
i++
|
||||
sleep 3
|
||||
done
|
||||
if [[ $i -eq 100 ]]; then
|
||||
writeLog 'Prepare flash firmware(准备刷写固件)'
|
||||
file=$(cat /tmp/easyupdate.log | sed -n "s/Writing to '\(.*\)'/\1/p")
|
||||
flashFirmware
|
||||
fi
|
||||
else
|
||||
writeLog "Is the latest(已是最新)"
|
||||
@ -154,6 +180,10 @@ else
|
||||
file=$2
|
||||
flashFirmware
|
||||
;;
|
||||
-k)
|
||||
file=$2
|
||||
checkSha
|
||||
;;
|
||||
-u)
|
||||
updateCloud
|
||||
;;
|
||||
@ -161,4 +191,4 @@ else
|
||||
shellHelp
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
Reference in New Issue
Block a user