فهرست منبع

Refactor: make it much thiner

Signed-off-by: Tianling Shen <[email protected]>
Tianling Shen 4 سال پیش
والد
کامیت
83cc79dffe

+ 5 - 9
Makefile

@@ -1,22 +1,18 @@
+# SPDX-License-Identifier: GPL-3.0-only
 #
-# Copyright (C) 2021 ImmortalWrt
-# (https://immortalwrt.org)
-#
-# This is free software, licensed under the GNU General Public License v3.
-# See /LICENSE for more information.
-#
+# Copyright (C) 2021 ImmortalWrt.org
 
 include $(TOPDIR)/rules.mk
 
 LUCI_TITLE:=LuCI support for UnblockNeteaseMusic
-LUCI_DEPENDS:=+bash +busybox +coreutils +coreutils-nohup +curl +dnsmasq-full +ipset +libopenssl +node
+LUCI_DEPENDS:=+busybox +dnsmasq-full +ipset +jsonfilter +libupstream-openssl +node +uclient-fetch
 LUCI_PKGARCH:=all
 
 PKG_NAME:=luci-app-unblockneteasemusic
 PKG_VERSION:=2.9
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
-PKG_MAINTAINER:=CN_SZTL <[email protected]>
+PKG_MAINTAINER:=Tianling Shen <[email protected]>
 
 include $(TOPDIR)/feeds/luci/luci.mk
 

+ 4 - 4
luasrc/controller/unblockneteasemusic.lua

@@ -31,14 +31,14 @@ function act_status()
 end
 
 function update_luci()
-	luci_cloud_ver=luci.sys.exec("curl -s 'https://api.github.com/repos/immortalwrt/luci-app-unblockneteasemusic/releases/latest' | jsonfilter -e '@.tag_name'")
+	luci_cloud_ver=luci.sys.exec("uclient-fetch -q -O- 'https://api.github.com/repos/immortalwrt/luci-app-unblockneteasemusic/releases/latest' | jsonfilter -e '@.tag_name'")
 	if not luci_cloud_ver then
 		return "1"
 	else
 		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")
+			luci.sys.call("/usr/share/unblockneteasemusic/update.sh update_luci")
 			if not nixio.fs.access("/usr/share/unblockneteasemusic/update_luci_successfully") then
 				return "2"
 			else
@@ -59,7 +59,7 @@ function act_update_luci()
 end
 
 function update_core()
-	core_cloud_ver=luci.sys.exec("curl -s 'https://api.github.com/repos/1715173329/UnblockNeteaseMusic/commits/enhanced' | jsonfilter -e '@.sha'")
+	core_cloud_ver=luci.sys.exec("uclient-fetch -q -O- 'https://api.github.com/repos/1715173329/UnblockNeteaseMusic/commits/enhanced' | jsonfilter -e '@.sha'")
 	core_cloud_ver_mini=string.sub(core_cloud_ver, 1, 7)
 	if not core_cloud_ver or not core_cloud_ver_mini then
 		return "1"
@@ -67,7 +67,7 @@ function update_core()
 		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")
+			luci.sys.call("/usr/share/unblockneteasemusic/update.sh update_core_from_luci")
 			if not nixio.fs.access("/usr/share/unblockneteasemusic/update_core_successfully") then
 				return "2"
 			else

+ 5 - 5
root/etc/init.d/unblockneteasemusic

@@ -1,6 +1,6 @@
 #!/bin/sh /etc/rc.common
-# Created By ImmortalWrt
-# https://github.com/immortalwrt
+# SPDX-License-Identifier: GPL-3.0-only
+# Copyright (C) 2021 Tianling Shen <[email protected]>
 
 START=92
 STOP=10
@@ -108,7 +108,7 @@ ipset=/clientlog3.music.163.com/neteasemusic
 		done
 
 		if ! ipset list "neteasemusic" > "/dev/null"; then ipset create "neteasemusic" hash:ip; fi
