This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / tools / tornade / tornade.sh
2.0 kB 77 lines
1#!/usr/bin/env bash 2set -euo pipefail 3 4# Create temporary directory for this tor instance 5TOR_DIR=$(mktemp -d -t tornade.XXXXXX) 6trap 'rm -rf "$TOR_DIR"' EXIT 7 8# Generate random ports 9SOCKS_PORT=$((9050 + RANDOM % 1000)) 10CONTROL_PORT=$((SOCKS_PORT + 1)) 11 12# Create tor configuration 13cat > "$TOR_DIR/torrc" <<EOF 14DataDirectory $TOR_DIR/data 15SocksPort 127.0.0.1:$SOCKS_PORT 16ControlPort 127.0.0.1:$CONTROL_PORT 17Log notice file $TOR_DIR/tor.log 18RunAsDaemon 0 19 20# Performance optimizations 21CircuitBuildTimeout 10 22LearnCircuitBuildTimeout 0 23NumEntryGuards 3 24KeepalivePeriod 60 25SocksTimeout 60 26 27# Don't wait for descriptor downloads 28UseMicroDescriptors 0 29EOF 30 31# Start tor in background 32echo "Starting isolated Tor instance on port $SOCKS_PORT..." >&2 33tor -f "$TOR_DIR/torrc" & 34TOR_PID=$! 35 36# Function to cleanup tor process 37cleanup() { 38 if kill -0 "$TOR_PID" 2>/dev/null; then 39 echo "Stopping Tor instance..." >&2 40 kill "$TOR_PID" 2>/dev/null || true 41 wait "$TOR_PID" 2>/dev/null || true 42 fi 43 rm -rf "$TOR_DIR" 44} 45trap cleanup EXIT INT TERM 46 47# Wait for tor to be ready 48echo "Waiting for Tor to establish circuits..." >&2 49# Check frequently at first, then slow down 50for i in {1..60}; do 51 if grep -q "Bootstrapped 100%" "$TOR_DIR/tor.log" 2>/dev/null; then 52 echo "Tor is ready!" >&2 53 break 54 fi 55 # Check every 0.1s for first 2 seconds, then every 0.5s 56 if [ "$i" -le 20 ]; then 57 sleep 0.1 58 else 59 sleep 0.5 60 fi 61done 62 63if ! grep -q "Bootstrapped 100%" "$TOR_DIR/tor.log" 2>/dev/null; then 64 echo "Error: Tor failed to establish circuits" >&2 65 exit 1 66fi 67 68# Check if we're trying to run SSH on macOS 69if [[ "$1" == "ssh" ]] && [[ "$(uname)" == "Darwin" ]]; then 70 # On macOS, use ProxyCommand instead of torsocks due to SIP 71 shift # remove 'ssh' from arguments 72 exec ssh -o ProxyCommand="nc -x 127.0.0.1:$SOCKS_PORT %h %p" "$@" 73else 74 # For other commands or non-macOS systems, use torsocks 75 export TORSOCKS_TOR_PORT=$SOCKS_PORT 76 exec torsocks "$@" 77fi