1
1
mirror of https://github.com/dnscrypt/dnscrypt-server-docker synced 2024-11-22 19:42:03 +01:00

Merge pull request #59 from PeterDaveHello/refactor-shellscripts

Refactor shellscripts
This commit is contained in:
Frank Denis 2019-05-12 13:40:13 +02:00 committed by GitHub
commit 81f3ccbf81
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 16 deletions

@ -10,7 +10,7 @@ prune() {
} }
rotation_needed() { rotation_needed() {
if [ $(/usr/bin/find "$STKEYS_DIR" -name '*.cert' -type f -cmin -720 -print -quit | wc -l | sed 's/[^0-9]//g') -le 0 ]; then if [ "$(/usr/bin/find "$STKEYS_DIR" -name '*.cert' -type f -cmin -720 -print -quit | wc -l | sed 's/[^0-9]//g')" -le 0 ]; then
echo true echo true
else else
echo false echo false
@ -54,7 +54,7 @@ provider_name=$(cat "$KEYS_DIR/provider_name")
mkdir -p "$STKEYS_DIR" mkdir -p "$STKEYS_DIR"
prune prune
[ $(rotation_needed) = true ] && new_key [ "$(rotation_needed)" = true ] && new_key
[ -r "$BLACKLIST" ] && blacklist_opt="--blacklist-file=${BLACKLIST}" [ -r "$BLACKLIST" ] && blacklist_opt="--blacklist-file=${BLACKLIST}"
@ -64,5 +64,5 @@ exec /opt/dnscrypt-wrapper/sbin/dnscrypt-wrapper \
--resolver-address=127.0.0.1:553 \ --resolver-address=127.0.0.1:553 \
--provider-name="$provider_name" \ --provider-name="$provider_name" \
--provider-cert-file="$(stcerts_files)" \ --provider-cert-file="$(stcerts_files)" \
--crypt-secretkey-file=$(stkeys_files) \ --crypt-secretkey-file="$(stkeys_files)" \
$blacklist_opt $blacklist_opt

@ -9,7 +9,7 @@ KEYS_DIR="/opt/dnscrypt-wrapper/etc/keys"
# -N provider-name -E external-ip-address:port # -N provider-name -E external-ip-address:port
init() { init() {
if [ $(is_initialized) = yes ]; then if [ "$(is_initialized)" = yes ]; then
start start
exit $? exit $?
fi fi
@ -65,7 +65,7 @@ provider_info() {
} }
is_initialized() { is_initialized() {
if [ ! -f "${KEYS_DIR}/public.key" -a ! -f "${KEYS_DIR}/secret.key" -a ! -f "${KEYS_DIR}/provider_name" ]; then if [ ! -f "${KEYS_DIR}/public.key" ] && [ ! -f "${KEYS_DIR}/secret.key" ] && [ ! -f "${KEYS_DIR}/provider_name" ]; then
echo no echo no
else else
echo yes echo yes
@ -73,7 +73,7 @@ is_initialized() {
} }
ensure_initialized() { ensure_initialized() {
if [ $(is_initialized) = no ]; then if [ "$(is_initialized)" = no ]; then
echo "Please provide an initial configuration (init -N <provider_name> -E <external IP>)" >&2 echo "Please provide an initial configuration (init -N <provider_name> -E <external IP>)" >&2
exit 1 exit 1
fi fi

@ -6,13 +6,13 @@ KEYS_DIR="/opt/dnscrypt-wrapper/etc/keys"
STKEYS_DIR="${KEYS_DIR}/short-term" STKEYS_DIR="${KEYS_DIR}/short-term"
rotation_needed() { rotation_needed() {
if [ $(/usr/bin/find "$STKEYS_DIR" -type f -cmin -720 -print -quit | wc -l | sed 's/[^0-9]//g') -le 0 ]; then if [ "$(/usr/bin/find "$STKEYS_DIR" -type f -cmin -720 -print -quit | wc -l | sed 's/[^0-9]//g')" -le 0 ]; then
echo true echo true
else else
echo false echo false
fi fi
} }
[ $(rotation_needed) = true ] || exit 0 [ "$(rotation_needed)" = true ] || exit 0
sv status dnscrypt-wrapper | egrep -q '^run:' || exit 0 sv status dnscrypt-wrapper | grep -E -q '^run:' || exit 0
sv restart dnscrypt-wrapper sv restart dnscrypt-wrapper

@ -4,17 +4,17 @@ KEYS_DIR="/opt/dnscrypt-wrapper/etc/keys"
ZONES_DIR="/opt/unbound/etc/unbound/zones" ZONES_DIR="/opt/unbound/etc/unbound/zones"
reserved=12582912 reserved=12582912
availableMemory=$((1024 * $( (fgrep MemAvailable /proc/meminfo || fgrep MemTotal /proc/meminfo) | sed 's/[^0-9]//g' ) )) availableMemory=$((1024 * $( (grep -F MemAvailable /proc/meminfo || grep -F MemTotal /proc/meminfo) | sed 's/[^0-9]//g' ) ))
if [ $availableMemory -le $(($reserved * 2)) ]; then if [ $availableMemory -le $((reserved * 2)) ]; then
echo "Not enough memory" >&2 echo "Not enough memory" >&2
exit 1 exit 1
fi fi
availableMemory=$(($availableMemory - $reserved)) availableMemory=$((availableMemory - reserved))
msg_cache_size=$(($availableMemory / 3)) msg_cache_size=$((availableMemory / 3))
rr_cache_size=$(($availableMemory / 3)) rr_cache_size=$((availableMemory / 3))
nproc=$(nproc) nproc=$(nproc)
if [ $nproc -gt 1 ]; then if [ "$nproc" -gt 1 ]; then
threads=$(($nproc - 1)) threads=$((nproc - 1))
else else
threads=1 threads=1
fi fi