@@ -14,6 +14,65 @@ if ! id litd > /dev/null 2>&1; then
1414 chown -R $USERID :$GROUPID /home/litd
1515fi
1616
17+ usermod -a -G debian-tor litd
18+ mkdir -p /var/lib/tor/litd-service
19+ chown -R debian-tor:debian-tor /var/lib/tor
20+ chmod 755 /var/lib/tor
21+ chmod 700 /var/lib/tor/litd-service
22+
23+ if [ " ${ENABLE_TOR} " = " true" ]; then
24+ echo " Starting Tor service..."
25+
26+ # Set default ports if not provided
27+ TOR_SOCKS_PORT=${TOR_SOCKS_PORT:- 9050}
28+ TOR_CONTROL_PORT=${TOR_CONTROL_PORT:- 9051}
29+
30+ # Generate torrc file with dynamic ports
31+ cat > /etc/tor/torrc << EOF
32+ # Config
33+ SocksPort 127.0.0.1:${TOR_SOCKS_PORT}
34+ ControlPort 127.0.0.1:${TOR_CONTROL_PORT}
35+ CookieAuthentication 1
36+ DataDirectory /var/lib/tor
37+ Log notice stdout
38+
39+ # Hidden service settings (optional - for LND Tor address)
40+ HiddenServiceDir /var/lib/tor/litd-service
41+ HiddenServiceVersion 3
42+ HiddenServicePort 9735 127.0.0.1:9735
43+ HiddenServicePort 8080 127.0.0.1:8080
44+ EOF
45+
46+ gosu debian-tor tor &
47+ TOR_PID=$!
48+
49+ echo " Waiting for Tor to create auth cookie..."
50+ COOKIE_FILE=" /var/lib/tor/control_auth_cookie"
51+ TIMEOUT=30
52+ ELAPSED=0
53+
54+ while [ ! -f " $COOKIE_FILE " ] && [ $ELAPSED -lt $TIMEOUT ]; do
55+ sleep 0.5
56+ ELAPSED=$(( ELAPSED + 1 ))
57+ done
58+
59+ if [ -f " $COOKIE_FILE " ]; then
60+ # Get the litd group ID
61+ LITD_GID=$( getent group litd | cut -d: -f3)
62+ # Change the cookie file's group to litd
63+ chown debian-tor:$LITD_GID " $COOKIE_FILE "
64+ chmod 640 " $COOKIE_FILE "
65+ # Fix directory permissions - Tor sets this to 700, but we need 755
66+ # so litd user can traverse into the directory
67+ chmod 755 /var/lib/tor
68+ echo " Tor auth cookie created and permissions set for SAFECOOKIE auth"
69+ else
70+ echo " WARNING: Tor auth cookie not found after ${TIMEOUT} seconds"
71+ fi
72+ else
73+ echo " Tor service disabled (ENABLE_TOR != 'true')"
74+ fi
75+
1776if [ $( echo " $1 " | cut -c1) = " -" ]; then
1877 echo " $0 : assuming arguments for litd"
1978
0 commit comments