|
@@ -1,7 +1,7 @@
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
-
|
|
|
+
|
|
|
USE_PROCD=1
|
|
|
-
|
|
|
+
|
|
|
START=95
|
|
|
STOP=01
|
|
|
|
|
@@ -29,7 +29,7 @@ set_forward_dnsmasq()
|
|
|
done
|
|
|
uci delete dhcp.@dnsmasq[0].resolvfile 2>/dev/null
|
|
|
uci set dhcp.@dnsmasq[0].noresolv=1
|
|
|
- uci commit dhcp
|
|
|
+ uci commit dhcp
|
|
|
/etc/init.d/dnsmasq restart
|
|
|
}
|
|
|
|
|
@@ -115,7 +115,7 @@ 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() {
|
|
@@ -128,22 +128,22 @@ get_tz()
|
|
|
SET_TZ=""
|
|
|
|
|
|
if [ -e "/etc/localtime" ]; then
|
|
|
- return
|
|
|
+ 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
|
|
|
+ return
|
|
|
fi
|
|
|
-
|
|
|
+
|
|
|
SET_TZ=$tz
|
|
|
}
|
|
|
|
|
@@ -187,7 +187,7 @@ use_port53()
|
|
|
/etc/init.d/dnsmasq reload
|
|
|
}
|
|
|
|
|
|
-do_redirect()
|
|
|
+do_redirect()
|
|
|
{
|
|
|
config_load "${CONFIGURATION}"
|
|
|
local section="$CONFIGURATION"
|
|
@@ -213,7 +213,7 @@ do_redirect()
|
|
|
if [ "$old_enabled" = "1" -a "$old_redirect" == "exchange" ]; then
|
|
|
AdGuardHome_PORT=$(uci get dhcp.@dnsmasq[0].port 2>/dev/null)
|
|
|
fi
|
|
|
-
|
|
|
+
|
|
|
if [ "$old_redirect" != "$redirect" ] || [ "$old_port" != "$AdGuardHome_PORT" ] || [ "$old_enabled" = "1" -a "$enabled" = "0" ]; then
|
|
|
if [ "$old_redirect" != "none" ]; then
|
|
|
if [ "$old_redirect" == "redirect" -a "$old_port" != "0" ]; then
|
|
@@ -267,18 +267,18 @@ get_filesystem()
|
|
|
}}}{
|
|
|
split($0,d,"/");
|
|
|
if ("/" in fs)
|
|
|
- {
|
|
|
+ {
|
|
|
result1=fs["/"];
|
|
|
}
|
|
|
if ("/" in pt)
|
|
|
- {
|
|
|
+ {
|
|
|
result2=pt["/"];
|
|
|
}
|
|
|
for (i=2;i<=length(d);i++)
|
|
|
{
|
|
|
p[i]=p[i-1]"/"d[i];
|
|
|
if (p[i] in fs)
|
|
|
- {
|
|
|
+ {
|
|
|
result1=fs[p[i]];
|
|
|
result2=pt[p[i]];
|
|
|
}
|
|
@@ -373,6 +373,7 @@ backup() {
|
|
|
start_service() {
|
|
|
# Reading config
|
|
|
config_load "${CONFIGURATION}"
|
|
|
+ # update password
|
|
|
config_get hashpass $CONFIGURATION hashpass ""
|
|
|
if [ -n "$hashpass" ]; then
|
|
|
config_editor "users.password" "$hashpass" "$configpath"
|
|
@@ -380,26 +381,52 @@ start_service() {
|
|
|
fi
|
|
|
local enabled
|
|
|
config_get_bool enabled $CONFIGURATION enabled 0
|
|
|
-
|
|
|
- if [ "$enabled" == "1" ]; then
|
|
|
+ # update crontab
|
|
|
+ do_crontab
|
|
|
+ if [ "$enabled" == "0" ]; then
|
|
|
+ procd_kill $CONFIGURATION
|
|
|
+ do_redirect 0
|
|
|
+ return
|
|
|
+ fi
|
|
|
+ #what need to do before reload
|
|
|
+ config_get workdir $CONFIGURATION workdir "/usr/bin/AdGuardHome"
|
|
|
+ ADDITIONAL_ARGS="$ADDITIONAL_ARGS -w $workdir"
|
|
|
+
|
|
|
+ config_get backupfile $CONFIGURATION backupfile ""
|
|
|
+ mkdir -p $workdir/data
|
|
|
+ if [ -n "$backupfile" ] && [ ! -d "$workdir/data" ]; then
|
|
|
+ restore
|
|
|
+ fi
|
|
|
+ # for overlay data-stk-oo not suppport
|
|
|
+ local cwdfs=$(get_filesystem $workdir)
|
|
|
+ echo "workdir is a $cwdfs filesystem"
|
|
|
+ if [ "$cwdfs" == "jffs2" ]; then
|
|
|
+ echo "fs error ln db to tmp $workdir $cwdfs"
|
|
|
+ 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 2>/dev/null
|
|
|
+ ln -s /tmp/stats.db $workdir/data/stats.db 2>/dev/null
|
|
|
+ fi
|
|
|
+ touch $workdir/data/sessions.db
|
|
|
+ if [ ! -L $workdir/data/sessions.db ]; then
|
|
|
+ mv -f $workdir/data/sessions.db /tmp/sessions.db 2>/dev/null
|
|
|
+ ln -s /tmp/sessions.db $workdir/data/sessions.db 2>/dev/null
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+ #reload
|
|
|
+ procd_send_signal $CONFIGURATION
|
|
|
local ADDITIONAL_ARGS=""
|
|
|
config_get configpath $CONFIGURATION configpath "/etc/AdGuardHome.yaml"
|
|
|
config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome/AdGuardHome"
|
|
|
-
|
|
|
+
|
|
|
echo -e "$configpath\n$binpath">/lib/upgrade/keep.d/luci-app-adguardhome
|
|
|
mkdir -p ${binpath%/*}
|
|
|
ADDITIONAL_ARGS="$ADDITIONAL_ARGS -c $configpath"
|
|
|
-
|
|
|
+
|
|
|
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"
|
|
|
- config_get backupfile $CONFIGURATION backupfile ""
|
|
|
- mkdir -p $workdir/data
|
|
|
- if [ -n "$backupfile" ] && [ ! -d "$workdir/data" ]; then
|
|
|
- restore
|
|
|
- fi
|
|
|
+
|
|
|
echo -e "$configpath\n$binpath">/lib/upgrade/keep.d/luci-app-adguardhome
|
|
|
# hack to save config file when upgrade system
|
|
|
config_get keepdb $CONFIGURATION keepdb 0
|
|
@@ -410,7 +437,7 @@ start_service() {
|
|
|
if [ -n "$logfile" ]; then
|
|
|
ADDITIONAL_ARGS="$ADDITIONAL_ARGS -l $logfile"
|
|
|
fi
|
|
|
-
|
|
|
+
|
|
|
if [ ! -f "$binpath" ]; then
|
|
|
do_redirect 0
|
|
|
rm /var/run/update_core_error 2>/dev/null
|
|
@@ -418,38 +445,21 @@ start_service() {
|
|
|
sh /usr/share/AdGuardHome/update_core.sh 2>&1 >/tmp/AdGuardHome_update.log || touch /var/run/update_core_error
|
|
|
rm /var/run/update_core
|
|
|
exit 0
|
|
|
- fi
|
|
|
+ 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)
|
|
|
- echo "workdir is a $cwdfs filesystem"
|
|
|
- if [ "$cwdfs" == "jffs2" ]; then
|
|
|
- echo "fs error ln db to tmp $workdir $cwdfs"
|
|
|
- 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 2>/dev/null
|
|
|
- ln -s /tmp/stats.db $workdir/data/stats.db 2>/dev/null
|
|
|
- fi
|
|
|
- touch $workdir/data/sessions.db
|
|
|
- if [ ! -L $workdir/data/sessions.db ]; then
|
|
|
- mv -f $workdir/data/sessions.db /tmp/sessions.db 2>/dev/null
|
|
|
- ln -s /tmp/sessions.db $workdir/data/sessions.db 2>/dev/null
|
|
|
- fi
|
|
|
- fi
|
|
|
+
|
|
|
procd_open_instance
|
|
|
get_tz
|
|
|
- if [ -n "$SET_TZ" ]; then
|
|
|
- procd_set_param env TZ="$SET_TZ"
|
|
|
+ if [ -n "$SET_TZ" ]; then
|
|
|
+ procd_set_param env TZ="$SET_TZ"
|
|
|
fi
|
|
|
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
|
|
|
procd_set_param limits core="unlimited"
|
|
|
- procd_set_param stderr 1
|
|
|
+ procd_set_param stderr 1
|
|
|
# pass config to script on start
|
|
|
procd_set_param command $binpath $ADDITIONAL_ARGS
|
|
|
procd_set_param file "$configpath"
|
|
@@ -467,31 +477,14 @@ start_service() {
|
|
|
echo "no config start watching"
|
|
|
fi
|
|
|
fi
|
|
|
- do_crontab
|
|
|
echo "AdGuardHome turn on"
|
|
|
(sleep 10 && [ -z "$(pgrep $binpath)" ] && logger "AdGuardHome" "no process in 10s cancel redirect" && do_redirect 0 )&
|
|
|
- fi
|
|
|
}
|
|
|
reload_service()
|
|
|
-{
|
|
|
+{
|
|
|
rm /var/run/AdGucitest 2>&1 >/dev/null
|
|
|
- config_load "${CONFIGURATION}"
|
|
|
echo "AdGuardHome reloading"
|
|
|
- config_get_bool enabled $CONFIGURATION enabled 0
|
|
|
- if [ "$enabled" == "0" ]; then
|
|
|
- procd_kill $CONFIGURATION
|
|
|
- do_redirect 0
|
|
|
- do_crontab
|
|
|
- config_get hashpass $CONFIGURATION hashpass ""
|
|
|
- if [ -n "$hashpass" ]; then
|
|
|
- config_editor "users.password" "$hashpass" "$configpath"
|
|
|
- uci set $CONFIGURATION.$CONFIGURATION.hashpass=""
|
|
|
- fi
|
|
|
- else
|
|
|
- procd_send_signal $CONFIGURATION
|
|
|
- start
|
|
|
- fi
|
|
|
- echo "enabled=$enabled"
|
|
|
+ start
|
|
|
}
|
|
|
|
|
|
del_querylog(){
|
|
@@ -504,7 +497,7 @@ if [ "$btarget"x == "$wtarget"x ]; then
|
|
|
return 0
|
|
|
fi
|
|
|
if [ "$btarget" \> "$wtarget" ]; then
|
|
|
- rm -f $backupwdpath/data/$btarget
|
|
|
+ rm -f $backupwdpath/data/$btarget
|
|
|
return 0
|
|
|
else
|
|
|
rm -f $workdir/data/$wtarget
|
|
@@ -531,40 +524,38 @@ boot() {
|
|
|
}
|
|
|
do_crontab(){
|
|
|
config_get crontab $CONFIGURATION crontab ""
|
|
|
- local findstr default enable
|
|
|
+ local findstr default cronenable
|
|
|
findstr="/usr/share/AdGuardHome/update_core.sh"
|
|
|
default="#30 3 * * * /usr/share/AdGuardHome/update_core.sh 2>&1"
|
|
|
- [ "${crontab//autoupdate/}" == "$crontab" ] && enable=0 || enable=1
|
|
|
+ [ "$enabled" == "0" ] || [ "${crontab//autoupdate/}" == "$crontab" ] && cronenable=0 || cronenable=1
|
|
|
crontab_editor
|
|
|
-
|
|
|
+
|
|
|
findstr="tail -n [0-9]* .*/data/querylog.json > .*/data/querylog.json"
|
|
|
default="#0 * * * * tail -n 2000 $workdir/data/querylog.json > $workdir/data/querylog.json"
|
|
|
- [ "${crontab//cutquerylog/}" == "$crontab" ] && enable=0 || enable=1
|
|
|
+ [ "$enabled" == "0" ] || [ "${crontab//cutquerylog/}" == "$crontab" ] && cronenable=0 || cronenable=1
|
|
|
crontab_editor
|
|
|
-
|
|
|
+
|
|
|
config_get logfile $CONFIGURATION logfile ""
|
|
|
- if [ "$logfile" != "syslog" -a "$logfile" != "" ]; then
|
|
|
- findstr="tail -n [0-9]* $logfile > $logfile"
|
|
|
- default="#30 3 * * * tail -n 2000 $logfile > $logfile"
|
|
|
- [ "${crontab//cutruntimelog/}" == "$crontab" ] && enable=0 || enable=1
|
|
|
- crontab_editor
|
|
|
- fi
|
|
|
-
|
|
|
+ findstr="tail -n [0-9]* $logfile > $logfile"
|
|
|
+ default="#30 3 * * * tail -n 2000 $logfile > $logfile"
|
|
|
+ [ "$logfile" != "syslog" -a "$logfile" != "" ] || [ "$enabled" == "0" ] || [ "${crontab//cutruntimelog/}" == "$crontab" ] && cronenable=0 || cronenable=1
|
|
|
+ crontab_editor
|
|
|
+
|
|
|
findstr="/usr/share/AdGuardHome/addhost.sh"
|
|
|
default="#0 * * * * /usr/share/AdGuardHome/addhost.sh"
|
|
|
- [ "${crontab//autohost/}" == "$crontab" ] && enable=0 || enable=1
|
|
|
+ [ "$enabled" == "0" ] || [ "${crontab//autohost/}" == "$crontab" ] && cronenable=0 || cronenable=1
|
|
|
crontab_editor
|
|
|
- [ "$enable" == "0" ] && /usr/share/AdGuardHome/addhost.sh del
|
|
|
-
|
|
|
+ [ "$cronenable" == "0" ] && /usr/share/AdGuardHome/addhost.sh "del" "noreload" || /usr/share/AdGuardHome/addhost.sh "" "noreload"
|
|
|
+
|
|
|
findstr="/usr/share/AdGuardHome/gfw2adg.sh"
|
|
|
default="#30 3 * * * /usr/share/AdGuardHome/gfw2adg.sh"
|
|
|
- [ "${crontab//autogfw/}" == "$crontab" ] && enable=0 || enable=1
|
|
|
+ [ "$enabled" == "0" ] || [ "${crontab//autogfw/}" == "$crontab" ] && cronenable=0 || cronenable=1
|
|
|
crontab_editor
|
|
|
}
|
|
|
crontab_editor(){
|
|
|
local line="$(grep "$findstr" $CRON_FILE)"
|
|
|
if [ -n "$line" -a "${line:0:1}" != "#" ]; then
|
|
|
- if [ $enable -eq 1 ]; then
|
|
|
+ if [ $cronenable -eq 1 ]; then
|
|
|
return
|
|
|
else
|
|
|
sed -i "\,$findstr,d" $CRON_FILE
|
|
@@ -572,7 +563,7 @@ crontab_editor(){
|
|
|
/etc/init.d/cron restart
|
|
|
fi
|
|
|
else
|
|
|
- if [ $enable -eq 1 ]; then
|
|
|
+ if [ $cronenable -eq 1 ]; then
|
|
|
[ -z "$line" ] && line="$default"
|
|
|
sed -i "\,$findstr,d" $CRON_FILE
|
|
|
echo "${line:1}" >> $CRON_FILE
|