-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnm-heatwave-ap.sh
More file actions
57 lines (45 loc) · 1.76 KB
/
nm-heatwave-ap.sh
File metadata and controls
57 lines (45 loc) · 1.76 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
#!/bin/bash
# NetworkManager dispatcher script for Heatwave AP
# This script starts/stops the dnsmasq captive portal when the Heatwave AP is activated
INTERFACE=$1
STATUS=$2
CONNECTION=$3
# Location of the custom dnsmasq config
DNSMASQ_CONF="/home/heatwave/heatwave-app/dnsmasq.conf"
# Log file
LOG_FILE="/var/log/heatwave-ap.log"
log() {
echo "$(date): $1" >> "$LOG_FILE"
echo "$1"
}
# Only run for the Heatwave connection
if [ "$CONNECTION" = "Heatwave" ]; then
if [ "$STATUS" = "up" ]; then
log "Heatwave AP activated on $INTERFACE. Starting captive portal..."
# Stop the system dnsmasq if it's running
if systemctl is-active --quiet dnsmasq; then
log "Stopping system dnsmasq service"
systemctl stop dnsmasq
fi
# Start dnsmasq with our custom config
log "Starting dnsmasq with custom config"
dnsmasq --conf-file="$DNSMASQ_CONF" --no-daemon --log-facility="$LOG_FILE" &
# Store the PID for later cleanup
echo $! > /tmp/heatwave-dnsmasq.pid
log "Dnsmasq started with PID $(cat /tmp/heatwave-dnsmasq.pid)"
elif [ "$STATUS" = "down" ]; then
log "Heatwave AP deactivated. Stopping captive portal..."
# Kill our custom dnsmasq instance
if [ -f /tmp/heatwave-dnsmasq.pid ]; then
DNSMASQ_PID=$(cat /tmp/heatwave-dnsmasq.pid)
log "Killing dnsmasq PID $DNSMASQ_PID"
kill "$DNSMASQ_PID" 2>/dev/null
rm /tmp/heatwave-dnsmasq.pid
fi
# Restart the system dnsmasq if it was enabled
if systemctl is-enabled --quiet dnsmasq; then
log "Restarting system dnsmasq service"
systemctl start dnsmasq
fi
fi
fi