From 130675d0857e3840653bef0c12e0a65b5875e911 Mon Sep 17 00:00:00 2001 From: minicx Date: Sat, 18 Feb 2023 19:33:33 +0300 Subject: [PATCH 1/2] Added new feature --- Dockerfile | 9 +++++++-- assets/root/etc/init.d/tor_settings | 9 +++++++++ assets/root/tor.sh | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 assets/root/etc/init.d/tor_settings create mode 100644 assets/root/tor.sh diff --git a/Dockerfile b/Dockerfile index 90ad3e3..59d7750 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,9 @@ FROM dockage/alpine:3.16.2-openrc COPY assets/root/ / -RUN apk --no-cache --update --upgrade add tor privoxy socat \ +RUN chmod +x /tor.sh + +RUN apk --no-cache --update --upgrade add tor privoxy socat bash \ && mv /etc/tor/torrc.sample /etc/tor/torrc \ && mv /etc/privoxy/config.new /etc/privoxy/config \ && mv /etc/privoxy/default.action.new /etc/privoxy/default.action \ @@ -20,8 +22,11 @@ RUN apk --no-cache --update --upgrade add tor privoxy socat \ -e 's/#ControlPort 9051/ControlPort 9052/g' \ -e 's/#%include \/etc\/torrc\.d\/\*\.conf/%include \/etc\/torrc\.d\/\*\.conf/g' \ /etc/tor/torrc \ + && rc-update add tor_settings \ && rc-update add tor \ && rc-update add privoxy \ - && rc-update add socat + && rc-update add socat + + EXPOSE 9050/tcp 9051/tcp 8118/tcp diff --git a/assets/root/etc/init.d/tor_settings b/assets/root/etc/init.d/tor_settings new file mode 100644 index 0000000..14508a3 --- /dev/null +++ b/assets/root/etc/init.d/tor_settings @@ -0,0 +1,9 @@ +#!/sbin/openrc-run + +description="Sets up tor settings from envoriment" + +start() { + ebegin "Setting up Tor settings" + bash /tor.sh + eend $? +} diff --git a/assets/root/tor.sh b/assets/root/tor.sh new file mode 100644 index 0000000..92684a3 --- /dev/null +++ b/assets/root/tor.sh @@ -0,0 +1,20 @@ +#!/bin/bash +for env in $(printenv | grep '^TOR_'); do + name="$(cut -c5- <<< ${env%%=*})" + val="\"${env##*=}\"" + [[ "$name" =~ _ ]] && continue + [[ "$val" =~ ^\"([0-9]+|false|true)\"$ ]] && val="$(sed 's|"||g' <<< $val)" + if grep -q "^$name" /etc/tor/torrc; then + sed -i "/^$name/s| .*| $val|" /etc/tor/torrc + else + echo "$name $val" >>/etc/tor/torrc + fi +done + +LOCATION="$(cut -c10- <<< $(printenv | grep 'LOCATION'))" +printf "${LOCATION}" +if [ -n "$LOCATION" ]; then + sed -i '/^StrictNodes/d; /^ExitNodes/d' /etc/tor/torrc + echo "StrictNodes 1" >> /etc/tor/torrc + echo "ExitNodes {$LOCATION}" >> /etc/tor/torrc +fi From 2af51e430905c0dc221c93e8529d3251c54629bc Mon Sep 17 00:00:00 2001 From: minicx <39405619+loss-and-quick@users.noreply.github.com> Date: Sun, 19 Feb 2023 17:43:15 +0300 Subject: [PATCH 2/2] fixed issue with spaces --- assets/root/tor.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/assets/root/tor.sh b/assets/root/tor.sh index 92684a3..e90e4ae 100644 --- a/assets/root/tor.sh +++ b/assets/root/tor.sh @@ -1,15 +1,14 @@ #!/bin/bash -for env in $(printenv | grep '^TOR_'); do +while read -r env; do name="$(cut -c5- <<< ${env%%=*})" - val="\"${env##*=}\"" + val="${env##*=}" [[ "$name" =~ _ ]] && continue - [[ "$val" =~ ^\"([0-9]+|false|true)\"$ ]] && val="$(sed 's|"||g' <<< $val)" if grep -q "^$name" /etc/tor/torrc; then sed -i "/^$name/s| .*| $val|" /etc/tor/torrc else echo "$name $val" >>/etc/tor/torrc fi -done +done <<< $(printenv | grep '^TOR_') LOCATION="$(cut -c10- <<< $(printenv | grep 'LOCATION'))" printf "${LOCATION}"