|
1 | 1 | #!/usr/bin/env bash |
| 2 | +set -euo pipefail |
2 | 3 |
|
3 | | -BCC_VERSION=0.31.0 |
| 4 | +BCC_VERSION=0.35.0 |
| 5 | +WORK_DIR="" |
4 | 6 |
|
| 7 | +# Cleanup function for trap |
| 8 | +cleanup() { |
| 9 | + if [ -n "$WORK_DIR" ] && [ -d "$WORK_DIR" ]; then |
| 10 | + echo "Cleaning up temporary directory..." |
| 11 | + sudo rm -rf "$WORK_DIR" |
| 12 | + fi |
| 13 | +} |
| 14 | + |
| 15 | +trap cleanup EXIT |
| 16 | + |
| 17 | +# Check if BCC is already installed |
| 18 | +if command -v bcc-lua &> /dev/null; then |
| 19 | + INSTALLED_VERSION=$(dpkg -l | grep bpfcc-tools | awk '{print $3}' || echo "unknown") |
| 20 | + echo "BCC already installed (version: $INSTALLED_VERSION), skipping installation" |
| 21 | + exit 0 |
| 22 | +fi |
| 23 | + |
| 24 | +echo "Installing BCC version ${BCC_VERSION}..." |
| 25 | + |
| 26 | +# Remove any existing BCC installations |
| 27 | +echo "Removing existing BCC packages..." |
5 | 28 | sudo apt update |
6 | | -sudo apt purge bpfcc-tools libbpfcc python3-bpfcc |
| 29 | +sudo apt purge -y bpfcc-tools libbpfcc python3-bpfcc || true |
| 30 | + |
| 31 | +# Install build dependencies |
| 32 | +echo "Installing build dependencies..." |
7 | 33 | sudo apt install -y zip bison build-essential cmake flex git libedit-dev \ |
8 | 34 | libllvm14 llvm-14-dev libclang-14-dev python3 zlib1g-dev libelf-dev libfl-dev python3-setuptools \ |
9 | 35 | liblzma-dev libdebuginfod-dev arping netperf iperf |
10 | 36 |
|
11 | | -wget https://github.com/iovisor/bcc/releases/download/v${BCC_VERSION}/bcc-src-with-submodule.tar.gz |
12 | | -tar xf bcc-src-with-submodule.tar.gz |
| 37 | +# Create temp directory for build |
| 38 | +WORK_DIR=$(mktemp -d) |
| 39 | +cd "$WORK_DIR" |
| 40 | + |
| 41 | +# Download BCC source |
| 42 | +echo "Downloading BCC ${BCC_VERSION}..." |
| 43 | +wget -q --show-progress "https://github.com/iovisor/bcc/releases/download/v${BCC_VERSION}/bcc-src-with-submodule.tar.gz" |
13 | 44 |
|
| 45 | +# Verify download succeeded and has content |
| 46 | +if [ ! -s bcc-src-with-submodule.tar.gz ]; then |
| 47 | + echo "ERROR: Download failed or file is empty" |
| 48 | + exit 1 |
| 49 | +fi |
14 | 50 |
|
15 | | -# from https://github.com/iovisor/bcc/blob/master/INSTALL.md |
| 51 | +echo "Extracting source..." |
| 52 | +tar xf bcc-src-with-submodule.tar.gz |
| 53 | + |
| 54 | +# Create python symlink if needed (idempotent) |
| 55 | +if [ ! -e /usr/bin/python ]; then |
| 56 | + echo "Creating python symlink..." |
| 57 | + sudo ln -s /usr/bin/python3 /usr/bin/python |
| 58 | +fi |
16 | 59 |
|
| 60 | +# Build and install BCC |
| 61 | +# Reference: https://github.com/iovisor/bcc/blob/master/INSTALL.md |
| 62 | +echo "Building BCC (this may take several minutes)..." |
17 | 63 | cd bcc/ |
18 | | -sudo ln -s /usr/bin/python3 /usr/bin/python |
19 | 64 | mkdir build |
20 | 65 | cd build/ |
21 | | -cmake .. |
22 | | -make |
23 | | -sudo make install |
24 | | -cmake -DPYTHON_CMD=/usr/bin/python3 .. # build python3 binding |
25 | | -pushd src/python/ |
26 | | -make |
27 | | -sudo make install |
28 | | -popd |
29 | | - |
30 | | -# cleanup |
31 | | -cd |
32 | | -sudo rm -rf bcc bcc-src-with-submodule.tar.gz |
33 | 66 |
|
| 67 | +echo "Running cmake..." |
| 68 | +cmake .. > /dev/null |
| 69 | + |
| 70 | +echo "Compiling..." |
| 71 | +make -j$(nproc) |
| 72 | + |
| 73 | +echo "Installing BCC..." |
| 74 | +sudo make install > /dev/null |
| 75 | + |
| 76 | +echo "Building Python3 bindings..." |
| 77 | +cmake -DPYTHON_CMD=/usr/bin/python3 .. > /dev/null |
| 78 | +pushd src/python/ > /dev/null |
| 79 | +make -j$(nproc) |
| 80 | +sudo make install > /dev/null |
| 81 | +popd > /dev/null |
| 82 | + |
| 83 | +# Verify installation |
| 84 | +echo "Verifying BCC installation..." |
| 85 | +if ! python3 -c "import bcc" 2>/dev/null; then |
| 86 | + echo "ERROR: BCC Python module not found after installation" |
| 87 | + exit 1 |
| 88 | +fi |
| 89 | + |
| 90 | +echo "BCC ${BCC_VERSION} installed successfully" |
0 commit comments