Repository navigation
Expand file tree
/
Copy pathbuild-deb.sh
More file actions
executable file
·124 lines (103 loc) · 3.32 KB
/
Copy pathbuild-deb.sh
File metadata and controls
executable file
·124 lines (103 loc) · 3.32 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
119
120
121
122
123
#!/bin/bash
# Debian Package Builder for LBrightness (lbright)
# Maintained by LeanBitLab
set -e
echo "=== Building LBrightness Debian Package ==="
# Check requirements
if ! command -v dpkg-deb >/dev/null 2>&1; then
echo "Error: 'dpkg-deb' is required to build Debian packages."
exit 1
fi
if ! command -v cargo >/dev/null 2>&1; then
echo "Error: 'cargo' is required to compile lbright."
exit 1
fi
# Extract version from Cargo.toml
VERSION=$(grep '^version' Cargo.toml | head -n 1 | cut -d '"' -f 2)
if [ -z "$VERSION" ]; then
VERSION="0.1.0"
fi
# Detect system architecture
ARCH=$(dpkg --print-architecture 2>/dev/null || echo "amd64")
echo "Package Version: $VERSION"
echo "Architecture: $ARCH"
# Build Rust release binary
echo "Compiling release binary..."
cargo build --release
# Define directories
STAGE_DIR="dist/deb_build"
DEBIAN_DIR="$STAGE_DIR/DEBIAN"
BIN_DIR="$STAGE_DIR/usr/bin"
SYSTEMD_DIR="$STAGE_DIR/usr/lib/systemd/user"
DOC_DIR="$STAGE_DIR/usr/share/doc/lbright"
# Clean previous build artifacts
rm -rf dist/
mkdir -p "$DEBIAN_DIR"
mkdir -p "$BIN_DIR"
mkdir -p "$SYSTEMD_DIR"
mkdir -p "$DOC_DIR"
echo "Staging files..."
# Install compiled binary
install -Dm755 target/release/lbright "$BIN_DIR/lbright"
# Systemd User Service unit (adjusted for global /usr/bin execution)
sed 's|%h/.local/bin/lbright|/usr/bin/lbright|g' lbright.service > "$SYSTEMD_DIR/lbright.service"
chmod 644 "$SYSTEMD_DIR/lbright.service"
# Copyright / Documentation
if [ -f "LICENSE" ]; then
cp LICENSE "$DOC_DIR/copyright"
fi
if [ -f "README.md" ]; then
cp README.md "$DOC_DIR/"
fi
echo "Generating package metadata..."
# Create DEBIAN/control
cat << EOF > "$DEBIAN_DIR/control"
Package: lbright
Version: $VERSION
Section: utils
Priority: optional
Architecture: $ARCH
Maintainer: LeanBitLab <leanbitlab@users.noreply.github.com>
Depends: libc6
Recommends: ddcutil, i2c-tools
Provides: adaptive-brightness-linux, lbrightness
Replaces: adaptive-brightness-linux
Description: Lightweight adaptive screen brightness system for Linux
High-performance Rust daemon for intelligent screen brightness
control using direct sysfs kernel I/O, DDC/CI external monitor support,
ALS ambient light smoothing, and an interactive ANSI terminal UI.
EOF
# Create DEBIAN/postinst
cat << 'EOF' > "$DEBIAN_DIR/postinst"
#!/bin/bash
set -e
if [ "$1" = "configure" ]; then
echo "Reloading systemd user daemon..."
systemctl --global daemon-reload 2>/dev/null || true
echo ""
echo "LBrightness (lbright) installed successfully!"
echo "To start the background service for your user:"
echo " systemctl --user enable --now lbright.service"
echo ""
echo "To open the interactive menu: lbright tui"
echo "To check system status: lbright status"
fi
EOF
chmod 755 "$DEBIAN_DIR/postinst"
# Create DEBIAN/prerm
cat << 'EOF' > "$DEBIAN_DIR/prerm"
#!/bin/bash
set -e
if [ "$1" = "remove" ] || [ "$1" = "deconfigure" ]; then
systemctl --global disable lbright.service 2>/dev/null || true
fi
EOF
chmod 755 "$DEBIAN_DIR/prerm"
# Build the Debian package
PACKAGE_NAME="lbright_${VERSION}_${ARCH}.deb"
echo "Compiling Debian package: $PACKAGE_NAME..."
dpkg-deb --root-owner-group --build "$STAGE_DIR" "$PACKAGE_NAME"
echo ""
echo "=== Build Complete ==="
echo "Package generated: $PACKAGE_NAME"
echo "Install with: sudo dpkg -i $PACKAGE_NAME"