-		curl --retry "5" --retry-delay "3" -s "http://httpdns.n.netease.com/httpdns/v2/d?domain=music.163.com,interface.music.163.com,interface3.music.163.com,apm.music.163.com,apm3.music.163.com,clientlog.music.163.com,clientlog3.music.163.com" |grep -Eo '[0-9]+?\.[0-9]+?\.[0-9]+?\.[0-9]+?' |sort |uniq |awk '{print "ipset add neteasemusic "$1}' |bash > "/dev/null" 2>&1
+		uclient-fetch -q -O- "http://httpdns.n.netease.com/httpdns/v2/d?domain=music.163.com,interface.music.163.com,interface3.music.163.com,apm.music.163.com,apm3.music.163.com,clientlog.music.163.com,clientlog3.music.163.com" |jsonfilter -e '@.data.*.ip.*' |sort -u |awk '{print "ipset add neteasemusic "$1}' |sh > "/dev/null" 2>&1
 		iptables -t "nat" -N "netease_cloud_music"
 		iptables -t "nat" -A "netease_cloud_music" -d "0.0.0.0/8" -j "RETURN"
 		iptables -t "nat" -A "netease_cloud_music" -d "10.0.0.0/8" -j "RETURN"
@@ -194,7 +194,7 @@ start()
 	echo "*/5 * * * * /usr/share/$NAME/log_check.sh" >> "/etc/crontabs/root"
 	/etc/init.d/cron restart > "/dev/null" 2>&1
 
-	[ ! -e "/usr/share/$NAME/core/app.js" ] && { rm -f "/usr/share/$NAME/local_ver"; bash "/usr/share/$NAME/update.sh" "update_core_non_restart"; }
+	[ ! -e "/usr/share/$NAME/core/app.js" ] && { rm -f "/usr/share/$NAME/local_ver"; sh "/usr/share/$NAME/update.sh" "update_core_non_restart"; }
 	[ ! -e "/usr/share/$NAME/core/app.js" ] && { echo "Core Not Found, please download it before starting." >> "/tmp/$NAME.log"; exit 1; }
 
 	quality_check_line="$(awk "/target == 0 \|\| item.id == target/{print NR}" "/usr/share/$NAME/core/src/hook.js")"
@@ -213,7 +213,7 @@ start()
 
 	[ "${hijack_ways}" = "use_hosts" ] && { http_port="80"; https_port="443"; }
 	[ "${music_source}" = "default" ] && music_source="" || music_source="-o ${music_source}"
-	nohup node "/usr/share/$NAME/core/app.js" -a "${addr}" -p "${http_port}":"${https_port}" ${music_source} -e "${endpoint_url}" ${netease_server_ip} ${proxy_server_ip} ${strict_mode} >> "/tmp/$NAME.log" 2>&1 &
+	node "/usr/share/$NAME/core/app.js" -a "${addr}" -p "${http_port}":"${https_port}" ${music_source} -e "${endpoint_url}" ${netease_server_ip} ${proxy_server_ip} ${strict_mode} >> "/tmp/$NAME.log" 2>&1 &
 
 	set_type="start"
 	if [ "${hijack_ways}" = "use_ipset" ]; then

+ 6 - 6
root/usr/share/unblockneteasemusic/log_check.sh

@@ -1,13 +1,13 @@
-#!/bin/bash
-# Created By ImmortalWrt
-# https://github.com/immortalwrt
+#!/bin/sh
+# SPDX-License-Identifier: GPL-3.0-only
+# Copyright (C) 2021 Tianling Shen <[email protected]>
 
 NAME="unblockneteasemusic"
 
 log_max_size="4" #使用KB计算
 log_file="/tmp/$NAME.log"
 
-(( log_size = "$(ls -l "${log_file}" | awk -F ' ' '{print $5}')" / "1024" ))
-(( "${log_size}" >= "${log_max_size}" )) && echo "" > "${log_file}"
+log_size="$(expr $(ls -l "${log_file}" | awk -F ' ' '{print $5}') / "1024")"
+[ "${log_size}" -lt "${log_max_size}" ] || echo "" > "${log_file}"
 
