-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
104 lines (90 loc) · 3.96 KB
/
Copy pathsetup.sh
File metadata and controls
104 lines (90 loc) · 3.96 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
#!/usr/bin/env bash
# setup.sh — install wids as a systemd service
set -euo pipefail
SERVICE="wids"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WIDS_PY="$SCRIPT_DIR/wids.py"
ENV_FILE="$SCRIPT_DIR/.env"
# ── require root ──────────────────────────────────────────────
if [[ $EUID -ne 0 ]]; then
echo "Run with sudo: sudo bash setup.sh"
exit 1
fi
# ── env file ──────────────────────────────────────────────────
if [[ ! -f "$ENV_FILE" ]]; then
if [[ -f "$SCRIPT_DIR/.env.example" ]]; then
cp "$SCRIPT_DIR/.env.example" "$ENV_FILE"
echo "[!] Created $ENV_FILE from .env.example — edit it before continuing."
echo " Then re-run: sudo bash setup.sh"
exit 0
fi
fi
# ── log directory ─────────────────────────────────────────────
mkdir -p /var/log/wids/sessions
chmod 755 /var/log/wids
# ── systemd unit ──────────────────────────────────────────────
cat > /etc/systemd/system/wids.service <<EOF
[Unit]
Description=Wi-Fi Intrusion Detection System (WIDS)
After=network.target
[Service]
Type=forking
ExecStartPre=-/usr/bin/tmux kill-session -t wids
ExecStart=/usr/bin/tmux new-session -d -s wids /usr/bin/python3 $WIDS_PY
ExecStop=/usr/bin/tmux kill-session -t wids
Restart=on-failure
RestartSec=10
EnvironmentFile=-$ENV_FILE
StandardOutput=append:/var/log/wids/wids.log
StandardError=append:/var/log/wids/wids.log
[Install]
WantedBy=multi-user.target
EOF
# ── wids-attach helper ────────────────────────────────────────
cat > /usr/local/bin/wids-attach <<'EOF'
#!/usr/bin/env bash
SESSION="wids"
if ! sudo tmux has-session -t "$SESSION" 2>/dev/null; then
echo "[wids] Session not running."
echo " Status: $(systemctl is-active wids 2>/dev/null || echo unknown)"
echo " Start: sudo systemctl start wids"
exit 1
fi
echo "[wids] Attaching to TUI — detach with Ctrl-B then D"
exec sudo tmux attach-session -t "$SESSION"
EOF
chmod +x /usr/local/bin/wids-attach
# ── reload & enable ───────────────────────────────────────────
systemctl daemon-reload
systemctl enable "$SERVICE"
# ── start now ─────────────────────────────────────────────────
echo ""
echo "Starting service …"
systemctl start "$SERVICE"
sleep 2
STATUS=$(systemctl is-active "$SERVICE" 2>/dev/null || echo "unknown")
if [[ "$STATUS" == "active" ]]; then
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " ✓ WIDS is running"
echo ""
echo " Attach to the live TUI (from this or any SSH session):"
echo " wids-attach"
echo ""
echo " Detach from TUI without stopping WIDS:"
echo " Ctrl-B then D"
echo ""
echo " Service control:"
echo " sudo systemctl status wids"
echo " sudo systemctl restart wids"
echo " sudo systemctl stop wids"
echo ""
echo " Logs (append-only, readable any time):"
echo " tail -f /var/log/wids/wids.log"
echo " ls /var/log/wids/ # JSON + CSV exports here too"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
else
echo ""
echo "[!] Service started but status is: $STATUS"
echo " Check: journalctl -u wids -n 30"
fi