luci-app-adguardhome: fix path error if core download from the Internet

Signed-off-by: Tianling Shen <cnsztl@project-openwrt.eu.org>
This commit is contained in:
AmadeusGhost 2021-02-14 12:20:05 +08:00 committed by Tianling Shen
parent 1706e45bc7
commit d087251fed
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
11 changed files with 184 additions and 157 deletions

View File

@ -5,7 +5,7 @@ local m,s,o,o1
local fs=require"nixio.fs"
local uci=require"luci.model.uci".cursor()
local configpath=uci:get("AdGuardHome","AdGuardHome","configpath") or "/etc/AdGuardHome.yaml"
local binpath=uci:get("AdGuardHome","AdGuardHome","binpath") or "/usr/bin/AdGuardHome/AdGuardHome"
local binpath=uci:get("AdGuardHome","AdGuardHome","binpath") or "/usr/bin/AdGuardHome"
httpport=uci:get("AdGuardHome","AdGuardHome","httpport") or "3000"
m = Map("AdGuardHome", "AdGuard Home")
m.description = translate("Free and open source, powerful network-wide ads & trackers blocking DNS server.")
@ -65,7 +65,7 @@ o.default = "none"
o.optional = true
---- 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.default = "/usr/bin/AdGuardHome"
o.datatype = "string"
o.optional = false
o.rmempty=false
@ -118,7 +118,7 @@ return value
end
---- work dir
o = s:option(Value, "workdir", translate("Work dir"), translate("AdGuardHome work dir include rules,audit log and database"))
o.default = "/usr/bin/AdGuardHome"
o.default = "/etc/AdGuardHome"
o.datatype = "string"
o.optional = false
o.rmempty=false
@ -208,7 +208,7 @@ o = s:option(Flag, "waitonboot", translate("On boot when network ok restart"))
o.default = 1
o.optional = true
---- backup workdir on shutdown
local workdir=uci:get("AdGuardHome","AdGuardHome","workdir") or "/usr/bin/AdGuardHome"
local workdir=uci:get("AdGuardHome","AdGuardHome","workdir") or "/etc/AdGuardHome"
o = s:option(MultiValue, "backupfile", translate("Backup workdir files when shutdown"))
o1 = s:option(Value, "backupwdpath", translate("Backup workdir path"))
local name
@ -234,7 +234,7 @@ o.optional=false
o.description=translate("Will be restore when workdir/data is empty")
----backup workdir path
o1.default = "/usr/bin/AdGuardHome"
o1.default = "/etc/AdGuardHome"
o1.datatype = "string"
o1.optional = false
o1.validate=function(self, value)

View File

