Skip to content

Commit c65900b

Browse files
Merge pull request #62 from pythonbpf/script
make script curlable
2 parents d50157f + 711e34c commit c65900b

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ Python-BPF is an LLVM IR generator for eBPF programs written in Python. It uses
4040

4141
---
4242

43+
## Try It Out!
44+
Run
45+
```bash
46+
curl -s https://raw.githubusercontent.com/pythonbpf/Python-BPF/refs/heads/master/tools/setup.sh | sudo bash
47+
```
48+
4349
## Installation
4450

4551
Dependencies:

tools/setup.sh

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
#!/bin/bash
22

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+
}
279

2810
if [ "$EUID" -ne 0 ]; then
2911
echo "Please run this script with sudo."
3012
exit 1
3113
fi
3214

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+
3334
WORK_DIR="/tmp/python_bpf_setup"
3435
REAL_USER=$(logname || echo "$SUDO_USER")
3536

@@ -143,7 +144,7 @@ mkdir -p examples
143144
cd examples || exit 1
144145

145146
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}')
147148

148149
if [ -z "$FILES" ]; then
149150
echo "Failed to fetch file list from repository. Using fallback method..."
@@ -192,7 +193,7 @@ EOF
192193
chmod +x "$WORK_DIR/start_jupyter.sh"
193194
chown "$REAL_USER:$(id -gn "$REAL_USER")" "$WORK_DIR/start_jupyter.sh"
194195

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

Comments
 (0)