-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild-deb.sh
More file actions
executable file
·156 lines (131 loc) · 4.65 KB
/
build-deb.sh
File metadata and controls
executable file
·156 lines (131 loc) · 4.65 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
#
# build-deb.sh — Build a .deb package for rustguac (includes guacd).
#
# Prerequisites:
# - Rust toolchain (cargo)
# - guacd build deps (autoconf, automake, libtool, -dev packages)
# - dpkg-dev, debhelper, fakeroot
#
# guacamole-server is cloned automatically if not found at ../guacamole-server.
#
# Usage:
# ./build-deb.sh
#
# Output:
# ../rustguac_<version>_amd64.deb
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
GUACD_SRC_URL="https://github.com/apache/guacamole-server.git"
GUACD_SRC="${SCRIPT_DIR}/../guacamole-server"
STAGING="${SCRIPT_DIR}/debian/staging"
PREFIX="/opt/rustguac"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { echo -e "${GREEN}[build-deb]${NC} $*"; }
warn() { echo -e "${YELLOW}[build-deb]${NC} $*"; }
error() { echo -e "${RED}[build-deb]${NC} $*" >&2; }
# ---------------------------------------------------------------------------
# Step 1: Determine version
# ---------------------------------------------------------------------------
CARGO_VERSION=$(grep '^version' "$SCRIPT_DIR/Cargo.toml" | head -1 | sed 's/.*"\(.*\)".*/\1/')
GIT_HASH=$(git -C "$SCRIPT_DIR" rev-parse --short HEAD 2>/dev/null || echo "unknown")
VERSION="${CARGO_VERSION}+g${GIT_HASH}"
info "Building rustguac ${VERSION}"
# ---------------------------------------------------------------------------
# Step 2: Generate debian/changelog
# ---------------------------------------------------------------------------
info "Generating debian/changelog..."
cat > "$SCRIPT_DIR/debian/changelog" <<EOF
rustguac (${VERSION}) unstable; urgency=medium
* Built from git commit ${GIT_HASH}.
-- rustguac build <rustguac@localhost> $(date -R)
EOF
# ---------------------------------------------------------------------------
# Step 3: Build guacd into staging
# ---------------------------------------------------------------------------
apply_guacd_patches() {
local src="$1"
local patch_dir="${SCRIPT_DIR}/patches"
if [[ ! -d "$patch_dir" ]]; then
return 0
fi
for patch in "$patch_dir"/*.patch; do
[[ -f "$patch" ]] || continue
if git -C "$src" apply --check "$patch" 2>/dev/null; then
info "Applying patch: $(basename "$patch")"
git -C "$src" apply "$patch"
else
info "Patch already applied or N/A: $(basename "$patch")"
fi
done
}
build_guacd() {
if [[ ! -d "$GUACD_SRC/.git" ]]; then
info "guacamole-server not found at $GUACD_SRC — cloning..."
git clone --depth 1 "$GUACD_SRC_URL" "$GUACD_SRC"
fi
apply_guacd_patches "$GUACD_SRC"
info "Building guacd from $GUACD_SRC..."
local BUILD_DIR
BUILD_DIR=$(mktemp -d)
trap "rm -rf '$BUILD_DIR'" EXIT
# Run autoreconf if needed
if [[ ! -f "$GUACD_SRC/configure" ]]; then
info "Running autoreconf..."
(cd "$GUACD_SRC" && autoreconf -fi)
fi
cd "$BUILD_DIR"
info "Configuring guacd (prefix=$PREFIX)..."
"$GUACD_SRC/configure" \
--prefix="$PREFIX" \
--with-ssh \
--with-vnc \
--with-rdp \
--without-telnet \
--without-kubernetes \
--disable-guacenc \
--disable-guaclog \
--disable-static
info "Compiling guacd..."
make -j"$(nproc)"
info "Installing guacd to staging..."
rm -rf "$STAGING"
make DESTDIR="$STAGING" install
cd "$SCRIPT_DIR"
info "guacd staged at $STAGING"
}
build_guacd
# ---------------------------------------------------------------------------
# Step 4: Build rustguac
# ---------------------------------------------------------------------------
info "Building rustguac (cargo build --release)..."
cd "$SCRIPT_DIR"
cargo build --release
info "rustguac built."
# ---------------------------------------------------------------------------
# Step 5: Build the .deb
# ---------------------------------------------------------------------------
info "Running dpkg-buildpackage..."
cd "$SCRIPT_DIR"
dpkg-buildpackage -us -uc -b
# ---------------------------------------------------------------------------
# Step 6: Report results
# ---------------------------------------------------------------------------
DEB=$(ls -1t "$SCRIPT_DIR/../rustguac_${VERSION}_"*.deb 2>/dev/null | head -1)
if [[ -n "$DEB" ]]; then
echo ""
info "============================================"
info " Package built: $DEB"
info "============================================"
echo ""
info "Install on target:"
info " scp $DEB root@target:"
info " ssh root@target 'dpkg -i $(basename "$DEB") && apt-get -f install -y'"
else
error "Package not found — check build output above."
exit 1
fi