-[ "*$(uci get $NAME.@$NAME[0].daemon_enable 2>/dev/null)*" == "*1*" ] && { [ -z "$(ps |grep "$NAME" |grep "app.js" |grep -v "grep")" ] && /etc/init.d/$NAME restart; }
+[ "*$(uci get $NAME.@$NAME[0].daemon_enable 2>/dev/null)*" != "*1*" ] || { [ -z "$(ps |grep "$NAME" |grep "app.js" |grep -v "grep")" ] && /etc/init.d/$NAME restart; }

+ 7 - 7
root/usr/share/unblockneteasemusic/update.sh

@@ -1,6 +1,6 @@
-#!/bin/bash
-# Created By ImmortalWrt
-# https://github.com/immortalwrt
+#!/bin/sh
+# SPDX-License-Identifier: GPL-3.0-only
+# Copyright (C) 2021 Tianling Shen <[email protected]>
 
 NAME="unblockneteasemusic"
 
@@ -19,7 +19,7 @@ function clean_log(){
 }
 
 function check_luci_latest_version(){
-	luci_latest_ver="$(curl -s 'https://api.github.com/repos/immortalwrt/luci-app-unblockneteasemusic/releases/latest' | jsonfilter -e '@.tag_name')"
+	luci_latest_ver="$(uclient-fetch -q -O- 'https://api.github.com/repos/immortalwrt/luci-app-unblockneteasemusic/releases/latest' | jsonfilter -e '@.tag_name')"
 	[ -z "${luci_latest_ver}" ] && { echo -e "\nFailed to check latest LuCI version, please try again later." >> "/tmp/$NAME.log"; exit 1; }
 	if [ "$(opkg info "luci-app-unblockneteasemusic" |sed -n "2p" |tr -d "Version: ")" != "${luci_latest_ver}" ]; then
 		clean_log
@@ -37,7 +37,7 @@ function update_luci(){
 
 	mkdir -p "/tmp" > "/dev/null" 2>&1
 
-	curl -sL "https://github.com/immortalwrt/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
+	uclient-fetch -q "https://github.com/immortalwrt/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"
@@ -55,7 +55,7 @@ function update_luci(){
 }
 
 function check_core_latest_version(){
-	core_latest_ver="$(curl -s 'https://api.github.com/repos/1715173329/UnblockNeteaseMusic/commits/enhanced' | jsonfilter -e '@.sha')"
+	core_latest_ver="$(uclient-fetch -q -O- 'https://api.github.com/repos/1715173329/UnblockNeteaseMusic/commits/enhanced' | jsonfilter -e '@.sha')"
 	[ -z "${core_latest_ver}" ] && { echo -e "\nFailed to check latest core version, please try again later." >> "/tmp/$NAME.log"; exit 1; }
 	if [ ! -e "/usr/share/$NAME/core_local_ver" ]; then
 		clean_log
@@ -80,7 +80,7 @@ function update_core(){
 	mkdir -p "/usr/share/$NAME/core" > "/dev/null" 2>&1
 	rm -rf /usr/share/$NAME/core/* > "/dev/null" 2>&1
 
-	curl -sL "https://github.com/1715173329/UnblockNeteaseMusic/archive/enhanced.tar.gz" -o "/usr/share/$NAME/core/core.tar.gz" > "/dev/null" 2>&1
+	uclient-fetch -q "https://github.com/1715173329/UnblockNeteaseMusic/archive/enhanced.tar.gz" -O "/usr/share/$NAME/core/core.tar.gz" > "/dev/null" 2>&1
 	tar -zxf "/usr/share/$NAME/core/core.tar.gz" -C "/usr/share/$NAME/core/" > "/dev/null" 2>&1
 	mv /usr/share/$NAME/core/UnblockNeteaseMusic-enhanced/* "/usr/share/$NAME/core/"
 	rm -rf "/usr/share/$NAME/core/core.tar.gz" "/usr/share/$NAME/core/UnblockNeteaseMusic-enhanced" > "/dev/null" 2>&1