@ -91,7 +91,6 @@ EOF
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()
@ -119,13 +118,13 @@ EOF
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 "$CONFIGURATION"
[ "$(uci get AdGuardHome.AdGuardHome.redirect)" == "redirect" ] && procd_add_reload_trigger firewall
}
isrunning(){
config_load "${CONFIGURATION}"
_isrunning
@ -133,16 +132,19 @@ local r=$?
([ "$r" == "0" ] && echo "running") || ([ "$r" == "1" ] && echo "not run" ) || echo "no bin"
return $r
}
_isrunning(){
config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome/AdGuardHome"
config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome"
[ ! -f "$binpath" ] && return 2
pgrep $binpath 2>&1 >/dev/null && return 0
return 1
}
force_reload(){
config_load "${CONFIGURATION}"
_isrunning && procd_send_signal "$CONFIGURATION" || start
}
get_tz()
{
SET_TZ=""
@ -206,11 +208,13 @@ use_port53()
uci commit dhcp
/etc/init.d/dnsmasq reload
}
do_redirect()
{
config_load "${CONFIGURATION}"
_do_redirect $1
}
_do_redirect()
{
local section="$CONFIGURATION"
@ -271,6 +275,7 @@ _do_redirect()
use_port53
fi
}
get_filesystem()
{
# print out path filesystem
@ -340,7 +345,7 @@ boot_service() {
config_load "${CONFIGURATION}"
config_get waitonboot $CONFIGURATION waitonboot "0"
config_get_bool enabled $CONFIGURATION enabled 0
config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome/AdGuardHome"
config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome"
[ -f "$binpath" ] && start_service
if [ "$enabled" == "1" ] && [ "$waitonboot" == "1" ]; then
procd_open_instance "waitnet"
@ -358,16 +363,18 @@ testbackup(){
restore
fi
}
restore()
{
config_get workdir $CONFIGURATION workdir "/usr/bin/AdGuardHome"
config_get backupwdpath $CONFIGURATION backupwdpath "/usr/bin/AdGuardHome"
config_get workdir $CONFIGURATION workdir "/etc/AdGuardHome"
config_get backupwdpath $CONFIGURATION backupwdpath "/etc/AdGuardHome"
cp -u -r -f $backupwdpath/data $workdir
}
backup() {
config_get backupwdpath $CONFIGURATION backupwdpath "/usr/bin/AdGuardHome"
config_get backupwdpath $CONFIGURATION backupwdpath "/etc/AdGuardHome"
mkdir -p $backupwdpath/data
config_get workdir $CONFIGURATION workdir "/usr/bin/AdGuardHome"
config_get workdir $CONFIGURATION workdir "/etc/AdGuardHome"
config_get backupfile $CONFIGURATION backupfile ""
for one in $backupfile;
do
@ -391,6 +398,7 @@ backup() {
done
done
}
start_service() {
# Reading config
rm /var/run/AdGserverdis >/dev/null 2>&1
@ -411,7 +419,7 @@ start_service() {
return
fi
#what need to do before reload
config_get workdir $CONFIGURATION workdir "/usr/bin/AdGuardHome"
config_get workdir $CONFIGURATION workdir "/etc/AdGuardHome"
config_get backupfile $CONFIGURATION backupfile ""
mkdir -p $workdir/data
@ -436,7 +444,7 @@ start_service() {
fi
fi
local ADDITIONAL_ARGS=""
config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome/AdGuardHome"
config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome"
mkdir -p ${binpath%/*}
ADDITIONAL_ARGS="$ADDITIONAL_ARGS -c $configpath"
@ -492,6 +500,7 @@ start_service() {
echo "luci enable switch=$enabled"
(sleep 10 && [ -z "$(pgrep $binpath)" ] && logger "AdGuardHome" "no process in 10s cancel redirect" && _do_redirect 0 )&
}
reload_service()
{
rm /var/run/AdGlucitest >/dev/null 2>&1
@ -516,6 +525,7 @@ else
return 0
fi
}
stop_service()
{
config_load "${CONFIGURATION}"
@ -530,16 +540,19 @@ stop_service()
echo "AdGuardHome service disabled"
touch /var/run/AdGserverdis
}
boot() {
rc_procd boot_service "$@"
if eval "type service_started" 2>/dev/null >/dev/null; then
service_started
fi
}
test_crontab(){
config_load "${CONFIGURATION}"
do_crontab
}
do_crontab(){
config_get_bool enabled $CONFIGURATION enabled 0
config_get crontab $CONFIGURATION crontab ""
@ -551,8 +564,8 @@ do_crontab(){
[ "$enabled" == "0" ] || [ "${crontab//autoupdate/}" == "$crontab" ] && cronenable=0 || cronenable=1
crontab_editor
config_get workdir $CONFIGURATION workdir "/usr/bin/AdGuardHome"
config_get lastworkdir $CONFIGURATION lastworkdir "/usr/bin/AdGuardHome"
config_get workdir $CONFIGURATION workdir "/etc/AdGuardHome"
config_get lastworkdir $CONFIGURATION lastworkdir "/etc/AdGuardHome"
findstr="/usr/share/AdGuardHome/tailto.sh [0-9]* \$(uci get AdGuardHome.AdGuardHome.workdir)/data/querylog.json"
#[ -n "$lastworkdir" ] && findstr="/usr/share/AdGuardHome/tailto.sh [0-9]* $lastworkdir/data/querylog.json" && [ "$lastworkdir" != "$workdir" ] && replace="${lastworkdir//\//\\/}/${workdir//\//\\/}"
default="0 * * * * /usr/share/AdGuardHome/tailto.sh 2000 \$(uci get AdGuardHome.AdGuardHome.workdir)/data/querylog.json"
@ -582,6 +595,7 @@ do_crontab(){
[ "$cronreload" -gt 0 ] && /etc/init.d/cron restart
#[ "$commit" -gt 0 ] && uci commit AdGuardHome
}
crontab_editor(){
#usage input:
#findstr=
@ -615,5 +629,4 @@ crontab_editor(){
echo "$line" >> $CRON_FILE
fi
fi
}

View File

@ -1,4 +1,5 @@
#!/bin/sh
checkmd5(){
local nowmd5=$(md5sum /etc/hosts)
nowmd5=${nowmd5%% *}
@ -9,6 +10,7 @@ if [ "$nowmd5" != "$lastmd5" ]; then
[ "$1" == "noreload" ] || /etc/init.d/AdGuardHome reload
fi
}
[ "$1" == "del" ] && sed -i '/programaddstart/,/programaddend/d' /etc/hosts && checkmd5 "$2" && exit 0
/usr/bin/awk 'BEGIN{
while ((getline < "/tmp/dhcp.leases") > 0)

View File

@ -1,4 +1,5 @@
#!/bin/sh
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
logread -e AdGuardHome > /tmp/AdGuardHometmp.log
logread -e AdGuardHome -f >> /tmp/AdGuardHometmp.log &

View File

@ -1,5 +1,7 @@
#!/bin/sh
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
checkmd5(){
local nowmd5=$(md5sum /tmp/adguard.list 2>/dev/null)
nowmd5=${nowmd5%% *}
@ -10,6 +12,7 @@ if [ "$nowmd5" != "$lastmd5" ]; then
[ "$1" == "noreload" ] || /etc/init.d/AdGuardHome reload
fi
}
configpath=$(uci get AdGuardHome.AdGuardHome.configpath 2>/dev/null)
[ "$1" == "del" ] && sed -i '/programaddstart/,/programaddend/d' $configpath && checkmd5 "$2" && exit 0
gfwupstream=$(uci get AdGuardHome.AdGuardHome.gfwupstream 2>/dev/null)

View File

@ -1,4 +1,5 @@
#!/bin/sh
tail -n $1 "$2" > /var/run/tailtmp
cat /var/run/tailtmp > "$2"
rm /var/run/tailtmp

View File

@ -1,4 +1,5 @@
#!/bin/bash
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
binpath=$(uci get AdGuardHome.AdGuardHome.binpath)
if [ -z "$binpath" ]; then
@ -21,6 +22,7 @@ check_wgetcurl(){
[ "$1" == "1" ] && (opkg install curl ; check_wgetcurl 2 ; return)
echo error curl and wget && EXIT 1
}
check_latest_version(){
check_wgetcurl
latest_ver="$($downloader - 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)"
@ -53,6 +55,7 @@ check_latest_version(){
EXIT 0
fi
}
doupx(){
Archt="$(opkg info kernel | grep Architecture | awk -F "[ _]" '{print($2)}')"
case $Archt in
@ -114,6 +117,7 @@ doupx(){
fi
rm /tmp/upx-${upx_latest_ver}-${Arch}_linux.tar.xz
}
doupdate_core(){
echo -e "Updating core..."
mkdir -p "/tmp/AdGuardHomeupdate"
@ -215,13 +219,14 @@ doupdate_core(){
echo -e "Local version: ${latest_ver}, cloud version: ${latest_ver}.\n"
EXIT 0
}
EXIT(){
rm /var/run/update_core 2>/dev/null
[ "$1" != "0" ] && touch /var/run/update_core_error
exit $1
}
main(){
main(){
check_if_already_running
check_latest_version $1
}

View File

@ -1,4 +1,5 @@
#!/bin/sh
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
count=0
while :

View File

@ -1,4 +1,5 @@
#!/bin/sh
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
configpath=$(uci get AdGuardHome.AdGuardHome.configpath)
while :