浏览代码

downloadlink:add usr defined download link

rufengsuixing 5 年之前
父节点
当前提交
0082177112
共有 4 个文件被更改,包括 60 次插入32 次删除
  1. 3 1
      README.md
  2. 17 0
      luasrc/model/cbi/AdGuardHome/base.lua
  3. 2 0
      root/usr/share/AdGuardHome/links.txt
  4. 38 31
      root/usr/share/AdGuardHome/update_core.sh

+ 3 - 1
README.md

@@ -2,7 +2,9 @@
 复杂的AdGuardHome的openwrt的luci界面
 
  - 可以管理网页端口
- - luci下载/更新核心版本
+ - luci下载/更新核心版本(支持自定义链接下载)
+   - 如果为tar.gz文件需要与官方的文件结构一致
+   - 或者直接为主程序二进制
  - upx 压缩核心(xz依赖,脚本自动下载)
  - dns重定向
    - 作为dnsmasq的上游服务器(在AGH中无法统计客户端信息,也无法针对客户端调整设置,ssr-plus正常)

+ 17 - 0
luasrc/model/cbi/AdGuardHome/base.lua

@@ -80,11 +80,15 @@ o:value("--brute", translate("try all available compression methods & filters [s
 o:value("--ultra-brute", translate("try even more compression variants [very slow]"))
 o.default     = ""
 o.description=translate("bin use less space,but may have compatibility issues")
+o.rmempty = false
 ---- config path
 o = s:option(Value, "configpath", translate("Config Path"), translate("AdGuardHome config path"))
 o.default     = "/etc/AdGuardHome.yaml"
 o.datatype    = "string"
 o.validate=function(self, value)
+if fs.stat(value,"type")=="dir" then
+	fs.rmdir(value)
+end
 if fs.stat(value,"type")=="dir" then
 	if m.message then
 	m.message =m.message.."\nerror!config path is a dir"
@@ -185,9 +189,22 @@ else
 	return value
 end
 end
+----autoupdate
 o = s:option(Flag, "autoupdate", translate("Auto update core with crontab"))
 o.default = 0
+----cutquerylog
 o = s:option(Flag, "cutquerylog", translate("Auto tail querylog with crontab"))
 o.default = 0
+----downloadpath
+o = s:option(TextValue, "downloadlinks",translate("Update download links"))
+o.rows = 4
+o.wrap = "on"
+o.size=111
+o.cfgvalue = function(self, section)
+	return fs.readfile("/usr/share/AdGuardHome/links.txt")
+end
+o.write = function(self, section, value)
+	fs.writefile("/usr/share/AdGuardHome/links.txt", value:gsub("\r\n", "\n"))
+end
 fs.writefile("/var/run/lucilogpos","0")
 return m

+ 2 - 0
root/usr/share/AdGuardHome/links.txt

@@ -0,0 +1,2 @@
+https://github.com/AdguardTeam/AdGuardHome/releases/download/${latest_ver}/AdGuardHome_linux_${Arch}.tar.gz
+https://static.adguard.com/adguardhome/release/AdGuardHome_linux_${Arch}.tar.gz

+ 38 - 31
root/usr/share/AdGuardHome/update_core.sh

@@ -8,7 +8,7 @@ fi
 mkdir -p ${binpath%/*}
 configpath=$(uci get AdGuardHome.AdGuardHome.configpath)
 if [ -z "$configpath" ]; then
-uci get AdGuardHome.AdGuardHome.configpath="/etc/AdGuardHome.yaml"
+uci set AdGuardHome.AdGuardHome.configpath="/etc/AdGuardHome.yaml"
 configpath="/etc/AdGuardHome.yaml"
 fi
 mkdir -p ${configpath%/*}
@@ -115,7 +115,7 @@ doupx(){
 	Arch="powerpc64"
 	;;
 	*)
-	echo -e "error not support $Archt" 
+	echo -e "error not support $Archt if you can use offical release please issue a bug" 
 	exit 1
 	;;
 	esac
@@ -179,50 +179,57 @@ doupdate_core(){
 	exit 1
 	;;
 	*)
-	echo -e "error not support $Archt" 
-	
+	echo -e "error not support $Archt if you can use offical release please issue a bug" 
 	exit 1
 	;;
 	esac
-	echo -e "start download ${latest_ver}/AdGuardHome_linux_${Arch}.tar.gz" 
-	wget-ssl --no-check-certificate -t 2 -T 20 -O /tmp/AdGuardHomeupdate/AdGuardHome_linux_${Arch}.tar.gz "https://github.com/AdguardTeam/AdGuardHome/releases/download/${latest_ver}/AdGuardHome_linux_${Arch}.tar.gz" 2>&1
-	if [ "$?" != "0" ]; then
-		echo "github download failed try download from static.adguard.com"
-		wget-ssl --no-check-certificate -t 2 -T 20 -O /tmp/AdGuardHomeupdate/AdGuardHome_linux_${Arch}.tar.gz "https://static.adguard.com/adguardhome/release/AdGuardHome_linux_${Arch}.tar.gz" 2>&1
+	echo -e "start download" 
+	while read link
+	do
+		eval link=$link
+		wget-ssl --no-check-certificate -t 2 -T 20 -O /tmp/AdGuardHomeupdate/${link##*/} "$link" 2>&1
 		if [ "$?" != "0" ]; then
-			echo "download failed"
+			echo "download failed try another download"
+			rm -f /tmp/AdGuardHomeupdate/${link##*/}
+		else
+			local success="1"
+			break
+		fi
+	done < "/usr/share/AdGuardHome/links.txt"
+	[ -z "$success" ] && echo "no download success" && exit 1
+	if [ "${link##*.}" == "gz" ]; then
+		tar -zxf "/tmp/AdGuardHomeupdate/${link##*/}" -C "/tmp/AdGuardHomeupdate/"
+		if [ ! -e "/tmp/AdGuardHomeupdate/AdGuardHome" ]; then
+			echo -e "Failed to download core." 
+			rm -rf "/tmp/AdGuardHomeupdate" >/dev/null 2>&1
 			exit 1
 		fi
+		downloadbin="/tmp/AdGuardHomeupdate/AdGuardHome/AdGuardHome"
+	else
+		downloadbin="/tmp/AdGuardHomeupdate/${link##*/}"
 	fi
-	tar -zxf "/tmp/AdGuardHomeupdate/AdGuardHome_linux_${Arch}.tar.gz" -C "/tmp/AdGuardHomeupdate/"
-	if [ ! -e "/tmp/AdGuardHomeupdate/AdGuardHome" ]; then
-		echo -e "Failed to download core." 
-		rm -rf "/tmp/AdGuardHomeupdate" >/dev/null 2>&1
-		exit 1
-	else 
-		echo -e "download success start copy" 
-		if [ ! -z "$upxflag" ]; then
+	chmod 755 $downloadbin
+	echo -e "download success start copy" 
+	if [ ! -z "$upxflag" ]; then
 		echo -e "start upx may take a long time" 
 		doupx
-        #maybe need chmod
-		/tmp/upx-${upx_latest_ver}-${Arch}_linux/upx $upxflag /tmp/AdGuardHomeupdate/AdGuardHome/AdGuardHome
+		/tmp/upx-${upx_latest_ver}-${Arch}_linux/upx $upxflag $downloadbin
 		rm -rf /tmp/upx-${upx_latest_ver}-${Arch}_linux
-		fi
-		echo -e "start copy" 
-		/etc/init.d/AdGuardHome stop
-		rm "$binpath"
-		mv -f /tmp/AdGuardHomeupdate/AdGuardHome/AdGuardHome "$binpath"
-		if [ "$?" == "1" ]; then
-			echo "mv failed maybe not enough space please use upx or change bin to /tmp/AdGuardHome" 
-			exit 1
-		fi
-		/etc/init.d/AdGuardHome start
 	fi
+	echo -e "start copy" 
+	/etc/init.d/AdGuardHome stop
+	rm "$binpath"
+	mv -f "$downloadbin" "$binpath"
+	if [ "$?" == "1" ]; then
+		echo "mv failed maybe not enough space please use upx or change bin to /tmp/AdGuardHome" 
+		exit 1
+	fi
+	/etc/init.d/AdGuardHome start
 	rm -rf "/tmp/AdGuardHomeupdate" >/dev/null 2>&1
 	echo -e "Succeeded in updating core." 
 	uci set AdGuardHome.AdGuardHome.version="${latest_ver}"
 	uci commit AdGuardHome
-	echo -e "Local version: ${now_ver}, cloud version: ${latest_ver}.\n" 
+	echo -e "Local version: ${latest_ver}, cloud version: ${latest_ver}.\n" 
 }
 
 main(){