aboutsummaryrefslogtreecommitdiffstats
path: root/core/entrypoint-tor.sh
blob: 808c2d506df0544729de50b945e878c9174e3cdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env sh

if [ "$ROUTE_TOR" = 1 ] || [ "$ROUTE_TOR" = 2 ]; then
  cat > /etc/tor/torrc <<- EOF
Log notice stdout
SocksPort ${TOR_PORT:-9050} # Default: Bind to localhost:9050 for local connections.
MaxCircuitDirtiness ${MAX_CIRCUIT:-300}
CircuitBuildTimeout ${CIRCUIT_TIMEOUT:-300}
ExcludeExitNodes {US}
StrictNodes 1
EOF
  tor -f /etc/tor/torrc --runasdaemon 1

  # check loop health tor
  while :; do
      checkurl=$(curl --socks5 "localhost:${TOR_PORT:-9050}" -o /dev/null -s -w "%{http_code}\n" "${URL_CHECK:-https://www.youtube.com/results?search_query=rms}")
      if [ "$checkurl" = '502' ] || [ "$checkurl" = '302' ]; then
          if pgrep tor > /dev/null; then
              pkill tor > /dev/null
              tor -f /etc/tor/torrc --runasdaemon 1
          else
              tor -f /etc/tor/torrc --runasdaemon 1
          fi
      fi
      sleep 5
  done
fi