Browse Source

fix update

rufengsuixing 6 years ago
parent
commit
2470fdf879

+ 1 - 1
luasrc/controller/AdGuardHome.lua

@@ -15,7 +15,7 @@ end
 
 function act_status()
   local e={}
-  e.running=luci.sys.call("pgrep -f AdGuardHome/AdGuardHome >/dev/null")==0
+  e.running=luci.sys.call("pgrep -f AdGuardHome >/dev/null")==0
   luci.http.prepare_content("application/json")
   luci.http.write_json(e)
 end

+ 8 - 4
luasrc/model/cbi/AdGuardHome.lua

@@ -35,16 +35,20 @@ o.rmempty=false
 o.description = translate("<input type=\"button\" style=\"width:180px;border-color:Teal; text-align:center;font-weight:bold;color:Green;\" value=\"AdGuardHome Web:"..httpport.."\" onclick=\"window.open('http://'+window.location.hostname+':"..httpport.."/')\"/>")
 ---- update warning not safe
 if fs.access(configpath) then
-	local e=luci.sys.exec(binpath.." -c "..configpath.." --check-config 2>&1")
+	e=luci.sys.exec(binpath.." -c "..configpath.." --check-config 2>&1")
 	e=string.match(e,'(v%d+\.%d+\.%d+)')
 	if (e==nil) then
 	e="not found bin"
 	end
 else
 	if fs.access(binpath) then
-	e="not find config"
-	else
-	e="not found bin and config"
+		maybev=uci:get("AdGuardHome","AdGuardHome","version")
+		if (maybev==nil) then
+		e=""
+		end
+		e="not find config"..maybev
+		else
+		e="not found bin and config"
 	end
 end
 

+ 14 - 2
root/usr/share/AdGuardHome/update_core.sh

@@ -1,12 +1,18 @@
 #!/bin/bash
 PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-binpath=$(uci get AdGuardHome.AdGuardHome.binpath)
 touch /var/run/update_core
+binpath=$(uci get AdGuardHome.AdGuardHome.binpath)
 if [ -z "$binpath" ]; then
 uci get AdGuardHome.AdGuardHome.binpath="/tmp/AdGuardHome/AdGuardHome"
 binpath="/tmp/AdGuardHome/AdGuardHome"
 fi
 mkdir -p ${binpath%/*}
+configpath=$(uci get AdGuardHome.AdGuardHome.configpath)
+if [ -z "$configpath" ]; then
+uci get AdGuardHome.AdGuardHome.configpath="/etc/AdGuardHome.yaml"
+configpath="/etc/AdGuardHome.yaml"
+fi
+mkdir -p ${configpath%/*}
 
 function check_if_already_running(){
 	running_tasks="$(ps |grep "AdGuardHome" |grep "update_core" |grep -v "grep" |awk '{print $1}' |wc -l)"
@@ -20,7 +26,11 @@ function clean_log(){
 function check_latest_version(){
 	latest_ver="$(wget -O- https://api.github.com/repos/AdguardTeam/AdGuardHome/releases/latest 2>/dev/null|grep -E 'tag_name' |grep -E 'v[0-9.]+' -o 2>/dev/null)"
 	[ -z "${latest_ver}" ] && echo -e "\nFailed to check latest version, please try again later." >>/tmp/AdGuardHome_update.log && exit 1
-	now_ver="$($binpath  --check-config 2>&1| grep -E 'v[0-9.]+' -o)"
+	if [ -f "$configpath" ]; then
+	now_ver="$($binpath -c $configpath --check-config 2>&1| grep -E 'v[0-9.]+' -o)"
+	else
+	now_ver=$(uci get AdGuardHome.AdGuardHome.version)
+	fi
 	if [ "${latest_ver}"x != "${now_ver}"x ]; then
 		clean_log
 		echo -e "Local version: ${now_ver}., cloud version: ${latest_ver}." >>/tmp/AdGuardHome_update.log
@@ -28,6 +38,7 @@ function check_latest_version(){
 	else
 			echo -e "\nLocal version: ${now_ver}, cloud version: ${latest_ver}." >>/tmp/AdGuardHome_update.log
 			echo -e "You're already using the latest version." >>/tmp/AdGuardHome_update.log
+			uci set AdGuardHome.AdGuardHome.version="${latest_ver}"
 			rm /var/run/update_core
 			exit 3
 	fi
@@ -103,6 +114,7 @@ function doupdate_core(){
 	fi
 	rm -rf "/tmp/AdGuardHome/update" >/dev/null 2>&1
 	echo -e "Succeeded in updating core." >>/tmp/AdGuardHome_update.log
+	uci set AdGuardHome.AdGuardHome.version="${latest_ver}"
 	echo -e "Local version: ${now_ver}, cloud version: ${latest_ver}.\n" >>/tmp/AdGuardHome_update.log
 	rm /var/run/update_core
 }