#!/bin/bash
if [[ -z "${PRIVATE_KEY}" ]]; then
echo 'PRIVATE_KEY missing'
exit 1
fi
if [[ -z "${REDIRECT}" ]]; then
echo 'REDIRECT missing'
echo "Starting tor listener at port ${LISTEN_PORT:-80}, redirecting to ${REDIRECT}"
echo "${PRIVATE_KEY}" > /web/private_key
cat >> /etc/tor/torrc << EOF
Log notice stdout
DataDirectory /tmp/tor
HiddenServiceDir /web/
HiddenServicePort ${LISTEN_PORT:-80} ${REDIRECT}
HiddenServiceVersion 3
EOF
tor -f /etc/tor/torrc