Files
OBD2-Simulator/prepare_can.sh

57 lines
1.7 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -euo pipefail
# === OBD-II Simulator Systemvorbereitung ===
# Verwendung:
# sudo ./prepare_can.sh # einrichten
# sudo ./prepare_can.sh --undo # rückgängig machen
IP_BIN="${IP_BIN:-$(command -v ip || true)}"
PY_BIN="${PY_BIN:-$(python3 -c 'import sys,os; print(os.path.realpath(sys.executable))' 2>/dev/null || true)}"
if [[ "$#" -gt 0 && "$1" == "--undo" ]]; then
echo ">>> Entferne Capabilities von Python und ip …"
if [[ -n "$PY_BIN" && -x "$PY_BIN" ]]; then
sudo setcap -r "$PY_BIN" || true
getcap "$PY_BIN" || true
fi
if [[ -n "$IP_BIN" && -x "$IP_BIN" ]]; then
sudo setcap -r "$IP_BIN" || true
getcap "$IP_BIN" || true
fi
echo ">>> Undo abgeschlossen."
exit 0
fi
if [[ -z "$PY_BIN" || ! -x "$PY_BIN" ]]; then
echo "FEHLER: Konnte Python-Interpreter nicht ermitteln. PY_BIN=… setzen."
exit 1
fi
if [[ -z "$IP_BIN" || ! -x "$IP_BIN" ]]; then
echo "FEHLER: 'ip' (iproute2) nicht gefunden bitte installieren."
exit 1
fi
echo ">>> Python: $PY_BIN"
echo ">>> ip: $IP_BIN"
echo ">>> Setze Capabilities auf Python und ip …"
sudo setcap cap_net_admin,cap_net_raw=eip "$PY_BIN" || true
sudo setcap cap_net_admin,cap_net_raw=ep "$IP_BIN" || true
echo ">>> Prüfe Capabilities:"
getcap "$PY_BIN" || true
getcap "$IP_BIN" || true
# Optional: vcan0 einrichten
if ! ip link show vcan0 &>/dev/null; then
echo ">>> Richte vcan0 ein (virtuelles CAN, nur zu Testzwecken)…"
sudo modprobe vcan || true
sudo ip link add dev vcan0 type vcan || true
fi
sudo ip link set vcan0 up || true
ip -details link show vcan0 | sed 's/^/ /'
echo ">>> Vorbereitung abgeschlossen."
echo "Starte die App jetzt einfach normal (ohne sudo)."