rufengsuixing 5 years ago
parent
commit
76c9987623

+ 56 - 0
Makefile

@@ -0,0 +1,56 @@
+# Copyright (C) 2018-2019 Lienol
+#
+# This is free software, licensed under the Apache License, Version 2.0 .
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=luci-app-adguardhome
+PKG_VERSION:=1.0
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/luci-app-adguardhome
+	SECTION:=luci
+	CATEGORY:=LuCI
+	SUBMENU:=3. Applications
+	TITLE:=LuCI Support for adguardhome
+	DEPENDS:=
+endef
+
+define Package/luci-app-adguardhome/description
+	LuCI support for adguardhome
+endef
+
+define Build/Prepare
+endef
+
+define Build/Compile
+endef
+
+define Package/luci-app-adguardhome/install
+    $(INSTALL_DIR) $(1)/usr/lib/lua/luci
+	cp -pR ./luasrc/* $(1)/usr/lib/lua/luci
+	$(INSTALL_DIR) $(1)/
+	cp -pR ./root/* $(1)/
+endef
+
+define Package/luci-app-adguardhome/postinst
+#!/bin/sh
+	/etc/init.d/AdGuardHome enable >/dev/null 2>&1
+exit 0
+endef
+
+define Package/luci-app-adguardhome/prerm
+#!/bin/sh
+if [ -z "$${IPKG_INSTROOT}" ]; then
+     /etc/init.d/AdGuardHome disable
+     /etc/init.d/AdGuardHome stop
+fi
+exit 0
+endef
+
+$(eval $(call BuildPackage,luci-app-adguardhome))

+ 10 - 2
README.md

@@ -1,2 +1,10 @@
-# luci-app-AdGuardHome
- 
+# luci-app-adguardhome
+复杂的adguardhome的openwrt的luci界面,仍待测试
+
+ - 可以管理网页端口
+ - luci更新核心版本
+ - dns重定向
+ - 自定义bin path
+ - 自定义config path
+ - 自定义work path
+ - 自定义log path

+ 17 - 0
luasrc/controller/AdGuardHome.lua

@@ -0,0 +1,17 @@
+module("luci.controller.AdGuardHome",package.seeall)
+function index()
+if not nixio.fs.access("/etc/config/AdGuardHome")then
+return
+end
+	entry({"admin","services","AdGuardHome"},firstchild(),_("AdGuard Home"),30).dependent=true
+	entry({"admin","services","AdGuardHome","general"},cbi("AdGuardHome"),_("Base Setting"),1)
+    entry({"admin","services","AdGuardHome","log"},form("AdGuardHomelog"),_("Log"),2)
+    entry({"admin","services","AdGuardHome","status"},call("act_status")).leaf=true
+end 
+
+function act_status()
+  local e={}
+  e.running=luci.sys.call("pgrep -f AdGuardHome/AdGuardHome >/dev/null")==0
+  luci.http.prepare_content("application/json")
+  luci.http.write_json(e)
+end

+ 84 - 0
luasrc/model/cbi/AdGuardHome.lua

@@ -0,0 +1,84 @@
+require("luci.sys")
+require("luci.util")
+local fs=require"nixio.fs"
+local uci=require"luci.model.uci".cursor()
+
+local configpath=uci:get("AdGuardHome","AdGuardHome","configpath")
+if (configpath==nil) then
+configpath="/etc/AdGuardHome.yaml"
+end
+local binpath="/usr/bin/AdGuardHome/AdGuardHome"
+local httpport=luci.sys.exec("awk '/bind_port:/{printf($2)}' "..configpath.." 2>nul")
+mp = Map("AdGuardHome", translate("AdGuard Home"))
+mp.description = translate("免费和开源,功能强大的全网络广告和跟踪程序拦截DNS服务器")
+mp:section(SimpleSection).template  = "AdGuardHome/AdGuardHome_status"
+
+s = mp:section(TypedSection, "AdGuardHome")
+s.anonymous=true
+s.addremove=false
+---- enable
+o = s:option(Flag, "enabled", translate("启用广告屏蔽"))
+o.default = 0
+o.rmempty = false
+---- httport
+o =s:option(Value,"httpport",translate("网页管理端口(覆盖配置)"))
+o.placeholder=3000
+o.default=3000
+o.datatype="port"
+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
+local e=luci.sys.exec(binpath.." --check-config 2>&1")
+e=string.match(e,'(v%d+\.%d+\.%d+)')
+o=s:option(Button,"restart",translate("手动更新"))
+o.inputtitle=translate("更新核心版本")
+if (e==nil) then
+e="not found"
+end
+o.description=string.format(translate("目前运行主程序版本").."<strong><font color=\"green\">: %s </font></strong>",e)
+o.inputstyle="reload"
+o.write=function()
+luci.sys.exec("bash /usr/share/AdGuardHome/update_core.sh 2>&1")
+luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome"))
+end
+---- port warning not safe
+local port=luci.sys.exec("awk '/  port:/{printf($2)}' "..configpath.." 2>nul")
+---- Redirect
+o = s:option(ListValue, "redirect", port..translate("Redirect"), translate("AdGuardHome redirect mode"))
+o.placeholder = "none"
+o:value("none", translate("none"))
+o:value("dnsmasq-upstream", translate("Run as dnsmasq upstream server"))
+o:value("redirect", translate("Redirect 53 port to AdGuardHome"))
+o.default     = "none"
+o.rempty      = false
+---- bin path
+o = s:option(Value, "binpath", translate("Bin Path"), translate("AdGuardHome Bin path if no bin will auto download"))
+o.default     = "/usr/bin/AdGuardHome/AdGuardHome"
+o.datatype    = "string"
+o.rempty      = false
+---- config path
+o = s:option(Value, "configpath", translate("Config Path"), translate("AdGuardHome config path"))
+o.default     = "/etc/AdGuardHome.yaml"
+o.datatype    = "string"
+o.rempty      = false
+---- work dir
+o = s:option(Value, "workdir", translate("Work dir"), translate("AdGuardHome work dir"))
+o.default     = "/usr/bin/AdGuardHome"
+o.datatype    = "string"
+o.rempty      = false
+---- log file
+o = s:option(Value, "logfile", translate("Log File"), translate("AdGuardHome runtime Log file if 'syslog': write to system log;if empty no log"))
+o.default     = ""
+o.datatype    = "string"
+o.rempty      = false
+---- debug
+o = s:option(Flag, "verbose", translate("verbose debug"))
+o.default = 0
+o.rmempty = false
+
+local apply = luci.http.formvalue("cbi.apply")
+ if apply then
+     io.popen("/etc/init.d/AdGuardHome reload")
+end
+
+return mp

+ 16 - 0
luasrc/model/cbi/AdGuardHomelog.lua

@@ -0,0 +1,16 @@
+local e=require"nixio.fs"
+local uci=require"luci.model.uci".cursor()
+logfile=uci:get("AdGuardHome","AdGuardHome","logfile")
+
+f=SimpleForm("logview")
+t=f:field(TextValue,"conf")
+t.rmempty=true
+t.rows=20
+function t.cfgvalue()
+if (logfile==nil) then
+	return "no log available"
+end
+return e.readfile(logfile)
+end
+t.readonly="readonly"
+return f

+ 22 - 0
luasrc/view/AdGuardHome/AdGuardHome_status.htm

@@ -0,0 +1,22 @@
+<script type="text/javascript">//<![CDATA[
+XHR.poll(3, '<%=url([[admin]], [[services]], [[AdGuardHome]], [[status]])%>', null,
+	function(x, data) {
+		var tb = document.getElementById('AdGuardHome_status');
+		if (data && tb) {
+			if (data.running) {
+				var links = '<em><b><font color=green>AdGuardHome <%:RUNNING%></font></b></em>';
+				tb.innerHTML = links;
+			} else {
+				tb.innerHTML = '<em><b><font color=red>AdGuardHome <%:NOT RUNNING%></font></b></em>';
+			}
+		}
+	}
+);
+//]]>
+</script>
+<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
+<fieldset class="cbi-section">
+	<p id="AdGuardHome_status">
+		<em><%:Collecting data...%></em>
+	</p>
+</fieldset>

+ 16 - 0
root/etc/config/AdGuardHome

@@ -0,0 +1,16 @@
+config AdGuardHome 'AdGuardHome'
+	option port '3000'
+	option enabled '0'
+	option httport '3000'
+	option httpport '3000'
+	option redirect 'none'
+	option configpath '/etc/AdGuardHome.yaml'
+	option workdir '/usr/bin/AdGuardHome'
+	option logfile '/tmp/AdGuardHome.log'
+	option verbose '0'
+	option lessspace '1'
+	option binpath '/usr/bin/AdGuardHome/AdGuardHome'
+	list old_redirect 'none'
+	list old_port '5553'
+	list old_enabled '1'
+

+ 290 - 0
root/etc/init.d/AdGuardHome

@@ -0,0 +1,290 @@
+#!/bin/sh /etc/rc.common
+ 
+USE_PROCD=1
+ 
+START=95
+STOP=01
+
+CONFIGURATION=AdGuardHome
+config_get configpath $CONFIGURATION configpath "/etc/AdGuardHome.yaml"
+
+set_forward_dnsmasq()
+{
+    local PORT="$1"
+    addr="127.0.0.1#$PORT"
+    OLD_SERVER="`uci get dhcp.@dnsmasq[0].server 2>/dev/null`"
+    echo $OLD_SERVER | grep "^$addr" >/dev/null 2>&1
+    if [ $? -eq 0 ]; then
+        return
+    fi
+    uci delete dhcp.@dnsmasq[0].server 2>/dev/null
+    uci add_list dhcp.@dnsmasq[0].server=$addr
+    for server in $OLD_SERVER; do
+        if [ "$server" = "$addr" ]; then
+            continue
+        fi
+        uci add_list dhcp.@dnsmasq[0].server=$server
+    done
+    uci delete dhcp.@dnsmasq[0].resolvfile 2>/dev/null
+    uci set dhcp.@dnsmasq[0].noresolv=1
+    uci commit dhcp 
+    /etc/init.d/dnsmasq restart
+}
+
+stop_forward_dnsmasq()
+{
+    local OLD_PORT="$1"
+    addr="127.0.0.1#$OLD_PORT"
+    OLD_SERVER="`uci get dhcp.@dnsmasq[0].server 2>/dev/null`"
+    echo $OLD_SERVER | grep "^$addr" >/dev/null 2>&1
+    if [ $? -ne 0 ]; then
+        return
+    fi
+
+    uci del_list dhcp.@dnsmasq[0].server=$addr 2>/dev/null
+    addrlist="`uci get dhcp.@dnsmasq[0].server 2>/dev/null`"
+    if [ -z "$addrlist" ] ; then
+        uci set dhcp.@dnsmasq[0].resolvfile=/tmp/resolv.conf.auto 2>/dev/null
+        uci delete dhcp.@dnsmasq[0].noresolv 2>/dev/null
+    fi
+    uci commit dhcp
+    /etc/init.d/dnsmasq restart
+}
+
+set_iptable()
+{
+    local ipv6_server=$1
+    local tcp_server=$2
+
+    IPS="`ifconfig | grep "inet addr" | grep -v ":127" | grep "Bcast" | awk '{print $2}' | awk -F : '{print $2}'`"
+    for IP in $IPS
+    do
+        if [ "$tcp_server" == "1" ]; then
+            iptables -t nat -A PREROUTING -p tcp -d $IP --dport 53 -j REDIRECT --to-ports $AdGuardHome_PORT >/dev/null 2>&1
+        fi
+        iptables -t nat -A PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $AdGuardHome_PORT >/dev/null 2>&1
+    done
+
+    if [ "$ipv6_server" == 0 ]; then
+        return
+    fi
+
+    IPS="`ifconfig | grep "inet6 addr" | grep -v " fe80::" | grep -v " ::1" | grep "Global" | awk '{print $3}'`"
+    for IP in $IPS
+    do
+        if [ "$tcp_server" == "1" ]; then
+            ip6tables -t nat -A PREROUTING -p tcp -d $IP --dport 53 -j REDIRECT --to-ports $AdGuardHome_PORT >/dev/null 2>&1
+        fi
+        ip6tables -t nat -A PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $AdGuardHome_PORT >/dev/null 2>&1
+    done
+
+}
+
+clear_iptable()
+{
+    local OLD_PORT="$1"
+    local ipv6_server=$2
+    IPS="`ifconfig | grep "inet addr" | grep -v ":127" | grep "Bcast" | awk '{print $2}' | awk -F : '{print $2}'`"
+    for IP in $IPS
+    do
+        iptables -t nat -D PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $OLD_PORT >/dev/null 2>&1
+        iptables -t nat -D PREROUTING -p tcp -d $IP --dport 53 -j REDIRECT --to-ports $OLD_PORT >/dev/null 2>&1
+    done
+
+    if [ "$ipv6_server" == 0 ]; then
+        return
+    fi
+
+    IPS="`ifconfig | grep "inet6 addr" | grep -v " fe80::" | grep -v " ::1" | grep "Global" | awk '{print $3}'`"
+    for IP in $IPS
+    do
+        ip6tables -t nat -D PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $OLD_PORT >/dev/null 2>&1
+        ip6tables -t nat -D PREROUTING -p tcp -d $IP --dport 53 -j REDIRECT --to-ports $OLD_PORT >/dev/null 2>&1
+    done
+    
+}
+
+service_triggers() {
+    procd_add_reload_trigger firewall
+    procd_add_reload_trigger "CONFIGURATION"
+}
+
+get_tz()
+{
+    SET_TZ=""
+
+    if [ -e "/etc/localtime" ]; then
+        return 
+    fi
+    
+    for tzfile in /etc/TZ /var/etc/TZ
+    do
+        if [ ! -e "$tzfile" ]; then
+            continue
+        fi
+        
+        tz="`cat $tzfile 2>/dev/null`"
+    done
+    
+    if [ -z "$tz" ]; then
+        return  
+    fi
+    
+    SET_TZ=$tz
+}
+
+reload_service()
+{
+    stop
+    start
+}
+
+do_redirect() 
+{
+    local section="$CONFIGURATION"
+    args=""
+	ipv6_server=0
+	tcp_server=0
+    config_get_bool "enabled" "$section" "enabled" '0'
+	
+    AdGuardHome_PORT=$(awk '/  port:/{printf($2)}' $configpath)
+    
+    config_get "redirect" "$section" "redirect" "none"
+    config_get "old_redirect" "$section" "old_redirect" "none"
+    config_get "old_port" "$section" "old_port" "0"
+    config_get "old_enabled" "$section" "old_enabled" "0"
+
+    if [ "$old_redirect" != "$redirect" ] || [ "$old_port" != "$AdGuardHome_PORT" ] || [ "$old_enabled" = "1" -a "$enabled" = "0" ]; then
+        if [ "$old_redirect" != "none" ]; then
+            if [ "$old_port" != "0" ]; then
+                clear_iptable "$old_port" "$ipv6_server"
+            fi
+            if [ "$old_redirect" == "dnsmasq-upstream" ]; then
+                stop_forward_dnsmasq "$old_port"
+            fi
+        fi
+    fi
+    
+    uci delete AdGuardHome.@AdGuardHome[0].old_redirect 2>/dev/null
+    uci delete AdGuardHome.@AdGuardHome[0].old_port 2>/dev/null
+    uci delete AdGuardHome.@AdGuardHome[0].old_enabled 2>/dev/null
+    uci add_list AdGuardHome.@AdGuardHome[0].old_redirect="$redirect" 2>/dev/null
+    uci add_list AdGuardHome.@AdGuardHome[0].old_port="$AdGuardHome_PORT" 2>/dev/null
+    uci add_list AdGuardHome.@AdGuardHome[0].old_enabled="$enabled" 2>/dev/null
+    uci commit AdGuardHome
+
+    [ "$enabled" -gt 0 ] || return 1
+
+    if [ "$redirect" = "redirect" ]; then
+        set_iptable $ipv6_server $tcp_server
+    elif [ "$redirect" = "dnsmasq-upstream" ]; then
+        set_forward_dnsmasq "$AdGuardHome_PORT"
+    fi
+
+
+    #procd_open_instance "AdGuardHome"
+
+    #get_tz
+    #if [ ! -z "$SET_TZ" ]; then
+    #    procd_set_param env TZ="$SET_TZ"
+    #fi
+    #procd_set_param file "$AdGuardHome_CONF"
+    #procd_close_instance
+}
+get_filesystem()
+{
+# print out path filesystem
+    mount | awk '{print($3" "$5)}'
+    echo $0 | awk '
+    BEGIN{
+    while (("mount"| getline ret) > 0)
+    {
+    split(ret,d);
+    fs[d[3]]=d[5];
+    }
+    }{
+    split($0,d,"/");
+    if ("/" in fs)
+    { 
+    result=fs["/"]
+    }
+    for (i=2;i<=NF;i++)
+    {
+       p[i]=p[i-1]"/"d[i]
+       if (p[i] in fs)
+        { 
+        result=fs[p[i]]
+        }
+    }
+    print(result)}'
+}
+start_service() {
+    # Reading config
+    config_load "${CONFIGURATION}"
+    local enabled
+	local ADDITIONAL_ARGS=""
+    config_get_bool enabled $CONFIGURATION enabled 0
+    if [ "$enabled" -eq 0 ]; then
+        echo "AdGuardHome has turned off"
+        return 1
+    fi
+	config_get httpport $CONFIGURATION httpport 3000
+	ADDITIONAL_ARGS="$ADDITIONAL_ARGS -p $httpport"
+	
+    config_get workdir $CONFIGURATION workdir "/usr/bin/AdGuardHome"
+	ADDITIONAL_ARGS="$ADDITIONAL_ARGS -w $workdir"
+	mkdir -p $workdir
+	config_get configpath $CONFIGURATION configpath "/etc/AdGuardHome.yaml"
+	ADDITIONAL_ARGS="$ADDITIONAL_ARGS -c $configpath"
+	
+	config_get logfile $CONFIGURATION logfile ""
+	if [ ! -z "$logfile" ]; then
+		ADDITIONAL_ARGS="$ADDITIONAL_ARGS -l $logfile"
+	fi
+	config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome/AdGuardHome"
+	mkdir -p ${binpath%/*}
+	if [ ! -f "$binpath" ]; then
+        /usr/share/AdGuardHome/update_core.sh
+    fi 
+	config_get_bool verbose $CONFIGURATION verbose 0
+	if [ "$verbose" -eq 1 ]; then
+        ADDITIONAL_ARGS="$ADDITIONAL_ARGS -v"
+    fi
+	
+	# for overlay data-stk-oo not suppport
+    local cwdfs=$(get_filesystem $workdir)
+	if [ "$cwdfs"=="overlay" ]; then
+		echo "fs error ln db to tmp"
+		logger "AdGuardHome" "warning db redirect to tmp"
+		touch $workdir/data/stats.db
+		if [ ! -L $workdir/data/stats.db ]; then
+		mv -f $workdir/data/stats.db /tmp/stats.db
+		ln -s /tmp/stats.db $workdir/data/stats.db
+		fi
+		touch $workdir/data/sessions.db
+		if [ ! -L $workdir/data/sessions.db ]; then
+		mv -f $workdir/data/sessions.db /tmp/sessions.db
+		ln -s /tmp/sessions.db $workdir/data/sessions.db
+		fi
+	fi
+	
+    procd_open_instance
+    procd_set_param respawn
+    # pass config to script on start
+    procd_set_param command $binpath $ADDITIONAL_ARGS
+    procd_close_instance
+	do_redirect
+    echo "AdGuardHome turn on"
+    echo "enabled="$enabled""
+}
+
+stop_service()
+{
+    config_load "${CONFIGURATION}"
+    local enabled
+    config_get_bool enabled AdGuardHome enabled 0
+    do_redirect
+	killall -q AdGuardHome
+    echo "AdGuardHome turn off"
+    echo "enabled="$enabled""
+}

+ 105 - 0
root/usr/share/update_core.sh

@@ -0,0 +1,105 @@
+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%/*}
+/usr/bin/AdGuardHome
+function check_if_already_running(){
+	running_tasks="$(ps |grep "AdGuardHome" |grep "update_core" |grep -v "grep" |awk '{print $1}' |wc -l)"
+	[ "${running_tasks}" -gt "2" ] && echo -e "\nA task is already running." >>/tmp/AdGuardHome_update.log && exit 2
+}
+
+function clean_log(){
+	echo "" > /tmp/AdGuardHome_update.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 [ "${latest_ver}" != "${now_ver}" ]; then
+		clean_log
+		echo -e "Local version: ${now_ver}., cloud version: ${latest_ver}." >>/tmp/AdGuardHome_update.log
+		update_core
+	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
+			exit 3
+	fi
+}
+
+function update_core(){
+	echo -e "Updating core..." >>/tmp/AdGuardHome_update.log
+	mkdir -p "/tmp/AdGuardHome/update" >/dev/null 2>&1
+	rm -rf /tmp/AdGuardHome/update/* >/dev/null 2>&1
+	Archt="$(opkg info kernel | grep Architecture | awk -F "[ _]" '{print($2)}')"
+	case $Archt in
+	"i386")
+	Arch="386"
+	;;
+	"x86")
+	Arch="amd64"
+	;;
+	"mipsel")
+	Arch="mipsle"
+	;;
+	"mips")
+	Arch="mips"
+	;;
+	"arm")
+	Arch="arm"
+	;;
+	"ram64")
+	Arch="arm64"
+	;;
+	"aarch64")
+	Arch="arm64"
+	;;
+	*)
+	echo -e "error not support $Archt" >>/tmp/AdGuardHome_update.log
+	exit 1
+	;;
+	esac
+	wget-ssl --no-check-certificate -t 1 -T 10 -O  /tmp/AdGuardHome/update/AdGuardHome_linux_${Arch}.tar.gz "https://github.com/AdguardTeam/AdGuardHome/releases/download/${latest_ver}/AdGuardHome_linux_${Arch}.tar.gz"  >/dev/null 2>&1
+	tar -zxf "/tmp/AdGuardHome/update/AdGuardHome_linux_${Arch}.tar.gz" -C "/tmp/AdGuardHome/update/" >/dev/null 2>&1
+	
+	if [ ! -e "/tmp/AdGuardHome/update/AdGuardHome" ]; then
+		echo -e "Failed to download core." >>/tmp/AdGuardHome_update.log
+		rm -rf "/tmp/AdGuardHome/update" >/dev/null 2>&1
+		exit 1
+	else
+		if [ "$(uci get AdGuardHome.AdGuardHome.lessspace)"x != "1"x ]; then
+		cp -f /tmp/AdGuardHome/update/AdGuardHome/AdGuardHome "$binpath"
+			if [ "$?" == "1" ]; then
+				echo cp failed maybe not enough space try to kill and cp
+				/etc/init.d/AdGuardHome stop
+				cp -f /tmp/AdGuardHome/update/AdGuardHome/AdGuardHome "$binpath"
+				if [ "$?" == "0" ]; then
+					uci set AdGuardHome.AdGuardHome.lessspace="1"
+				else
+					echo cp failed
+					exit 1
+				fi
+			fi
+		else
+		    /etc/init.d/AdGuardHome stop
+			cp -f /tmp/AdGuardHome/update/AdGuardHome/AdGuardHome "$binpath"
+			if [ "$?" != "0" ]; then
+				echo cp failed
+				exit 1
+			fi
+		fi
+		[ "${luci_update}" == "y" ] && touch "/tmp/AdGuardHome/update_successfully"
+		/etc/init.d/AdGuardHome restart
+	fi
+	rm -rf "/tmp/AdGuardHome/update" >/dev/null 2>&1
+	echo -e "Succeeded in updating core." >/tmp/AdGuardHome_update.log
+	echo -e "Local version: ${now_ver}, cloud version: ${latest_ver}.\n" >>/tmp/AdGuardHome_update.log
+}
+
+function main(){
+	check_if_already_running
+	check_latest_version
+}
+	main