Skip to content

Commit feadf1b

Browse files
committed
Add multi-format packaging support (DEB, RPM, tarball)
- Add RPM packaging configuration in Cargo.toml - Create automated build script for all package formats - Add tarball generation with install/uninstall scripts for Arch users - Update documentation with installation instructions for all formats - Add packaging test script to validate configurations
1 parent ad592f7 commit feadf1b

5 files changed

Lines changed: 267 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ bin
66
include
77
doc
88
pyvenv.cfg
9+
dist/

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ A Bluetooth advertisement proxy for Home Assistant using the ESPHome API.
2323
Runs as a daemon, forwarding BLE advertisements via TCP to Home Assistant.
2424
"""
2525

26+
[package.metadata.generate-rpm]
27+
assets = [
28+
{ source = "target/release/linux_bt_proxy", dest = "/usr/bin/linux_bt_proxy", mode = "755" },
29+
{ source = "systemd/linux-bt-proxy.service", dest = "/lib/systemd/system/linux-bt-proxy.service", mode = "644" }
30+
]
31+
[package.metadata.generate-rpm.requires]
32+
systemd = "*"
33+
2634
[dependencies]
2735
clap = { version = "4", features = ["derive"] }
2836
tokio = { version = "1", features = ["full"] }

README.rst

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,48 @@ This project provides a Bluetooth proxy daemon for ESPHome, designed to run on L
66
Current version cooperates with desktop and other system usage of the bluetooth hardware by using the bluez stack via dbus. Future work to access raw advertisements via
77
HCI, bypassing any filtering or delay that bluez may be doing is being considered.
88

9+
Installation
10+
------------
11+
12+
**Debian/Ubuntu (DEB packages)**
13+
14+
System packages for Debian-based systems (Debian, Ubuntu, Pop-OS) are provided as part of the release package:
15+
16+
.. code-block:: bash
17+
18+
sudo dpkg -i linux-bt-proxy_*.deb
19+
20+
**Red Hat/Fedora/CentOS (RPM packages)**
21+
22+
RPM packages are available for Red Hat-based systems:
23+
24+
.. code-block:: bash
25+
26+
sudo rpm -i linux-bt-proxy-*.rpm
27+
# or with dnf/yum:
28+
sudo dnf install linux-bt-proxy-*.rpm
29+
30+
**Arch Linux (Tarball)**
31+
32+
For Arch Linux and other distributions, extract the tarball and run the install script:
33+
34+
.. code-block:: bash
35+
36+
tar -xzf linux-bt-proxy-*-x86_64-unknown-linux-gnu.tar.gz
37+
cd linux-bt-proxy-*
38+
sudo ./install.sh
39+
40+
All packages install the daemon as a systemd service. After installation:
41+
42+
.. code-block:: bash
43+
44+
sudo systemctl enable linux-bt-proxy
45+
sudo systemctl start linux-bt-proxy
46+
947
Usage
1048
-----
11-
System packages for debian based systems (Debian. Ubuntu, Pop-OS) are provided as part of the release package. This daemon runs as a systemd unit.
1249

13-
14-
For testing and development, you many run the proxy daemon with:
50+
For testing and development, you may run the proxy daemon with:
1551

1652
.. code-block:: bash
1753
@@ -39,6 +75,27 @@ Requires Rust (edition 2021 or newer) and a Linux system with BlueZ.
3975
4076
cargo build --release
4177
78+
Packaging
79+
---------
80+
81+
To build all package formats (DEB, RPM, and tarball):
82+
83+
.. code-block:: bash
84+
85+
./scripts/build-packages.sh
86+
87+
This will create packages in the ``dist/`` directory:
88+
89+
- ``*.deb`` - Debian/Ubuntu packages
90+
- ``*.rpm`` - Red Hat/Fedora/CentOS packages
91+
- ``*.tar.gz`` - Generic tarball for Arch Linux and other distributions
92+
93+
Prerequisites for packaging:
94+
95+
.. code-block:: bash
96+
97+
cargo install cargo-deb cargo-generate-rpm
98+
4299
Project Structure
43100
-----------------
44101

scripts/build-packages.sh

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Build script for creating DEB, RPM, and tarball packages
5+
# Usage: ./scripts/build-packages.sh [--skip-build]
6+
7+
SKIP_BUILD=false
8+
if [[ "${1:-}" == "--skip-build" ]]; then
9+
SKIP_BUILD=true
10+
fi
11+
12+
echo "=== Linux Bluetooth Proxy Package Builder ==="
13+
14+
# Get version from Cargo.toml
15+
VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
16+
echo "Building packages for version $VERSION"
17+
18+
# Create output directory
19+
mkdir -p dist
20+
21+
# Build release binary (unless skipped)
22+
if [[ "$SKIP_BUILD" == "false" ]]; then
23+
echo "Building release binary..."
24+
cargo build --release
25+
else
26+
echo "Skipping build (using existing binary)"
27+
fi
28+
29+
# Check if binary exists
30+
if [[ ! -f "target/release/linux_bt_proxy" ]]; then
31+
echo "Error: Release binary not found. Run 'cargo build --release' first."
32+
exit 1
33+
fi
34+
35+
# Build DEB package
36+
echo "Building DEB package..."
37+
if ! command -v cargo-deb &> /dev/null; then
38+
echo "Installing cargo-deb..."
39+
cargo install cargo-deb
40+
fi
41+
cargo deb --output dist/
42+
43+
# Build RPM package
44+
echo "Building RPM package..."
45+
if ! command -v cargo-generate-rpm &> /dev/null; then
46+
echo "Installing cargo-generate-rpm..."
47+
cargo install cargo-generate-rpm
48+
fi
49+
cargo generate-rpm --output dist/
50+
51+
# Create tarball for Arch users
52+
echo "Building tarball..."
53+
TARBALL_NAME="linux-bt-proxy-${VERSION}-x86_64-unknown-linux-gnu"
54+
TARBALL_DIR="dist/${TARBALL_NAME}"
55+
56+
# Create temporary directory structure
57+
mkdir -p "$TARBALL_DIR"/{usr/bin,lib/systemd/system,usr/share/doc/linux-bt-proxy}
58+
59+
# Copy files
60+
cp target/release/linux_bt_proxy "$TARBALL_DIR/usr/bin/"
61+
cp systemd/linux-bt-proxy.service "$TARBALL_DIR/lib/systemd/system/"
62+
cp README.rst "$TARBALL_DIR/usr/share/doc/linux-bt-proxy/"
63+
cp LICENSE "$TARBALL_DIR/usr/share/doc/linux-bt-proxy/"
64+
65+
# Create install script for tarball
66+
cat > "$TARBALL_DIR/install.sh" << 'EOF'
67+
#!/bin/bash
68+
set -euo pipefail
69+
70+
echo "Installing Linux Bluetooth Proxy..."
71+
72+
# Check if running as root
73+
if [[ $EUID -ne 0 ]]; then
74+
echo "This script must be run as root (use sudo)"
75+
exit 1
76+
fi
77+
78+
# Copy files
79+
cp usr/bin/linux_bt_proxy /usr/bin/
80+
chmod 755 /usr/bin/linux_bt_proxy
81+
82+
cp lib/systemd/system/linux-bt-proxy.service /lib/systemd/system/
83+
chmod 644 /lib/systemd/system/linux-bt-proxy.service
84+
85+
# Copy documentation
86+
mkdir -p /usr/share/doc/linux-bt-proxy
87+
cp usr/share/doc/linux-bt-proxy/* /usr/share/doc/linux-bt-proxy/
88+
89+
# Reload systemd
90+
systemctl daemon-reload
91+
92+
echo "Installation complete!"
93+
echo "To start the service: sudo systemctl start linux-bt-proxy"
94+
echo "To enable at boot: sudo systemctl enable linux-bt-proxy"
95+
EOF
96+
97+
chmod +x "$TARBALL_DIR/install.sh"
98+
99+
# Create uninstall script
100+
cat > "$TARBALL_DIR/uninstall.sh" << 'EOF'
101+
#!/bin/bash
102+
set -euo pipefail
103+
104+
echo "Uninstalling Linux Bluetooth Proxy..."
105+
106+
# Check if running as root
107+
if [[ $EUID -ne 0 ]]; then
108+
echo "This script must be run as root (use sudo)"
109+
exit 1
110+
fi
111+
112+
# Stop and disable service
113+
systemctl stop linux-bt-proxy 2>/dev/null || true
114+
systemctl disable linux-bt-proxy 2>/dev/null || true
115+
116+
# Remove files
117+
rm -f /usr/bin/linux_bt_proxy
118+
rm -f /lib/systemd/system/linux-bt-proxy.service
119+
rm -rf /usr/share/doc/linux-bt-proxy
120+
121+
# Reload systemd
122+
systemctl daemon-reload
123+
124+
echo "Uninstallation complete!"
125+
EOF
126+
127+
chmod +x "$TARBALL_DIR/uninstall.sh"
128+
129+
# Create tarball
130+
cd dist
131+
tar -czf "${TARBALL_NAME}.tar.gz" "$TARBALL_NAME"
132+
rm -rf "$TARBALL_NAME"
133+
cd ..
134+
135+
echo "=== Package build complete ==="
136+
echo "Generated packages in dist/:"
137+
ls -la dist/
138+
echo ""
139+
echo "DEB: Install with 'sudo dpkg -i dist/*.deb'"
140+
echo "RPM: Install with 'sudo rpm -i dist/*.rpm' or 'sudo dnf install dist/*.rpm'"
141+
echo "Tarball: Extract and run 'sudo ./install.sh'"

scripts/test-packages.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Test script to verify package configurations
5+
# Usage: ./scripts/test-packages.sh
6+
7+
echo "=== Testing Package Configurations ==="
8+
9+
# Test if cargo-deb config is valid
10+
echo "Testing DEB configuration..."
11+
if cargo deb --help &>/dev/null; then
12+
echo "✓ cargo-deb is available"
13+
else
14+
echo "✗ cargo-deb not found (run: cargo install cargo-deb)"
15+
fi
16+
17+
# Test if cargo-generate-rpm config is valid
18+
echo "Testing RPM configuration..."
19+
if cargo generate-rpm --help &>/dev/null; then
20+
echo "✓ cargo-generate-rpm is available"
21+
else
22+
echo "✗ cargo-generate-rpm not found (run: cargo install cargo-generate-rpm)"
23+
fi
24+
25+
# Test if required files exist
26+
echo "Testing required files..."
27+
required_files=(
28+
"systemd/linux-bt-proxy.service"
29+
"README.rst"
30+
"LICENSE"
31+
"Cargo.toml"
32+
)
33+
34+
for file in "${required_files[@]}"; do
35+
if [[ -f "$file" ]]; then
36+
echo "$file exists"
37+
else
38+
echo "$file missing"
39+
fi
40+
done
41+
42+
# Check if release binary would be built
43+
if [[ -f "target/release/linux_bt_proxy" ]]; then
44+
echo "✓ Release binary exists"
45+
else
46+
echo "⚠ Release binary not found (run: cargo build --release)"
47+
fi
48+
49+
echo ""
50+
echo "Package metadata:"
51+
echo "Name: $(grep '^name = ' Cargo.toml | sed 's/name = "\(.*\)"/\1/')"
52+
echo "Version: $(grep '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')"
53+
echo "Description: $(grep '^description = ' Cargo.toml | sed 's/description = "\(.*\)"/\1/')"
54+
echo "License: $(grep '^license = ' Cargo.toml | sed 's/license = "\(.*\)"/\1/')"
55+
56+
echo ""
57+
echo "Ready to build packages with: ./scripts/build-packages.sh"

0 commit comments

Comments
 (0)