diff --git a/Dockerfile b/Dockerfile index ccb7a11..e6cca18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,9 @@ FROM dockage/alpine:3.19-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..e90e4ae --- /dev/null +++ b/assets/root/tor.sh @@ -0,0 +1,19 @@ +#!/bin/bash +while read -r env; do + name="$(cut -c5- <<< ${env%%=*})" + val="${env##*=}" + [[ "$name" =~ _ ]] && continue + 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 <<< $(printenv | grep '^TOR_') + +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