Browse Source

improve:only reload when list update

rufengsuixing 5 years ago
parent
commit
4515bc8369
2 changed files with 24 additions and 4 deletions
  1. 12 2
      root/usr/share/AdGuardHome/addhost.sh
  2. 12 2
      root/usr/share/AdGuardHome/gfw2adg.sh

+ 12 - 2
root/usr/share/AdGuardHome/addhost.sh

@@ -1,5 +1,15 @@
 #!/bin/sh
-[ "$1" == "del" ] && sed -i '/programaddstart/,/programaddend/d' /etc/hosts && exit 0
+checkmd5(){
+local nowmd5=$(md5sum /etc/hosts)
+nowmd5=${nowmd5%% *}
+local lastmd5=$(uci get AdGuardHome.AdGuardHome.hostsmd5)
+if [ "$nowmd5" != "$lastmd5" ]; then
+	/etc/init.d/AdGuardHome reload
+	uci get AdGuardHome.AdGuardHome.hostsmd5="$nowmd5"
+	uci commit AdGuardHome
+fi
+}
+[ "$1" == "del" ] && sed -i '/programaddstart/,/programaddend/d' /etc/hosts && checkmd5 && exit 0
 /usr/bin/awk 'BEGIN{
 while ((getline < "/tmp/dhcp.leases") > 0)
 {
@@ -20,4 +30,4 @@ else
 	cat /tmp/tmphost >> /etc/hosts
 fi
 rm /tmp/tmphost
-/etc/init.d/AdGuardHome reload
+checkmd5

+ 12 - 2
root/usr/share/AdGuardHome/gfw2adg.sh

@@ -1,7 +1,17 @@
 #!/bin/sh
 PATH="/usr/sbin:/usr/bin:/sbin:/bin"
+checkmd5(){
+local nowmd5=$(md5sum /tmp/adguard.list 2>/dev/null)
+nowmd5=${nowmd5%% *}
+local lastmd5=$(uci get AdGuardHome.AdGuardHome.gfwlistmd5)
+if [ "$nowmd5" != "$lastmd5" ]; then
+	/etc/init.d/AdGuardHome reload
+	uci get AdGuardHome.AdGuardHome.gfwlistmd5="$nowmd5"
+	uci commit AdGuardHome
+fi
+}
 configpath=$(uci get AdGuardHome.AdGuardHome.configpath)
-[ "$1" == "del" ] && sed -i '/programaddstart/,/programaddend/d' $configpath && exit 0
+[ "$1" == "del" ] && sed -i '/programaddstart/,/programaddend/d' $configpath && checkmd5 && exit 0
 gfwupstream=$(uci get AdGuardHome.AdGuardHome.gfwupstream)
 if [ -z $gfwupstream ]; then
 gfwupstream="tcp://208.67.220.220:5353"
@@ -72,5 +82,5 @@ else
 	sed -i '1i\  - '\''[/programaddstart/]#'\''' /tmp/adguard.list
 	sed -i '/upstream_dns:/'r/tmp/adguard.list $configpath
 fi
-/etc/init.d/AdGuardHome restart
+checkmd5
 rm -f /tmp/gfwlist.txt /tmp/adguard.list