|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -echo "====================================================================" |
4 | | -echo " ⚠️ WARNING ⚠️" |
5 | | -echo " This script will run kernel-level BPF programs." |
6 | | -echo " BPF programs run with kernel privileges and could potentially" |
7 | | -echo " affect system stability if not used properly." |
8 | | -echo "" |
9 | | -echo " PLEASE REVIEW THE SOURCE CODE BEFORE RUNNING:" |
10 | | -echo " https://github.com/pythonbpf/python-bpf" |
11 | | -echo "====================================================================" |
12 | | -echo |
13 | | - |
14 | | -echo "This script will:" |
15 | | -echo "1. Check and install required dependencies (libelf, clang, python, bpftool)" |
16 | | -echo "2. Download example programs from the Python-BPF GitHub repository" |
17 | | -echo "3. Create a Python virtual environment with necessary packages" |
18 | | -echo "4. Start a Jupyter notebook server" |
19 | | -echo |
20 | | - |
21 | | -read -p "Would you like to continue? (y/N) " -n 1 -r |
22 | | -echo |
23 | | -if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
24 | | - echo "Script execution cancelled." |
25 | | - exit 1 |
26 | | -fi |
| 3 | +print_warning() { |
| 4 | + echo -e "\033[1;33m$1\033[0m" |
| 5 | +} |
| 6 | +print_info() { |
| 7 | + echo -e "\033[1;32m$1\033[0m" |
| 8 | +} |
27 | 9 |
|
28 | 10 | if [ "$EUID" -ne 0 ]; then |
29 | 11 | echo "Please run this script with sudo." |
30 | 12 | exit 1 |
31 | 13 | fi |
32 | 14 |
|
| 15 | +print_warning "====================================================================" |
| 16 | +print_warning " WARNING " |
| 17 | +print_warning " This script will run kernel-level BPF programs. " |
| 18 | +print_warning " BPF programs run with kernel privileges and could potentially " |
| 19 | +print_warning " affect system stability if not used properly. " |
| 20 | +print_warning " " |
| 21 | +print_warning " This is a non-interactive version for curl piping. " |
| 22 | +print_warning " The script will proceed automatically with installation. " |
| 23 | +print_warning "====================================================================" |
| 24 | +echo |
| 25 | + |
| 26 | +print_info "This script will:" |
| 27 | +echo "1. Check and install required dependencies (libelf, clang, python, bpftool)" |
| 28 | +echo "2. Download example programs from the Python-BPF GitHub repository" |
| 29 | +echo "3. Create a Python virtual environment with necessary packages" |
| 30 | +echo "4. Set up a Jupyter notebook server" |
| 31 | +echo "Starting in 5 seconds. Press Ctrl+C to cancel..." |
| 32 | +sleep 5 |
| 33 | + |
33 | 34 | WORK_DIR="/tmp/python_bpf_setup" |
34 | 35 | REAL_USER=$(logname || echo "$SUDO_USER") |
35 | 36 |
|
@@ -143,7 +144,7 @@ mkdir -p examples |
143 | 144 | cd examples || exit 1 |
144 | 145 |
|
145 | 146 | echo "Fetching example files list..." |
146 | | -FILES=$(curl -s "https://api.github.com/repos/pythonbpf/Python-BPF/contents/examples" | grep -o '"path":"examples/[^"]*"' | awk -F'"' '{print $4}') |
| 147 | +FILES=$(curl -s "https://api.github.com/repos/pythonbpf/Python-BPF/contents/examples" | grep -o '"path": "examples/[^"]*"' | awk -F'"' '{print $4}') |
147 | 148 |
|
148 | 149 | if [ -z "$FILES" ]; then |
149 | 150 | echo "Failed to fetch file list from repository. Using fallback method..." |
|
192 | 193 | chmod +x "$WORK_DIR/start_jupyter.sh" |
193 | 194 | chown "$REAL_USER:$(id -gn "$REAL_USER")" "$WORK_DIR/start_jupyter.sh" |
194 | 195 |
|
195 | | -echo "========================================================" |
196 | | -echo "Setup complete! To start Jupyter Notebook, run:" |
197 | | -echo "$ sudo $WORK_DIR/start_jupyter.sh" |
198 | | -echo "" |
| 196 | +print_info "========================================================" |
| 197 | +print_info "Setup complete! To start Jupyter Notebook, run:" |
| 198 | +print_info "$ sudo $WORK_DIR/start_jupyter.sh" |
| 199 | +print_info "========================================================" |
0 commit comments