-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathpcileech-sudo
More file actions
executable file
·57 lines (50 loc) · 1.88 KB
/
pcileech-sudo
File metadata and controls
executable file
·57 lines (50 loc) · 1.88 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
# pcileech-sudo - Run pcileech commands with elevated privileges
#
# This wrapper script handles:
# 1. Automatic virtual environment detection
# 2. Running pcileech.py with sudo while preserving the Python environment
#
# Usage: pcileech-sudo <command> [args...]
# Example: pcileech-sudo build --bdf 0000:03:00.0 --board pcileech_35t325_x1
# pcileech-sudo check --device 0000:03:00.0
# pcileech-sudo tui
set -euo pipefail
# Find the script directory (where pcileech.py is located)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Check if pcileech.py exists in the script directory
if [ ! -f "$SCRIPT_DIR/pcileech.py" ]; then
# Try to find it relative to installed location
if [ -f "/app/pcileech.py" ]; then
SCRIPT_DIR="/app"
else
echo "Error: Could not find pcileech.py in $SCRIPT_DIR or /app"
echo "Please run this script from the PCILeechFWGenerator directory"
exit 1
fi
fi
# Determine the Python interpreter to use
PYTHON_CMD=""
# Check for active virtual environment first
if [ -n "${VIRTUAL_ENV:-}" ]; then
PYTHON_CMD="$VIRTUAL_ENV/bin/python3"
elif [ -f "$SCRIPT_DIR/.venv/bin/python3" ]; then
# Check for local .venv
PYTHON_CMD="$SCRIPT_DIR/.venv/bin/python3"
elif [ -f "$HOME/.pcileech-venv/bin/python3" ]; then
# Check for user-level venv
PYTHON_CMD="$HOME/.pcileech-venv/bin/python3"
else
# Fall back to system Python
PYTHON_CMD="python3"
fi
# Verify the Python interpreter exists
if [ ! -x "$PYTHON_CMD" ] && ! command -v "$PYTHON_CMD" &> /dev/null; then
echo "Error: Python interpreter not found: $PYTHON_CMD"
echo "Please ensure Python 3 is installed and accessible"
exit 1
fi
# Execute pcileech.py with sudo, preserving the Python environment
# Using 'sudo -E' to preserve environment variables
cd "$SCRIPT_DIR"
exec sudo -E "$PYTHON_CMD" "$SCRIPT_DIR/pcileech.py" "$@"