-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
381 lines (339 loc) · 13.8 KB
/
install.sh
File metadata and controls
381 lines (339 loc) · 13.8 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VERSION=$(cat "$ROOT_DIR/VERSION" 2>/dev/null || echo "unknown")
echo ""
echo "========================================="
echo " FPP Admin Eavesdrop - v${VERSION}"
echo "========================================="
echo ""
# Detect FPP web root
WEBROOT="/opt/fpp/www"
if [[ ! -d "$WEBROOT" ]]; then
WEBROOT="/var/www/html"
fi
if [[ ! -d "$WEBROOT" ]]; then
echo "[ERROR] Cannot find web root. Is this an FPP system?"
exit 1
fi
echo "[install] Web root: $WEBROOT"
MUSIC_DIR="/home/fpp/media/music"
LISTEN_SYNC="/home/fpp/listen-sync"
# Deploy web files
echo "[install] Deploying web files..."
sudo mkdir -p "$WEBROOT/listen"
sudo cp -f "$ROOT_DIR/www/listen/listen.html" "$WEBROOT/listen/listen.html" 2>/dev/null || \
sudo cp -f "$ROOT_DIR/www/listen/index.html" "$WEBROOT/listen/index.html" 2>/dev/null || true
sudo cp -f "$ROOT_DIR/www/listen/status.php" "$WEBROOT/listen/status.php"
sudo cp -f "$ROOT_DIR/www/listen/admin.php" "$WEBROOT/listen/admin.php"
sudo cp -f "$ROOT_DIR/www/listen/version.php" "$WEBROOT/listen/version.php"
sudo cp -f "$ROOT_DIR/www/listen/calibrate.html" "$WEBROOT/listen/calibrate.html" 2>/dev/null || true
sudo cp -f "$ROOT_DIR/www/listen/logo.png" "$WEBROOT/listen/logo.png" 2>/dev/null || true
sudo cp -f "$ROOT_DIR/VERSION" "$WEBROOT/listen/VERSION" 2>/dev/null || true
# Create index.html redirect if listen.html exists
if [[ -f "$WEBROOT/listen/listen.html" ]]; then
echo '<meta http-equiv="refresh" content="0;url=listen.html">' | sudo tee "$WEBROOT/listen/index.html" > /dev/null
fi
sudo chown -R www-data:www-data "$WEBROOT/listen" 2>/dev/null || true
sudo chmod -R 755 "$WEBROOT/listen" 2>/dev/null || true
echo "[install] Web files deployed"
# Create /music symlink
if [[ ! -L "$WEBROOT/music" ]] && [[ ! -d "$WEBROOT/music" ]]; then
sudo ln -s "$MUSIC_DIR" "$WEBROOT/music"
echo "[install] Created /music symlink"
elif [[ -L "$WEBROOT/music" ]]; then
CURRENT=$(readlink -f "$WEBROOT/music")
if [[ "$CURRENT" != "$MUSIC_DIR" ]]; then
sudo rm -f "$WEBROOT/music"
sudo ln -s "$MUSIC_DIR" "$WEBROOT/music"
echo "[install] Updated /music symlink"
fi
fi
sudo chmod -R a+rX "$MUSIC_DIR" 2>/dev/null || true
# Create config directory
echo "[install] Setting up listener config..."
sudo mkdir -p "$LISTEN_SYNC"
sudo chown fpp:fpp "$LISTEN_SYNC"
# Fix Windows line endings on all text files (in case cloned on Windows)
if command -v sed >/dev/null 2>&1; then
find "$ROOT_DIR" \( -name "*.sh" -o -name "*.py" -o -name "*.service" \
-o -name "*.conf" -o -name "*.html" -o -name "*.php" -o -name "*.htaccess*" \) \
-exec sed -i 's/\r$//' {} + 2>/dev/null || true
fi
# ====== WiFi Access Point ======
# Install AP dependencies
for pkg in hostapd dnsmasq; do
if ! dpkg -l "$pkg" 2>/dev/null | grep -q "^ii"; then
echo "[install] Installing $pkg..."
sudo apt-get install -y "$pkg" 2>/dev/null || true
fi
done
# Ensure hostapd is unmasked (Raspbian masks it by default)
sudo systemctl unmask hostapd 2>/dev/null || true
# Ensure Bluetooth is available for BT speaker feature
if systemctl list-unit-files bluetooth.service >/dev/null 2>&1; then
sudo systemctl enable bluetooth 2>/dev/null || true
echo "[install] Bluetooth service enabled"
fi
# Deploy default AP config (if not already present)
AP_CONF="$LISTEN_SYNC/ap.conf"
if [[ ! -f "$AP_CONF" ]]; then
sudo tee "$AP_CONF" > /dev/null <<'EOF'
# AP Configuration for FPP Eavesdrop
# Edit via web UI or manually. Changes take effect on service restart.
WLAN_IF=wlan1
AP_IP=192.168.50.1
AP_MASK=24
EOF
sudo chmod 644 "$AP_CONF"
echo "[install] Default AP config created (IP: 192.168.50.1)"
else
echo "[install] AP config exists, keeping current settings"
fi
# Read configured interface from ap.conf
WLAN_IF="wlan1"
if [[ -f "$AP_CONF" ]]; then
source "$AP_CONF"
WLAN_IF="${WLAN_IF:-wlan1}"
fi
# Deploy default hostapd config with WPA2 (if not already present)
HOSTAPD_CONF="$LISTEN_SYNC/hostapd-listener.conf"
if [[ ! -f "$HOSTAPD_CONF" ]]; then
sudo tee "$HOSTAPD_CONF" > /dev/null <<EOF
interface=$WLAN_IF
driver=nl80211
ssid=SHOW_AUDIO
hw_mode=g
channel=6
country_code=US
wmm_enabled=1
ieee80211n=1
auth_algs=1
ignore_broadcast_ssid=0
ap_isolate=0
# WPA2 configuration
wpa=2
wpa_passphrase=Listen123
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
EOF
sudo chmod 644 "$HOSTAPD_CONF"
echo "[install] Default WiFi password: Listen123"
else
echo "[install] Hostapd config exists, keeping current settings"
fi
# Configure sudoers for www-data (admin.php WiFi management)
echo "[install] Configuring sudoers..."
SUDOERS_FILE="/etc/sudoers.d/listener-sync"
sudo tee "$SUDOERS_FILE" > /dev/null <<'EOF'
# Allow www-data to manage listener AP config and service
www-data ALL=(ALL) NOPASSWD: /usr/bin/tee /home/fpp/listen-sync/hostapd-listener.conf
www-data ALL=(ALL) NOPASSWD: /usr/bin/tee /home/fpp/listen-sync/ap.conf
www-data ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart listener-ap.service
www-data ALL=(ALL) NOPASSWD: /usr/bin/systemctl stop hostapd
# Allow www-data to write calibration FSEQ files
www-data ALL=(ALL) NOPASSWD: /bin/cp /tmp/fseq_* /home/fpp/media/sequences/_bt_cal.fseq
www-data ALL=(ALL) NOPASSWD: /bin/chown fpp\:fpp /home/fpp/media/sequences/_bt_cal.fseq
www-data ALL=(ALL) NOPASSWD: /bin/rm -f /home/fpp/media/sequences/_bt_cal.fseq
# Allow www-data to query WiFi station info
www-data ALL=(ALL) NOPASSWD: /sbin/iw dev * station dump
# Allow www-data to manage Bluetooth devices
www-data ALL=(ALL) NOPASSWD: /usr/bin/bluetoothctl
EOF
sudo chmod 440 "$SUDOERS_FILE"
if sudo visudo -cf "$SUDOERS_FILE" > /dev/null 2>&1; then
echo "[install] Sudoers configured"
else
echo "[ERROR] Invalid sudoers syntax! Removing."
sudo rm -f "$SUDOERS_FILE"
exit 1
fi
# Deploy listener-ap script
echo "[install] Deploying listener-ap..."
sudo cp -f "$ROOT_DIR/server/listener-ap.sh" "$LISTEN_SYNC/listener-ap.sh"
sudo chown fpp:fpp "$LISTEN_SYNC/listener-ap.sh"
sudo chmod 755 "$LISTEN_SYNC/listener-ap.sh"
# Fix CRLF on deployed copy too
if command -v sed >/dev/null 2>&1; then
sudo sed -i 's/\r$//' "$LISTEN_SYNC/listener-ap.sh" 2>/dev/null || true
fi
# Deploy listener-ap systemd service
if [[ -f "$ROOT_DIR/server/listener-ap.service" ]]; then
sudo cp -f "$ROOT_DIR/server/listener-ap.service" /etc/systemd/system/listener-ap.service
sudo systemctl daemon-reload
sudo systemctl enable listener-ap 2>/dev/null || true
echo "[install] listener-ap service installed"
# Only start if the configured interface is present
if [[ -e "/sys/class/net/$WLAN_IF" ]]; then
sudo systemctl restart listener-ap 2>/dev/null || true
echo "[install] listener-ap service started ($WLAN_IF detected)"
else
echo "[install] $WLAN_IF not detected -- listener-ap enabled but not started"
echo " Connect $WLAN_IF and run: sudo systemctl start listener-ap"
fi
fi
# ====== WebSocket Sync Server ======
# Install python3-websockets (required by ws-sync-server.py)
echo "[install] Checking Python websockets dependency..."
if python3 -c "import websockets" 2>/dev/null; then
echo "[install] python3-websockets already installed"
else
echo "[install] Installing python3-websockets..."
if sudo apt-get install -y python3-websockets 2>/dev/null; then
echo "[install] Installed python3-websockets via apt"
elif pip3 install websockets 2>/dev/null; then
echo "[install] Installed websockets via pip3"
else
echo "[WARN] Could not install python3-websockets. WebSocket sync will not work."
echo " Install manually: sudo apt install python3-websockets"
fi
fi
# Deploy WebSocket sync server
echo "[install] Deploying WebSocket sync server..."
sudo cp -f "$ROOT_DIR/server/ws-sync-server.py" "$LISTEN_SYNC/ws-sync-server.py"
sudo chown fpp:fpp "$LISTEN_SYNC/ws-sync-server.py"
sudo chmod 755 "$LISTEN_SYNC/ws-sync-server.py"
echo "[install] ws-sync-server.py deployed"
# Deploy ws-sync systemd service
if [[ -f "$ROOT_DIR/config/ws-sync.service" ]]; then
sudo cp -f "$ROOT_DIR/config/ws-sync.service" /etc/systemd/system/ws-sync.service
sudo systemctl daemon-reload
sudo systemctl enable ws-sync 2>/dev/null || true
sudo systemctl restart ws-sync 2>/dev/null || true
echo "[install] ws-sync service installed and started"
fi
# Configure Apache for WebSocket proxy
echo "[install] Configuring Apache WebSocket proxy..."
# Enable required Apache modules
for mod in proxy proxy_wstunnel headers rewrite; do
if ! apache2ctl -M 2>/dev/null | grep -q "${mod}_module"; then
sudo a2enmod "$mod" 2>/dev/null || true
fi
done
# Deploy Apache config
if [[ -f "$ROOT_DIR/config/apache-listener.conf" ]]; then
sudo cp -f "$ROOT_DIR/config/apache-listener.conf" /etc/apache2/conf-available/listener.conf
sudo a2enconf listener 2>/dev/null || true
echo "[install] Apache listener config deployed"
fi
# Restart Apache to apply changes
sudo systemctl restart apache2 2>/dev/null || sudo apachectl restart 2>/dev/null || true
echo "[install] Apache restarted"
# ====== FPP Plugin Registration ======
PLUGIN_DIR="/home/fpp/media/plugins/fpp-eavesdrop"
echo "[install] Registering FPP plugin..."
sudo mkdir -p "$PLUGIN_DIR"
sudo cp -f "$ROOT_DIR/pluginInfo.json" "$PLUGIN_DIR/pluginInfo.json"
sudo cp -f "$ROOT_DIR/api.php" "$PLUGIN_DIR/api.php"
sudo chown -R fpp:fpp "$PLUGIN_DIR"
echo "[install] Plugin registered"
# Deploy custom.js footer button (appends if not already present)
CUSTOM_JS="/home/fpp/media/config/custom.js"
if ! grep -q "fpp-eavesdrop" "$CUSTOM_JS" 2>/dev/null; then
echo "[install] Adding Eavesdrop footer button..."
cat >> "$CUSTOM_JS" <<'JSEOF'
// -- fpp-eavesdrop: Undoc footer button --
$(document).ready(function() {
if ($('#rebootShutdown').length) {
var btn = $('<button>')
.attr('type', 'button')
.addClass('buttons wideButton btn-outline-light')
.html('<i class="fas fa-fw fa-headphones fa-nbsp"></i>Undoc Eavesdrop')
.on('click', function() { window.open('/listen/', '_blank'); });
$('#rebootShutdown').prepend(btn);
}
// SBS mode warning on FPP Network Config page
if (window.location.pathname === '/networkconfig.php' || window.location.pathname === '/networkconfig.php/') {
$.getJSON('/listen/admin.php', { action: 'get_ap_config' }, function(res) {
if (!res.success || res.ap_iface !== 'wlan0') return;
// Inject warning banner
var banner = $('<div>')
.css({
background: '#4a0000', border: '2px solid #d33',
borderRadius: '6px', padding: '12px 16px', margin: '10px 0 16px',
color: '#ff6b6b', fontWeight: '600', fontSize: '14px'
})
.html('<i class="fas fa-exclamation-triangle"></i> ' +
'<b>SBS Mode Active</b> — wlan0 is running the Eavesdrop listener AP. ' +
'Scanning or changing wlan0 settings here will <b>disconnect all listeners</b>. ' +
'<a href="/listen/listen.html" style="color:#6bf;margin-left:4px;">Manage AP in Eavesdrop</a>');
$('h1.title').after(banner);
// Intercept wlan0 selection — warn before scan fires
var origLoadSIDS = window.LoadSIDS;
if (typeof origLoadSIDS === 'function') {
window.LoadSIDS = function(iface) {
if (iface === 'wlan0' && !confirm(
'SBS Mode is active — wlan0 is running the Eavesdrop AP.\n\n' +
'Scanning will disconnect all listeners.\n\nContinue anyway?'
)) {
return;
}
return origLoadSIDS.apply(this, arguments);
};
}
});
}
});
// -- end fpp-eavesdrop --
JSEOF
echo "[install] Footer button added"
else
echo "[install] Footer button already present"
fi
# ====== Self-Test ======
echo ""
echo "[install] Running self-tests..."
TESTS_OK=true
# Check ws-sync service
if systemctl is-active ws-sync >/dev/null 2>&1; then
echo "[test] ws-sync service: OK"
else
echo "[test] ws-sync service: FAILED (check: journalctl -u ws-sync)"
TESTS_OK=false
fi
# Probe ws-sync port (expect HTTP 426 Upgrade Required)
if command -v curl >/dev/null 2>&1; then
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8080/ 2>/dev/null || echo "000")
if [[ "$HTTP_CODE" == "426" ]]; then
echo "[test] ws-sync port 8080: OK (HTTP 426 = WebSocket expected)"
else
echo "[test] ws-sync port 8080: HTTP $HTTP_CODE (expected 426)"
TESTS_OK=false
fi
fi
# Check listener-ap service (only if configured interface exists)
if [[ -e "/sys/class/net/$WLAN_IF" ]]; then
if systemctl is-active listener-ap >/dev/null 2>&1; then
echo "[test] listener-ap service: OK"
else
echo "[test] listener-ap service: FAILED (check: journalctl -u listener-ap)"
TESTS_OK=false
fi
fi
# Get display values
LOCAL_IP=$(hostname -I 2>/dev/null | awk '{print $1}')
if [[ -z "$LOCAL_IP" ]]; then
LOCAL_IP="YOUR_FPP_IP"
fi
AP_SSID=$(grep '^ssid=' "$LISTEN_SYNC/hostapd-listener.conf" 2>/dev/null | cut -d= -f2 || echo "SHOW_AUDIO")
AP_IP=$(grep '^AP_IP=' "$LISTEN_SYNC/ap.conf" 2>/dev/null | cut -d= -f2 || echo "192.168.50.1")
echo ""
echo "========================================="
echo " Install complete!"
echo "========================================="
echo " Page: http://${LOCAL_IP}/listen/"
echo " Sync: WebSocket (ws://${LOCAL_IP}/ws)"
if [[ -e "/sys/class/net/$WLAN_IF" ]]; then
SBS_NOTE=""
[[ "$WLAN_IF" == "wlan0" ]] && SBS_NOTE=" (SBS mode)"
echo " WiFi: ${AP_SSID} (WPA2) on ${WLAN_IF}${SBS_NOTE}"
echo " AP IP: ${AP_IP}"
echo " Pass: Listen123 (change via web UI)"
fi
echo "========================================="
if [[ "$TESTS_OK" != "true" ]]; then
echo " WARNING: Some self-tests failed."
echo " Check: journalctl -u ws-sync -f"
echo "========================================="
fi