Fixed premission-issues with additional script

This commit is contained in:
2025-08-27 19:05:45 +02:00
parent 8195e570b3
commit 4c41be706d
4 changed files with 436 additions and 219 deletions

56
prepare_can.sh Executable file
View File

@@ -0,0 +1,56 @@
#!/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)."