luci-app-unblockneteasemusic: bump to 2.7
This commit is contained in:
parent
dcb3e4eb62
commit
0334d5b436
@ -11,8 +11,8 @@ LUCI_TITLE:=LuCI support for UnblockNeteaseMusic
|
||||
LUCI_DEPENDS:=+bash +busybox +coreutils-nohup +curl +dnsmasq-full +ipset +libopenssl +node
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_NAME:=luci-app-unblockneteasemusic
|
||||
PKG_VERSION:=2.6
|
||||
PKG_RELEASE:=3
|
||||
PKG_VERSION:=2.7
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_MAINTAINER:=[CTCGFW]Project-OpenWrt
|
||||
|
||||
|
||||
@ -12,10 +12,11 @@ function index()
|
||||
entry({"admin", "services", "unblockneteasemusic"},firstchild(), _("解除网易云音乐播放限制"), 50).dependent = false
|
||||
|
||||
entry({"admin", "services", "unblockneteasemusic", "general"},cbi("unblockneteasemusic"), _("基本设定"), 1)
|
||||
entry({"admin", "services", "unblockneteasemusic", "upgrade_core"},form("unblockneteasemusic_upcore"), _("更新核心"), 2).leaf = true
|
||||
entry({"admin", "services", "unblockneteasemusic", "upgrade"},form("unblockneteasemusic_upgrade"), _("更新组件"), 2).leaf = true
|
||||
entry({"admin", "services", "unblockneteasemusic", "log"},form("unblockneteasemusiclog"), _("日志"), 3)
|
||||
|
||||
entry({"admin", "services", "unblockneteasemusic", "status"},call("act_status")).leaf=true
|
||||
entry({"admin", "services", "unblockneteasemusic", "update_luci"},call("act_update_luci"))
|
||||
entry({"admin", "services", "unblockneteasemusic", "update_core"},call("act_update_core"))
|
||||
end
|
||||
|
||||
@ -26,21 +27,49 @@ function act_status()
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
|
||||
function update_core()
|
||||
cloud_ver=luci.sys.exec("curl -s 'https://github.com/nondanee/UnblockNeteaseMusic/commits/master' |tr -d '\n' |grep -Eo 'commit\/[0-9a-z]+' |sed -n 1p |sed 's#commit/##g'")
|
||||
cloud_ver_mini=luci.sys.exec("curl -s 'https://github.com/nondanee/UnblockNeteaseMusic/commits/master' |tr -d '\n' |grep -Eo 'BtnGroup-item.> [0-9a-z]+' |sed -n 1p |sed 's#BtnGroup-item.> ##g'")
|
||||
if not cloud_ver or not cloud_ver_mini then
|
||||
function update_luci()
|
||||
luci_cloud_ver=luci.sys.exec("curl -s 'https://github.com/project-openwrt/luci-app-unblockneteasemusic/releases/latest'| grep -Eo '[0-9\.]+\-[0-9]+'")
|
||||
if not luci_cloud_ver then
|
||||
return "1"
|
||||
else
|
||||
local_ver=luci.sys.exec("cat '/usr/share/unblockneteasemusic/local_ver'")
|
||||
if not local_ver or (local_ver ~= cloud_ver) then
|
||||
luci.sys.call("rm -f /usr/share/unblockneteasemusic/update_successfully")
|
||||
luci.sys.call("/bin/bash /usr/share/unblockneteasemusic/update_core.sh luci_update")
|
||||
if not nixio.fs.access("/usr/share/unblockneteasemusic/update_successfully") then
|
||||
luci_local_ver=luci.sys.exec("opkg info 'luci-app-unblockneteasemusic' |sed -n '2p' |tr -d 'Version: '")
|
||||
if not luci_local_ver or (luci_local_ver ~= luci_cloud_ver) then
|
||||
luci.sys.call("rm -f /usr/share/unblockneteasemusic/update_luci_successfully")
|
||||
luci.sys.call("/bin/bash /usr/share/unblockneteasemusic/update.sh update_luci")
|
||||
if not nixio.fs.access("/usr/share/unblockneteasemusic/update_luci_successfully") then
|
||||
return "2"
|
||||
else
|
||||
luci.sys.call("rm -f /usr/share/unblockneteasemusic/update_successfully")
|
||||
return cloud_ver_mini
|
||||
luci.sys.call("rm -f /usr/share/unblockneteasemusic/update_luci_successfully")
|
||||
return luci_cloud_ver
|
||||
end
|
||||
else
|
||||
return "0"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function act_update_luci()
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json({
|
||||
ret = update_luci();
|
||||
})
|
||||
end
|
||||
|
||||
function update_core()
|
||||
core_cloud_ver=luci.sys.exec("curl -s 'https://github.com/nondanee/UnblockNeteaseMusic/commits/master' |tr -d '\n' |grep -Eo 'commit\/[0-9a-z]+' |sed -n 1p |sed 's#commit/##g'")
|
||||
core_cloud_ver_mini=luci.sys.exec("curl -s 'https://github.com/nondanee/UnblockNeteaseMusic/commits/master' |tr -d '\n' |grep -Eo 'BtnGroup-item.> [0-9a-z]+' |sed -n 1p |sed 's#BtnGroup-item.> ##g'")
|
||||
if not core_cloud_ver or not core_cloud_ver_mini then
|
||||
return "1"
|
||||
else
|
||||
core_local_ver=luci.sys.exec("cat '/usr/share/unblockneteasemusic/core_local_ver'")
|
||||
if not core_local_ver or (core_local_ver ~= core_cloud_ver) then
|
||||
luci.sys.call("rm -f /usr/share/unblockneteasemusic/update_core_successfully")
|
||||
luci.sys.call("/bin/bash /usr/share/unblockneteasemusic/update.sh update_core_from_luci")
|
||||
if not nixio.fs.access("/usr/share/unblockneteasemusic/update_core_successfully") then
|
||||
return "2"
|
||||
else
|
||||
luci.sys.call("rm -f /usr/share/unblockneteasemusic/update_core_successfully")
|
||||
return core_cloud_ver_mini
|
||||
end
|
||||
else
|
||||
return "0"
|
||||
@ -53,4 +82,4 @@ function act_update_core()
|
||||
luci.http.write_json({
|
||||
ret = update_core();
|
||||
})
|
||||
end
|
||||
end
|
||||
@ -48,7 +48,7 @@ hijack = s:option(ListValue, "hijack_ways", translate("劫持方法"))
|
||||
hijack:value("dont_hijack", translate("不开启劫持"))
|
||||
hijack:value("use_ipset", translate("使用IPSet劫持"))
|
||||
hijack:value("use_hosts", translate("使用Hosts劫持"))
|
||||
hijack.description = translate("如果使用Hosts劫持,主实例的HTTP/HTTPS端口将被锁定为80/443")
|
||||
hijack.description = translate("如果使用Hosts劫持,程序监听的HTTP/HTTPS端口将被锁定为80/443")
|
||||
hijack.default = "dont_hijack"
|
||||
hijack.rmempty = false
|
||||
|
||||
@ -103,7 +103,7 @@ pub_access.rmempty = false
|
||||
pub_access:depends("advanced_mode", 1)
|
||||
|
||||
strict_mode = s:option(Flag, "strict_mode", translate("启用严格模式"))
|
||||
strict_mode.description = translate("若将服务部署到公网,则强烈建议使用严格模式,此模式下仅放行网易云音乐所属域名的请求;注意:该模式下只能使用PAC方式进行代理")
|
||||
strict_mode.description = translate("若将服务部署到公网,则强烈建议使用严格模式,此模式下仅放行网易云音乐所属域名的请求;注意:该模式下不能使用全局代理")
|
||||
strict_mode.default = 0
|
||||
strict_mode.rmempty = false
|
||||
strict_mode:depends("advanced_mode", 1)
|
||||
@ -112,7 +112,6 @@ netease_server_ip = s:option(Value, "netease_server_ip", translate("网易云服
|
||||
netease_server_ip.description = translate("通过 ping music.163.com 即可获得IP地址,仅限填写一个")
|
||||
netease_server_ip.placeholder = "59.111.181.38"
|
||||
netease_server_ip.datatype = "ipaddr"
|
||||
netease_server_ip:depends("set_netease_server_ip", 1)
|
||||
netease_server_ip:depends("advanced_mode", 1)
|
||||
|
||||
proxy_server_ip = s:option(Value, "proxy_server_ip", translate("代理服务器地址"))
|
||||
@ -121,4 +120,16 @@ proxy_server_ip.placeholder = "http(s)://host:port"
|
||||
proxy_server_ip.datatype = "string"
|
||||
proxy_server_ip:depends("advanced_mode", 1)
|
||||
|
||||
self_issue_cert_crt = s:option(Value, "self_issue_cert_crt", translate("自签发证书公钥位置"))
|
||||
self_issue_cert_crt.description = translate("[公钥] 默认使用UnblockNeteaseMusic项目提供的CA证书,您可以指定为您自己的证书")
|
||||
self_issue_cert_crt.placeholder = "/usr/share/unblockneteasemusic/core/server.crt"
|
||||
self_issue_cert_crt.datatype = "file"
|
||||
self_issue_cert_crt:depends("advanced_mode", 1)
|
||||
|
||||
self_issue_cert_key = s:option(Value, "self_issue_cert_key", translate("自签发证书私钥位置"))
|
||||
self_issue_cert_key.description = translate("[私钥] 默认使用UnblockNeteaseMusic项目提供的CA证书,您可以指定为您自己的证书")
|
||||
self_issue_cert_key.placeholder = "/usr/share/unblockneteasemusic/core/server.key"
|
||||
self_issue_cert_key.datatype = "file"
|
||||
self_issue_cert_key:depends("advanced_mode", 1)
|
||||
|
||||
return mp
|
||||
|
||||
@ -4,6 +4,12 @@ m = SimpleForm("Version")
|
||||
m.reset = false
|
||||
m.submit = false
|
||||
|
||||
up_core=m:field(DummyValue,"update_luci",translate("更新LuCI"))
|
||||
up_core.rawhtml = true
|
||||
up_core.template = "unblockneteasemusic/update_luci"
|
||||
up_core.value = translate("未检查")
|
||||
up_core.description = "更新完毕后请手动刷新该界面"
|
||||
|
||||
up_core=m:field(DummyValue,"update_core",translate("更新主程序"))
|
||||
up_core.rawhtml = true
|
||||
up_core.template = "unblockneteasemusic/update_core"
|
||||
@ -0,0 +1,36 @@
|
||||
<%+cbi/valueheader%>
|
||||
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
function act_update_luci(btn,dataname)
|
||||
{
|
||||
btn.disabled = true;
|
||||
btn.value = '<%:正在更新LuCI...%> ';
|
||||
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "unblockneteasemusic","update_luci")%>',
|
||||
status.ret,
|
||||
function(x,status)
|
||||
{
|
||||
var s = document.getElementById(dataname+'-status');
|
||||
if (s)
|
||||
{
|
||||
if(status.ret=="0")
|
||||
s.innerHTML ="<font color='green'>"+"<%:当前已是最新版本%>"+"</font>";
|
||||
else if (status.ret=="1")
|
||||
s.innerHTML ="<font color='red'>"+"<%:无法检测最新版本%>"+"</font>";
|
||||
else if(status.ret=="2")
|
||||
s.innerHTML ="<font color='red'>"+"<%:更新失败,请稍后重试%>"+"</font>";
|
||||
else
|
||||
s.innerHTML ="<font color='green'>"+"<%:更新成功,当前版本号:%>"+status.ret+"</font>";
|
||||
}
|
||||
btn.disabled = false;
|
||||
btn.value = '<%:点此更新LuCI%>';
|
||||
}
|
||||
);
|
||||
return false;
|
||||
}
|
||||
//]]></script>
|
||||
|
||||
|
||||
<input type="button" class="cbi-button cbi-input-reload" value="<%:点此更新LuCI%> " onclick="return act_update_luci(this,'<%=self.option%>')" />
|
||||
<span id="<%=self.option%>-status"><em><%=self.value%></em></span>
|
||||
|
||||
<%+cbi/valuefooter%>
|
||||
@ -17,3 +17,5 @@ config unblockneteasemusic
|
||||
option strict_mode '0'
|
||||
option netease_server_ip '59.111.181.38'
|
||||
option proxy_server_ip ''
|
||||
option self_issue_cert_crt '/usr/share/unblockneteasemusic/core/server.crt'
|
||||
option self_issue_cert_key '/usr/share/unblockneteasemusic/core/server.key'
|
||||
|
||||
@ -31,6 +31,9 @@ netease_server_ip="$(uci get unblockneteasemusic.@unblockneteasemusic[0].netease
|
||||
proxy_server_ip="$(uci get unblockneteasemusic.@unblockneteasemusic[0].proxy_server_ip 2>"/dev/null")"
|
||||
[ -n "${proxy_server_ip}" ] && proxy_server_ip="-u ${proxy_server_ip}"
|
||||
|
||||
self_issue_cert_crt="$(uci get unblockneteasemusic.@unblockneteasemusic[0].self_issue_cert_crt 2>"/dev/null")"
|
||||
self_issue_cert_key="$(uci get unblockneteasemusic.@unblockneteasemusic[0].self_issue_cert_key 2>"/dev/null")"
|
||||
|
||||
set_ipset(){
|
||||
if [ "${set_type}" = "start" ]; then
|
||||
mkdir -p "/tmp/dnsmasq.d"
|
||||
@ -119,7 +122,7 @@ start()
|
||||
|
||||
[ "${enable}" -ne "1" ] && exit 0
|
||||
|
||||
[ ! -e "/usr/share/unblockneteasemusic/core/app.js" ] && rm -f "/usr/share/unblockneteasemusic/local_ver" && bash "/usr/share/unblockneteasemusic/update_core.sh"
|
||||
[ ! -e "/usr/share/unblockneteasemusic/core/app.js" ] && rm -f "/usr/share/unblockneteasemusic/local_ver" && bash "/usr/share/unblockneteasemusic/update.sh" "update_core_non_restart"
|
||||
[ ! -e "/usr/share/unblockneteasemusic/core/app.js" ] && echo "Core Not Found, please download it before starting." >> "/tmp/unblockneteasemusic.log" && exit 1
|
||||
|
||||
if [ "${music_source}" = "qq" ];then
|
||||
@ -133,6 +136,9 @@ start()
|
||||
sed -i -e "1i const key = '${youtube_key}'" "/usr/share/unblockneteasemusic/core/provider/youtube.js"
|
||||
fi
|
||||
|
||||
[ -f "${self_issue_cert_crt}" ] && { [ "${self_issue_cert_crt}" != "/usr/share/unblockneteasemusic/core/server.crt" ] && ln -sf "${self_issue_cert_crt}" "/usr/share/unblockneteasemusic/core/server.crt"; }
|
||||
[ -f "${self_issue_cert_key}" ] && { [ "${self_issue_cert_key}" != "/usr/share/unblockneteasemusic/core/server.key" ] && ln -sf "${self_issue_cert_key}" "/usr/share/unblockneteasemusic/core/server.key"; }
|
||||
|
||||
[ "${hijack_ways}" = "use_hosts" ] && { http_port="80"; https_port="443"; }
|
||||
if [ "${music_source}" = "default" ]; then
|
||||
nohup node "/usr/share/unblockneteasemusic/core/app.js" -a "${addr}" -p "${http_port}":"${https_port}" -e "${endpoint_url}" ${netease_server_ip} ${proxy_server_ip} ${strict_mode} >> "/tmp/unblockneteasemusic.log" 2>&1 &
|
||||
@ -150,7 +156,7 @@ start()
|
||||
[ "*$(uci get unblockneteasemusic.@unblockneteasemusic[0].pub_access 2>"/dev/null")*" = "*1*" ] && set_ports > "/dev/null" 2>&1
|
||||
|
||||
sed -i '/unblockneteasemusic/d' /etc/crontabs/root
|
||||
[ "${auto_update}" -eq "1" ] && echo "0 ${update_time} * * * /usr/share/unblockneteasemusic/update_core.sh" >> "/etc/crontabs/root"
|
||||
[ "${auto_update}" -eq "1" ] && echo "0 ${update_time} * * * /usr/share/unblockneteasemusic/update.sh update_core" >> "/etc/crontabs/root"
|
||||
echo "*/5 * * * * /usr/share/unblockneteasemusic/log_check.sh" >> "/etc/crontabs/root"
|
||||
/etc/init.d/cron restart > "/dev/null" 2>&1
|
||||
}
|
||||
|
||||
@ -0,0 +1,120 @@
|
||||
#!/bin/bash
|
||||
# Created By [CTCGFW]Project OpenWRT
|
||||
# https://github.com/project-openwrt
|
||||
|
||||
function check_core_if_already_running(){
|
||||
running_tasks="$(ps |grep "unblockneteasemusic" |grep "update" |grep "core" |grep -v "grep" |awk '{print $1}' |wc -l)"
|
||||
[ "${running_tasks}" -gt "2" ] && echo -e "\nA task is already running." >>/tmp/unblockneteasemusic.log && exit 2
|
||||
}
|
||||
|
||||
function check_luci_if_already_running(){
|
||||
running_tasks="$(ps |grep "unblockneteasemusic" |grep "update" |grep "update_luci" |grep -v "grep" |awk '{print $1}' |wc -l)"
|
||||
[ "${running_tasks}" -gt "2" ] && echo -e "\nA task is already running." >>/tmp/unblockneteasemusic.log && exit 2
|
||||
}
|
||||
|
||||
function clean_log(){
|
||||
echo "" > /tmp/unblockneteasemusic.log
|
||||
}
|
||||
|
||||
function check_luci_latest_version(){
|
||||
luci_latest_ver="$(curl -s 'https://github.com/project-openwrt/luci-app-unblockneteasemusic/releases/latest'| grep -Eo '[0-9\.]+\-[0-9]+')"
|
||||
[ -z "${luci_latest_ver}" ] && echo -e "\nFailed to check latest LuCI version, please try again later." >>/tmp/unblockneteasemusic.log && exit 1
|
||||
if [ "$(opkg info 'luci-app-unblockneteasemusic' |sed -n '2p' |tr -d 'Version: ')" != "${luci_latest_ver}" ]; then
|
||||
clean_log
|
||||
echo -e "Local LuCI version: $(opkg info 'luci-app-unblockneteasemusic' |sed -n '2p' |tr -d 'Version: '), cloud LuCI version: ${luci_latest_ver}." >>/tmp/unblockneteasemusic.log
|
||||
update_luci
|
||||
else
|
||||
echo -e "\nLocal LuCI version: $(opkg info 'luci-app-unblockneteasemusic' |sed -n '2p' |tr -d 'Version: '), cloud LuCI version: ${luci_latest_ver}." >>/tmp/unblockneteasemusic.log
|
||||
echo -e "You're already using the latest LuCI version." >>/tmp/unblockneteasemusic.log
|
||||
exit 3
|
||||
fi
|
||||
}
|
||||
|
||||
function update_luci(){
|
||||
echo -e "Updating LuCI..." >>/tmp/unblockneteasemusic.log
|
||||
|
||||
mkdir -p "/tmp" >/dev/null 2>&1
|
||||
|
||||
curl -sL "https://github.com/project-openwrt/luci-app-unblockneteasemusic/releases/download/v${luci_latest_ver}/luci-app-unblockneteasemusic_${luci_latest_ver}_all.ipk" -o "/tmp/luci-app-unblockneteasemusic_${luci_latest_ver}_all.ipk" >/dev/null 2>&1
|
||||
opkg install "/tmp/luci-app-unblockneteasemusic_${luci_latest_ver}_all.ipk"
|
||||
rm -f "/tmp/luci-app-unblockneteasemusic_${luci_latest_ver}_all.ipk"
|
||||
rm -rf "/tmp/luci-indexcache" "/tmp/luci-modulecache"
|
||||
|
||||
if [ "$(opkg info 'luci-app-unblockneteasemusic' |sed -n '2p' |tr -d 'Version: ')" != "$1" ]; then
|
||||
echo -e "Failed to update LuCI." >>/tmp/unblockneteasemusic.log
|
||||
exit 1
|
||||
else
|
||||
touch "/usr/share/unblockneteasemusic/update_luci_successfully"
|
||||
fi
|
||||
|
||||
echo -e "Succeeded in updating LuCI." >/tmp/unblockneteasemusic.log
|
||||
echo -e "Current LuCI version: ${luci_latest_ver}.\n" >>/tmp/unblockneteasemusic.log
|
||||
}
|
||||
|
||||
function check_core_latest_version(){
|
||||
core_latest_ver="$(curl -s https://github.com/nondanee/UnblockNeteaseMusic/commits/master |tr -d '\n' |grep -Eo 'commit\/[0-9a-z]+' |sed -n 1p |sed 's#commit/##g')"
|
||||
[ -z "${core_latest_ver}" ] && echo -e "\nFailed to check latest core version, please try again later." >>/tmp/unblockneteasemusic.log && exit 1
|
||||
if [ ! -e "/usr/share/unblockneteasemusic/core_local_ver" ]; then
|
||||
clean_log
|
||||
echo -e "Local version: NOT FOUND, cloud version: ${core_latest_ver}." >>/tmp/unblockneteasemusic.log
|
||||
update_core
|
||||
else
|
||||
if [ "$(cat /usr/share/unblockneteasemusic/core_local_ver)" != "${core_latest_ver}" ]; then
|
||||
clean_log
|
||||
echo -e "Local core version: $(cat /usr/share/unblockneteasemusic/core_local_ver 2>/dev/null), cloud core version: ${core_latest_ver}." >>/tmp/unblockneteasemusic.log
|
||||
update_core
|
||||
else
|
||||
echo -e "\nLocal core version: $(cat /usr/share/unblockneteasemusic/core_local_ver 2>/dev/null), cloud core version: ${core_latest_ver}." >>/tmp/unblockneteasemusic.log
|
||||
echo -e "You're already using the latest core version." >>/tmp/unblockneteasemusic.log
|
||||
exit 3
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function update_core(){
|
||||
echo -e "Updating core..." >>/tmp/unblockneteasemusic.log
|
||||
|
||||
mkdir -p "/usr/share/unblockneteasemusic/core" >/dev/null 2>&1
|
||||
rm -rf /usr/share/unblockneteasemusic/core/* >/dev/null 2>&1
|
||||
|
||||
curl -sL "https://github.com/nondanee/UnblockNeteaseMusic/archive/master.tar.gz" -o "/usr/share/unblockneteasemusic/core/core.tar.gz" >/dev/null 2>&1
|
||||
tar -zxf "/usr/share/unblockneteasemusic/core/core.tar.gz" -C "/usr/share/unblockneteasemusic/core/" >/dev/null 2>&1
|
||||
mv /usr/share/unblockneteasemusic/core/UnblockNeteaseMusic-master/* "/usr/share/unblockneteasemusic/core/"
|
||||
rm -rf "/usr/share/unblockneteasemusic/core/core.tar.gz" "/usr/share/unblockneteasemusic/core/UnblockNeteaseMusic-master" >/dev/null 2>&1
|
||||
|
||||
if [ ! -e "/usr/share/unblockneteasemusic/core/app.js" ]; then
|
||||
echo -e "Failed to download core." >>/tmp/unblockneteasemusic.log
|
||||
exit 1
|
||||
else
|
||||
[ "${update_core_from_luci}" == "y" ] && touch "/usr/share/unblockneteasemusic/update_core_successfully"
|
||||
echo -e "${core_latest_ver}" > /usr/share/unblockneteasemusic/core_local_ver
|
||||
[ "${non_restart}" != "y" ] && /etc/init.d/unblockneteasemusic restart
|
||||
fi
|
||||
|
||||
echo -e "Succeeded in updating core." >/tmp/unblockneteasemusic.log
|
||||
echo -e "Current core version: ${core_latest_ver}.\n" >>/tmp/unblockneteasemusic.log
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
"update_luci")
|
||||
check_luci_if_already_running
|
||||
check_luci_latest_version
|
||||
;;
|
||||
"update_core")
|
||||
check_core_if_already_running
|
||||
check_core_latest_version
|
||||
;;
|
||||
"update_core_non_restart")
|
||||
non_restart="y"
|
||||
check_core_if_already_running
|
||||
check_core_latest_version
|
||||
;;
|
||||
"update_core_from_luci")
|
||||
update_core_from_luci="y"
|
||||
check_core_if_already_running
|
||||
check_core_latest_version
|
||||
;;
|
||||
*)
|
||||
echo -e "Usage: ./update.sh {update_luci|update_core}"
|
||||
;;
|
||||
esac
|
||||
@ -1,64 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Created By [CTCGFW]Project OpenWRT
|
||||
# https://github.com/project-openwrt
|
||||
|
||||
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/unblockneteasemusic.log && exit 2
|
||||
}
|
||||
|
||||
function clean_log(){
|
||||
echo "" > /tmp/unblockneteasemusic.log
|
||||
}
|
||||
|
||||
function check_latest_version(){
|
||||
latest_ver="$(curl -s 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/unblockneteasemusic.log && exit 1
|
||||
if [ ! -e "/usr/share/unblockneteasemusic/local_ver" ]; then
|
||||
clean_log
|
||||
echo -e "Local version: NOT FOUND, cloud version: ${latest_ver}." >>/tmp/unblockneteasemusic.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/unblockneteasemusic.log
|
||||
update_core
|
||||
else
|
||||
echo -e "\nLocal version: $(cat /usr/share/unblockneteasemusic/local_ver 2>/dev/null), cloud version: ${latest_ver}." >>/tmp/unblockneteasemusic.log
|
||||
echo -e "You're already using the latest version." >>/tmp/unblockneteasemusic.log
|
||||
exit 3
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function update_core(){
|
||||
echo -e "Updating core..." >>/tmp/unblockneteasemusic.log
|
||||
|
||||
mkdir -p "/usr/share/unblockneteasemusic/core" >/dev/null 2>&1
|
||||
rm -rf /usr/share/unblockneteasemusic/core/* >/dev/null 2>&1
|
||||
|
||||
curl -L "https://github.com/nondanee/UnblockNeteaseMusic/archive/master.tar.gz" -o "/usr/share/unblockneteasemusic/core/core.tar.gz" >/dev/null 2>&1
|
||||
tar -zxf "/usr/share/unblockneteasemusic/core/core.tar.gz" -C "/usr/share/unblockneteasemusic/core/" >/dev/null 2>&1
|
||||
mv /usr/share/unblockneteasemusic/core/UnblockNeteaseMusic-master/* "/usr/share/unblockneteasemusic/core/"
|
||||
rm -rf "/usr/share/unblockneteasemusic/core/core.tar.gz" "/usr/share/unblockneteasemusic/core/UnblockNeteaseMusic-master" >/dev/null 2>&1
|
||||
|
||||
if [ ! -e "/usr/share/unblockneteasemusic/core/app.js" ]; then
|
||||
echo -e "Failed to download core." >>/tmp/unblockneteasemusic.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/unblockneteasemusic restart
|
||||
fi
|
||||
|
||||
echo -e "Succeeded in updating core." >/tmp/unblockneteasemusic.log
|
||||
echo -e "Current version: ${latest_ver}.\n" >>/tmp/unblockneteasemusic.log
|
||||
}
|
||||
|
||||
function main(){
|
||||
check_if_already_running
|
||||
check_latest_version
|
||||
}
|
||||
|
||||
[ "$1" == "luci_update" ] && luci_update="y"
|
||||
main
|
||||
Loading…
Reference in New Issue
Block a user