Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature | Configuring TOR via environment #15

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
9 changes: 9 additions & 0 deletions assets/root/etc/init.d/tor_settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/sbin/openrc-run

description="Sets up tor settings from envoriment"

start() {
ebegin "Setting up Tor settings"
bash /tor.sh
eend $?
}
19 changes: 19 additions & 0 deletions assets/root/tor.sh
Original file line number Diff line number Diff line change
@@ -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