Skip to content

Commit

Permalink
Merge pull request #328 from thuantran/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jumpsmm7 authored Mar 20, 2022
2 parents a25953b + 23a0585 commit e987610
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
68 changes: 34 additions & 34 deletions gen/manager
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -193,35 +191,37 @@ 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 &
;;
"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
2 changes: 1 addition & 1 deletion gen/manager.md5sum
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a1cfa9ad94a95887e4806f23ca71af39
764f53bfab6e6b3ce2529c0a801ba354
4 changes: 2 additions & 2 deletions installer
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# | | | \| | (___ | | / \ | | | | | |__ | |__) | Current Maintainer: #
# | | | . ` |\___ \ | | / /\ \ | | | | | __| | _ / SomeWhereOverTheRainBow #
# _| |_| |\ |____) | | |/ ____ \| |____| |____| |____| | \ \ #
#|_____|_| \_|_____/ |_/_/ \_|______|______|______|_| \_\ v2.3.8 #
#|_____|_| \_|_____/ |_/_/ \_|______|______|______|_| \_\ v2.3.9 #
# #
########################################################################################################

Expand All @@ -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)"

Expand Down
2 changes: 1 addition & 1 deletion installer.md5sum
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7f32960bbd7bf81f907cf9ab05b9307a
64d7e11e49b738df6b56531d6f59305d

0 comments on commit e987610

Please sign in to comment.