-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalwaysblock-daemon.sh
More file actions
executable file
·64 lines (51 loc) · 1.92 KB
/
alwaysblock-daemon.sh
File metadata and controls
executable file
·64 lines (51 loc) · 1.92 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# AlwaysBlock daemon script
# Runs at boot to start proxy and enable system proxy
# This script is called by LaunchDaemon (runs as root)
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# This placeholder will be replaced during installation with the actual path
# VENV_PATH_PLACEHOLDER
VENV_PATH="__VENV_PATH__"
# Extract user home from venv path (e.g., /Users/tavi/.alwaysblock-venv -> /Users/tavi)
USER_HOME="${VENV_PATH%/.alwaysblock-venv}"
# Log function
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
log "AlwaysBlock daemon starting..."
log "User home: $USER_HOME"
# Wait a bit for network to be ready
sleep 5
# Set HOME so Python uses correct config/data paths
export HOME="$USER_HOME"
# Start all AlwaysBlock services
log "Starting AlwaysBlock services..."
if ! /usr/local/bin/alwaysblock start 2>&1; then
log "Failed to start AlwaysBlock"
exit 1
fi
log "AlwaysBlock daemon started successfully"
# Keep running (LaunchDaemon will restart us if we exit)
# Monitor services and restart if they stop
while true; do
sleep 60
# Health check: ensure proxy is still running
if ! lsof -i :8905 >/dev/null 2>&1; then
log "Proxy daemon stopped, restarting..."
/usr/local/bin/alwaysblock start 2>&1
fi
# Health check: ensure system proxy is still enabled
if ! networksetup -getwebproxy "Wi-Fi" 2>/dev/null | grep -q "127.0.0.1"; then
# Try other common service names
for service in "Ethernet" "USB 10/100/1000 LAN" "Thunderbolt Ethernet"; do
if networksetup -listallnetworkservices 2>/dev/null | grep -q "$service"; then
if ! networksetup -getwebproxy "$service" 2>/dev/null | grep -q "127.0.0.1"; then
log "System proxy disabled on $service, re-enabling..."
/usr/local/bin/alwaysblock start 2>&1
break
fi
fi
done
fi
done