-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathinstall-sudo-wrapper.sh
More file actions
executable file
·118 lines (100 loc) · 3.71 KB
/
install-sudo-wrapper.sh
File metadata and controls
executable file
·118 lines (100 loc) · 3.71 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
#!/bin/bash
# Install the pcileech sudo wrapper script
# Note: This installs the updated wrapper that uses the unified pcileech.py entrypoint
set -euo pipefail
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if required files exist
check_files() {
local missing_files=()
if [ ! -f "pcileech-sudo" ]; then
missing_files+=("pcileech-sudo")
fi
if [ ${#missing_files[@]} -ne 0 ]; then
log_error "Missing required files:"
for file in "${missing_files[@]}"; do
log_error " - $file"
done
log_error "Please run this script from the PCILeechFWGenerator root directory"
return 1
fi
return 0
}
# Determine the installation directory
INSTALL_DIR="/usr/local/bin"
if [ ! -w "$INSTALL_DIR" ]; then
# If we don't have write permission to /usr/local/bin, use ~/.local/bin
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
log_info "Using user installation directory: $INSTALL_DIR"
else
log_info "Using system installation directory: $INSTALL_DIR"
fi
# Check if required files exist
if ! check_files; then
exit 1
fi
# Copy the wrapper script to the installation directory
log_info "Installing pcileech-sudo..."
cp pcileech-sudo "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/pcileech-sudo"
# Also install as pcileech-build-sudo for backwards compatibility
ln -sf "$INSTALL_DIR/pcileech-sudo" "$INSTALL_DIR/pcileech-build-sudo" 2>/dev/null || \
cp pcileech-sudo "$INSTALL_DIR/pcileech-build-sudo"
chmod +x "$INSTALL_DIR/pcileech-build-sudo"
log_info "Installed pcileech sudo wrapper to $INSTALL_DIR"
log_info "You can now run commands with sudo using: pcileech-sudo <command> [args]"
log_warning "Note: The wrapper uses the unified pcileech.py entrypoint"
# Add the directory to PATH if it's not already there
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
log_info "Adding $INSTALL_DIR to your PATH"
# Determine which shell configuration file to use
SHELL_CONFIG=""
if [ -f "$HOME/.zshrc" ]; then
SHELL_CONFIG="$HOME/.zshrc"
elif [ -f "$HOME/.bashrc" ]; then
SHELL_CONFIG="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
SHELL_CONFIG="$HOME/.bash_profile"
elif [ -f "$HOME/.profile" ]; then
SHELL_CONFIG="$HOME/.profile"
fi
if [ -n "$SHELL_CONFIG" ]; then
# Check if the PATH export already exists to avoid duplicates
if ! grep -q "export PATH.*$INSTALL_DIR" "$SHELL_CONFIG"; then
echo "export PATH=\"\$PATH:$INSTALL_DIR\"" >> "$SHELL_CONFIG"
log_info "Added $INSTALL_DIR to your PATH in $SHELL_CONFIG"
log_info "Please restart your terminal or run 'source $SHELL_CONFIG' to apply changes"
else
log_info "$INSTALL_DIR already exists in $SHELL_CONFIG"
fi
else
log_warning "Could not find a shell configuration file to update PATH"
log_warning "Please manually add $INSTALL_DIR to your PATH"
log_info "Add this line to your shell configuration file:"
log_info " export PATH=\"\$PATH:$INSTALL_DIR\""
fi
else
log_info "$INSTALL_DIR is already in your PATH"
fi
log_info "Installation complete!"
log_info ""
log_info "Usage examples:"
log_info " pcileech-sudo build --bdf 0000:03:00.0 --board pcileech_35t325_x1"
log_info " pcileech-sudo check --device 0000:03:00.0"
log_info " pcileech-sudo tui"
log_info ""
log_info "Alternative (from project directory):"
log_info " sudo python3 pcileech.py build --bdf 0000:03:00.0 --board pcileech_35t325_x1"