mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-18 17:33:31 +00:00
luci-app-unblockmusic: add auto update core js
This commit is contained in:
parent
099f6cbb8a
commit
9f169a17d3
@ -43,6 +43,8 @@ endef
|
||||
|
||||
define Build/Prepare
|
||||
tar -xzvf $(DL_DIR)/$(PKG_SOURCE) -C $(PKG_BUILD_DIR)
|
||||
echo -e $(PKG_VERSION) > $(PKG_BUILD_DIR)/UnblockNeteaseMusic/core_ver
|
||||
echo -e $(PKG_SOURCE_VERSION) > $(PKG_BUILD_DIR)/UnblockNeteaseMusic/local_ver
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
|
@ -11,12 +11,12 @@ include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-unblockmusic
|
||||
PKG_VERSION:=2.2.0
|
||||
PKG_RELEASE:=5
|
||||
PKG_RELEASE:=8
|
||||
|
||||
PKG_LICENSE:=Apache-2.0
|
||||
|
||||
LUCI_TITLE:=LuCI support for Unblock NeteaseCloudMusic
|
||||
LUCI_DEPENDS:=+UnblockNeteaseMusic +bash +dnsmasq-full +ipset
|
||||
LUCI_DEPENDS:=+UnblockNeteaseMusic +bash +dnsmasq-full +ipset +bash
|
||||
LUCI_PKGARCH:=all
|
||||
|
||||
PKG_MAINTAINER:=lean
|
||||
|
@ -32,7 +32,7 @@ endpoint.description = translate("默认为 https://music.163.com")
|
||||
o = s:option(Button,"certificate",translate("HTTPS 证书"))
|
||||
o.inputtitle = translate("下载 CA 根证书")
|
||||
o.description = translate("iOS 13 系统需要在“设置 -> 通用 -> 关于本机 -> 证书信任设置” 中,信任 UnblockNeteaseMusic Root CA )")
|
||||
o.inputstyle = "reload"
|
||||
o.inputstyle = "apply"
|
||||
o.write = function()
|
||||
Download()
|
||||
end
|
||||
@ -54,4 +54,21 @@ function Download()
|
||||
luci.http.close()
|
||||
end
|
||||
|
||||
o = s:option(Flag, "autoupdate")
|
||||
o.title = translate("自动检查更新主程序")
|
||||
o.default = 0
|
||||
o.rmempty = false
|
||||
o.description = translate("每天自动检测并更新到最新版本")
|
||||
|
||||
local ver = luci.sys.exec("cat /usr/share/UnblockNeteaseMusic/core_ver")
|
||||
|
||||
o = s:option(Button, "restart",translate("手动更新"))
|
||||
o.inputtitle = translate("更新核心版本")
|
||||
o.description = string.format(translate("目前运行主程序版本") .. "<strong><font color=\"green\">: %s </font></strong>", ver)
|
||||
o.inputstyle = "reload"
|
||||
o.write = function()
|
||||
luci.sys.exec("bash /usr/share/UnblockNeteaseMusic/update_core.sh 2>&1")
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "unblockmusic"))
|
||||
end
|
||||
|
||||
return mp
|
||||
|
@ -5,5 +5,6 @@ config unblockmusic
|
||||
option port '5200'
|
||||
option enable_ipset '1'
|
||||
option endpoint 'https://music.163.com'
|
||||
option autoupdate '1'
|
||||
|
||||
|
||||
|
@ -7,6 +7,9 @@ enable=$(uci get unblockmusic.@unblockmusic[0].enabled)
|
||||
TYPE=$(uci get unblockmusic.@unblockmusic[0].musicapptype)
|
||||
ROUTE_IP=$(uci get network.lan.ipaddr)
|
||||
ENDPOINT=$(uci get unblockmusic.@unblockmusic[0].endpoint)
|
||||
AUTOUPDATE=$(uci get unblockmusic.@unblockmusic[0].autoupdate)
|
||||
|
||||
CRON_FILE=/etc/crontabs/root
|
||||
|
||||
ipt_n="iptables -t nat"
|
||||
|
||||
@ -51,6 +54,21 @@ set_firewall(){
|
||||
EOF
|
||||
}
|
||||
|
||||
add_cron()
|
||||
{
|
||||
if [ $AUTOUPDATE -eq 1 ]; then
|
||||
sed -i '/update_core.sh/d' $CRON_FILE
|
||||
echo '0 2 * * * /usr/share/UnblockNeteaseMusic/update_core.sh 2>&1' >> $CRON_FILE
|
||||
crontab $CRON_FILE
|
||||
fi
|
||||
}
|
||||
|
||||
del_cron()
|
||||
{
|
||||
sed -i '/update_core.sh/d' $CRON_FILE
|
||||
/etc/init.d/cron restart
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
stop
|
||||
@ -70,6 +88,7 @@ start()
|
||||
fi
|
||||
|
||||
set_firewall
|
||||
add_cron
|
||||
|
||||
/usr/share/UnblockNeteaseMusic/logcheck.sh >/dev/null 2>&1 &
|
||||
}
|
||||
@ -82,6 +101,7 @@ stop()
|
||||
rm -f /tmp/unblockmusic.log
|
||||
|
||||
del_rule
|
||||
del_cron
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,64 @@
|
||||
|
||||
|
||||
function check_if_already_running(){
|
||||
running_tasks="$(ps |grep "unblockneteasemusic" |grep "update_core" |grep -v "grep" |awk '{print $1}' |wc -l)"
|
||||
[ "${running_tasks}" -gt "2" ] && echo -e "\nA task is already running." >>/tmp/unblockmusic_update.log && exit 2
|
||||
}
|
||||
|
||||
function clean_log(){
|
||||
echo "" > /tmp/unblockmusic_update.log
|
||||
}
|
||||
|
||||
function check_latest_version(){
|
||||
latest_ver="$(wget -O- https://github.com/nondanee/UnblockNeteaseMusic/commits/master |tr -d '\n' |grep -Eo 'commit\/[0-9a-z]+' |sed -n 1p |sed 's#commit/##g')"
|
||||
[ -z "${latest_ver}" ] && echo -e "\nFailed to check latest version, please try again later." >>/tmp/unblockmusic_update.log && exit 1
|
||||
if [ ! -e "/usr/share/UnblockNeteaseMusic/local_ver" ]; then
|
||||
clean_log
|
||||
echo -e "Local version: NOT FOUND, cloud version: ${latest_ver}." >>/tmp/unblockmusic_update.log
|
||||
update_core
|
||||
else
|
||||
if [ "$(cat /usr/share/UnblockNeteaseMusic/local_ver)" != "${latest_ver}" ]; then
|
||||
clean_log
|
||||
echo -e "Local version: $(cat /usr/share/UnblockNeteaseMusic/local_ver 2>/dev/null), cloud version: ${latest_ver}." >>/tmp/unblockmusic_update.log
|
||||
update_core
|
||||
else
|
||||
echo -e "\nLocal version: $(cat /usr/share/UnblockNeteaseMusic/local_ver 2>/dev/null), cloud version: ${latest_ver}." >>/tmp/unblockmusic_update.log
|
||||
echo -e "You're already using the latest version." >>/tmp/unblockmusic_update.log
|
||||
exit 3
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function update_core(){
|
||||
echo -e "Updating core..." >>/tmp/unblockmusic_update.log
|
||||
|
||||
mkdir -p "/tmp/unblockneteasemusic/core" >/dev/null 2>&1
|
||||
rm -rf /tmp/unblockneteasemusic/core/* >/dev/null 2>&1
|
||||
|
||||
wget-ssl --no-check-certificate -t 1 -T 10 -O /tmp/unblockneteasemusic/core/core.tar.gz "https://github.com/nondanee/UnblockNeteaseMusic/archive/master.tar.gz" >/dev/null 2>&1
|
||||
tar -zxf "/tmp/unblockneteasemusic/core/core.tar.gz" -C "/tmp/unblockneteasemusic/core/" >/dev/null 2>&1
|
||||
rm -f /tmp/unblockneteasemusic/core/UnblockNeteaseMusic-master/ca.crt /tmp/unblockneteasemusic/core/UnblockNeteaseMusic-master/server.crt /tmp/unblockneteasemusic/core/UnblockNeteaseMusic-master/server.key
|
||||
cp -a /tmp/unblockneteasemusic/core/UnblockNeteaseMusic-master/* "/usr/share/UnblockNeteaseMusic/"
|
||||
rm -rf "/tmp/unblockneteasemusic" >/dev/null 2>&1
|
||||
|
||||
if [ ! -e "/usr/share/UnblockNeteaseMusic/app.js" ]; then
|
||||
echo -e "Failed to download core." >>/tmp/unblockmusic_update.log
|
||||
exit 1
|
||||
else
|
||||
[ "${luci_update}" == "y" ] && touch "/usr/share/unblockneteasemusic/update_successfully"
|
||||
echo -e "${latest_ver}" > /usr/share/UnblockNeteaseMusic/local_ver
|
||||
/etc/init.d/unblockmusic restart
|
||||
fi
|
||||
|
||||
echo -e "Succeeded in updating core." >/tmp/unblockmusic_update.log
|
||||
echo -e "Local version: $(cat /usr/share/UnblockNeteaseMusic/local_ver 2>/dev/null), cloud version: ${latest_ver}.\n" >>/tmp/unblockmusic_update.log
|
||||
node /usr/share/UnblockNeteaseMusic/app.js -v > /usr/share/UnblockNeteaseMusic/core_ver
|
||||
}
|
||||
|
||||
function main(){
|
||||
check_if_already_running
|
||||
check_latest_version
|
||||
}
|
||||
|
||||
[ "$1" == "luci_update" ] && luci_update="y"
|
||||
main
|
Loading…
Reference in New Issue
Block a user