From cbe45426ce1c0e2eed673477da589637cc78033f Mon Sep 17 00:00:00 2001 From: Benjamin Dweck Date: Thu, 22 Oct 2020 19:16:10 +0200 Subject: [PATCH] Tor docker: parameterized hostname and added command for onion hostname output --- tor/Dockerfile | 7 +++---- tor/svc-hostname | 10 ++++++++++ tor/tor.sh | 11 ++++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) create mode 100755 tor/svc-hostname diff --git a/tor/Dockerfile b/tor/Dockerfile index d1ef4a1..ceb4e3a 100644 --- a/tor/Dockerfile +++ b/tor/Dockerfile @@ -11,10 +11,9 @@ RUN apk add --no-cache curl tor && \ HEALTHCHECK --interval=60s --timeout=15s --start-period=20s \ CMD curl -s --socks5 127.0.0.1:9050 'https://check.torproject.org/' | grep -qm1 Congratulations -COPY tor.sh /usr/bin/ - -#VOLUME ["/var/lib/tor/svc"] +COPY tor.sh /usr/local/bin/ +COPY svc-hostname /usr/local/bin/ #USER tor -CMD ["tor.sh"] +CMD [ "tor.sh", "$SVC_HOST" ] diff --git a/tor/svc-hostname b/tor/svc-hostname new file mode 100755 index 0000000..5e4aace --- /dev/null +++ b/tor/svc-hostname @@ -0,0 +1,10 @@ +#!/bin/sh + +while ! curl -s --socks5 127.0.0.1:9050 'https://check.torproject.org/' | grep -qm1 Congratulations +do + sleep 0.5 +done + +echo "*****" +echo "* Service Onion Hostname: $(cat /var/lib/tor/svc/hostname)" +echo "*****" diff --git a/tor/tor.sh b/tor/tor.sh index ce118f6..03f29af 100755 --- a/tor/tor.sh +++ b/tor/tor.sh @@ -1,5 +1,10 @@ #!/bin/sh -IP_BROKER=$(nslookup broker | awk '/^Address: / { print $2 }' | tail -n1 | sed -e 's/[[:space:]]//g') -sed -i "s/broker/$IP_BROKER/g" /etc/tor/torrc -tor \ No newline at end of file +HOSTNAME=$1 + +IP_BROKER=$(nslookup $HOSTNAME | awk '/^Address: / { print $2 }' | tail -n1 | sed -e 's/[[:space:]]//g') +sed -i "s/$HOSTNAME/$IP_BROKER/g" /etc/tor/torrc + +/usr/local/bin/svc-hostname & + +tor