diff --git a/gen/manager b/gen/manager index 4e6a484..dc1b8c8 100644 --- a/gen/manager +++ b/gen/manager @@ -2,6 +2,7 @@ [ -f /jffs/dnscrypt/.config ] && . /jffs/dnscrypt/.config +{ for PID in $(pidof "$(basename "$0")"); do if { awk '{ print }' "/proc/${PID}/cmdline" | grep -q monitor-start; } && [ "$PID" != "$$" ]; then { MON_PID="$PID"; }; fi; done; }; NAME="$(basename "$0")[$$]" append_on_demand () { @@ -108,15 +109,14 @@ start_monitor () { local COUNT local EXIT local RANDOM - COUNT="0" EXIT="0" RANDOM="0" logger -st "$NAME" "Starting_Monitor: $NAME" while true; do if [ "$EXIT" = "1" ]; then logger -st "$NAME" "Stopping_Monitor: $NAME"; trap - 1 2 3 6 10 12 15; stop_dnscrypt; break; fi if [ "$EXIT" = "2" ]; then start_dnscrypt; EXIT="0"; fi - if [ "$COUNT" -gt 90 ]; then COUNT="0"; timezone; "$0" opendns-update; fi - COUNT="$((COUNT + 1))" + if [ -z "$COUNT" ]; then COUNT="0"; timezone; "$0" opendns-update; fi + if [ "$COUNT" = "90" ]; then COUNT="0"; else COUNT="$((COUNT + 1))"; fi if [ -f "/jffs/dnscrypt/dnscrypt-proxy" ]; then case "$COUNT" in "30"|"60"|"90") @@ -144,27 +144,25 @@ start_monitor () { } stop_monitor () { - [ "$1" = "1" ] && { for PID in $(pidof "$(basename "$0")"); do if { awk '{ print }' "/proc/${PID}/cmdline" | grep -q monitor-start; } && [ "$PID" != "$$" ]; then { kill -s 10 "$PID" 2>/dev/null; }; fi; done; }; - [ "$1" = "2" ] && { for PID in $(pidof "$(basename "$0")"); do if { awk '{ print }' "/proc/${PID}/cmdline" | grep -q monitor-start; } && [ "$PID" != "$$" ]; then { kill -s 12 "$PID" 2>/dev/null; }; fi; done; }; + local SIGNAL + case "$1" in + "$MON_PID") + SIGNAL="12" + ;; + "$$") + if [ -n "$MON_PID" ]; then SIGNAL="10"; else { stop_dnscrypt; }; fi + ;; + esac + [ -n "$SIGNAL" ] && { kill -s "$SIGNAL" "$MON_PID" 2>/dev/null; }; } timezone () { - local SANITY - local NOW local TIMEZONE local TARGET - local LINK - SANITY="$(date -u -r "$0" '+%s')" - NOW="$(date -u '+%s')" TIMEZONE="/jffs/dnscrypt/localtime" TARGET="/etc/localtime" - LINK="$(readlink "$TARGET")" - if [ -f "$TIMEZONE" ] && [ "$LINK" = "$TIMEZONE" ]; then - [ "$NOW" -ge "$SANITY" ] && { touch "$0"; }; - elif [ -f "$TIMEZONE" ]; then - ln -sf $TIMEZONE $TARGET - [ "$NOW" -le "$SANITY" ] && { date -u -s "$(date -u -r "$0" '+%Y-%m-%d %H:%M:%S')"; }; - fi + if { [ ! -f "$TARGET" ] && [ -f "$TIMEZONE" ]; }; then { ln -sf "$TIMEZONE" "$TARGET"; }; fi + if [ -f "$TARGET" ] || [ "$(readlink "$TARGET")" ]; then { if [ "$(date -u '+%s')" -le "$(date -u -r "$0" '+%s')" ]; then { date -u -s "$(date -u -r "$0" '+%Y-%m-%d %H:%M:%S')"; }; else { touch "$0"; }; fi; }; fi } update_opendns () { @@ -193,14 +191,13 @@ case "$1" in dnsmasq_params ;; "start"|"restart"|"dnscrypt-start") - if [ -z "$(pidof dnscrypt-proxy)" ]; then { "$0" init-start >/dev/null 2>&1; }; else { stop_monitor 2; }; fi + { "$0" init-start >/dev/null 2>&1; }; ;; "stop"|"kill"|"dnscrypt-stop") { "$0" services-stop >/dev/null 2>&1; }; ;; "monitor-start") - { stop_monitor 1; }; - { start_monitor & }; + if [ -n "$MON_PID" ]; then { stop_monitor "$MON_PID"; }; else { start_monitor & }; fi ;; "opendns-update") update_opendns 0 & @@ -208,20 +205,23 @@ case "$1" in "init-start"|"services-stop") timezone if [ -n "$RAN_PRV" ]; then { kill -s 9 "$(pidof haveged jitterentropy-rngd rngd stty)" 2>/dev/null || killall -q -9 haveged jitterentropy-rngd rngd stty 2>/dev/null; }; fi - if [ "$1" = "init-start" ]; then - { printf "1" > /proc/sys/vm/overcommit_memory; }; - case "$RAN_PRV" in - "haveged") - { /jffs/dnscrypt/haveged -w 1024 -d 32 -i 32 -v 1; }; - ;; - "rngd") - init_hwrng & - ;; - esac - { "$0" monitor-start; }; - elif [ "$1" = "services-stop" ]; then - { stop_monitor 1; }; - fi + case "$1" in + "init-start") + { printf "1" > /proc/sys/vm/overcommit_memory; }; + case "$RAN_PRV" in + "haveged") + { /jffs/dnscrypt/haveged -w 1024 -d 32 -i 32 -v 1; }; + ;; + "rngd") + init_hwrng & + ;; + esac + { "$0" monitor-start; }; + ;; + "services-stop") + { stop_monitor "$$"; }; + ;; + esac ;; esac check_dns_environment diff --git a/gen/manager.md5sum b/gen/manager.md5sum index 7b967c0..2c0a7fb 100644 --- a/gen/manager.md5sum +++ b/gen/manager.md5sum @@ -1 +1 @@ -a1cfa9ad94a95887e4806f23ca71af39 +764f53bfab6e6b3ce2529c0a801ba354 diff --git a/installer b/installer index 4166ae0..37d06d4 100755 --- a/installer +++ b/installer @@ -19,7 +19,7 @@ # | | | \| | (___ | | / \ | | | | | |__ | |__) | Current Maintainer: # # | | | . ` |\___ \ | | / /\ \ | | | | | __| | _ / SomeWhereOverTheRainBow # # _| |_| |\ |____) | | |/ ____ \| |____| |____| |____| | \ \ # -#|_____|_| \_|_____/ |_/_/ \_|______|______|______|_| \_\ v2.3.8 # +#|_____|_| \_|_____/ |_/_/ \_|______|______|______|_| \_\ v2.3.9 # # # ######################################################################################################## @@ -37,7 +37,7 @@ # shellcheck disable=SC3057 # shellcheck disable=SC3060 -DI_VERSION="v2.3.8" +DI_VERSION="v2.3.9" readonly LATEST_URL="https://api.github.com/repos/jedisct1/dnscrypt-proxy/releases/latest" readonly DNSCRYPT_VER="$(curl -sL "$LATEST_URL" | grep "tag_name" | head -1 | cut -d \" -f 4)" diff --git a/installer.md5sum b/installer.md5sum index bb33f6d..2ee09c8 100644 --- a/installer.md5sum +++ b/installer.md5sum @@ -1 +1 @@ -7f32960bbd7bf81f907cf9ab05b9307a +64d7e11e49b738df6b56531d6f59305d