-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement customizable torrc configuration (#141)
- Loading branch information
1 parent
549784f
commit c0db575
Showing
7 changed files
with
366 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/github/workspace/tor/torrc.template:generic-api-key:59 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ services: | |
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
environment: | ||
- SOCKS_HOSTNAME=0.0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
# debug mode is off by default | ||
if [ -z "${DEBUG+x}" ]; then | ||
DEBUG=false | ||
fi | ||
|
||
# Honoring GitHub runner debug mode | ||
if [ -n "${RUNNER_DEBUG+x}" ] && [ "${RUNNER_DEBUG}" = 1 ]; then | ||
DEBUG=false | ||
fi | ||
|
||
if [ "${DEBUG}" = true ]; then | ||
set -o xtrace | ||
LOG_LEVEL=debug | ||
fi | ||
|
||
if [ -f '/etc/torrc' ]; then | ||
if [ "${DEBUG}" = true ]; then | ||
\echo 'DEBUG: Found existing /etc/torrc, overwritting /etc/tor/torrc.' | ||
fi | ||
\cp -f '/etc/torrc' '/etc/tor/torrc' | ||
else | ||
if [ -n "${SHELL_FORMAT+x}" ]; then | ||
if [ "${DEBUG}" = true ]; then | ||
\echo "DEBUG: Found custom Shell Format for envsubst: ${SHELL_FORMAT}" | ||
fi | ||
elif [ -n "${SHELL_FORMAT_EXTRA+x}" ]; then | ||
if [ "${DEBUG}" = true ]; then | ||
\echo "DEBUG: Found extra Shell Format for envsubst: ${SHELL_FORMAT_EXTRA}" | ||
fi | ||
# Escaping predefined variables names except | ||
# SHELL_FORMAT_EXTRA, as we don't want them to be | ||
# expanded. | ||
SHELL_FORMAT="\${DATA_DIRECTORY},\${LOG_LEVEL},\${LOG_FILE},\${SOCKS_HOSTNAME},\${SOCKS_PORT},${SHELL_FORMAT_EXTRA}" | ||
else | ||
# Using single quotes here on purpose, we don't want the | ||
# variables names to be expanded. | ||
# shellcheck disable=SC2016 | ||
SHELL_FORMAT='${DATA_DIRECTORY},${LOG_LEVEL},${LOG_FILE},${SOCKS_HOSTNAME},${SOCKS_PORT}' | ||
fi | ||
DATA_DIRECTORY="${DATA_DIRECTORY:-/var/lib/tor}" \ | ||
LOG_LEVEL="${LOG_LEVEL:-notice}" \ | ||
LOG_FILE="${LOG_FILE:-stdout}" \ | ||
SOCKS_HOSTNAME="${SOCKS_HOSTNAME:-127.0.0.1}" \ | ||
SOCKS_PORT="${SOCKS_PORT:-9050}" \ | ||
envsubst "${SHELL_FORMAT}" </etc/tor/torrc.template >/etc/tor/torrc | ||
fi | ||
|
||
if [ "${DEBUG}" = true ]; then | ||
\echo 'DEBUG: Content of /etc/tor/torrc:' | ||
\echo 'DEBUG: ==========================' | ||
\sed -e 's/^/DEBUG: /' /etc/tor/torrc | ||
\echo 'DEBUG: ==========================' | ||
fi | ||
|
||
cmd=$(\which tor) | ||
|
||
"${cmd}" -f /etc/tor/torrc "$@" |
Oops, something went wrong.