11#! /bin/bash
22# packaging/scripts/build-all-formats.sh
33# Universal build script for all Linux package formats
4- # Usage: ./build-all-formats.sh [version]
4+ # Usage: ./build-all-formats.sh [version] [formats...]
5+ #
6+ # Examples:
7+ # ./build-all-formats.sh # Build all formats
8+ # ./build-all-formats.sh 1.4.10 # Build all formats with specific version
9+ # ./build-all-formats.sh 1.4.10 deb rpm # Build only deb and rpm
10+ #
11+ # Supported formats: deb, rpm, arch, appimage, flatpak, snap
512
613set -euo pipefail
714
8- VERSION=" ${1:- 1.0.0} "
15+ VERSION=" ${1:- } "
16+ shift || true
17+
18+ # Get version from Cargo.toml if not provided
19+ if [[ -z " $VERSION " ]]; then
20+ ROOT=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) /../.." && pwd) "
21+ VERSION=$( grep ' ^version' " $ROOT /crates/terraphim_agent/Cargo.toml" | head -1 | sed ' s/.*"\(.*\)".*/\1/' )
22+ fi
23+
924ROOT=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) /../.." && pwd) "
1025PACKAGING_ROOT=" $ROOT /packaging"
26+ RELEASE_DIR=" $ROOT /release-artifacts"
1127
1228echo " ====================================================================="
13- echo " 🚀 Building all Linux package formats for Terraphim AI v$VERSION "
29+ echo " Building all Linux package formats for Terraphim AI v$VERSION "
1430echo " ====================================================================="
1531echo " "
1632
1733# Create release directory
18- mkdir -p " $ROOT /release-artifacts "
34+ mkdir -p " $RELEASE_DIR "
1935
2036# Setup Tauri signing if available
2137if [[ -f " $HOME /.tauri/tauriconfig" ]]; then
38+ # shellcheck source=/dev/null
2239 source " $HOME /.tauri/tauriconfig"
23- echo " 🔐 Using configured Tauri signing keys"
40+ echo " Using configured Tauri signing keys"
41+ else
42+ echo " Note: Tauri signing not configured, building unsigned packages"
43+ fi
44+
45+ # Determine which formats to build
46+ if [[ $# -gt 0 ]]; then
47+ FORMATS=(" $@ " )
2448else
25- echo " ⚠️ Tauri signing not configured, building unsigned packages "
49+ FORMATS=( " deb " " rpm " " arch " " appimage " " flatpak " " snap " )
2650fi
2751
52+ # Track build results
53+ declare -A BUILD_RESULTS
54+
2855# Function to build specific format
2956build_format () {
3057 local format=" $1 "
31- echo " 🔧 Building $format packages..."
32-
33- case " $format " in
34- " deb" )
35- " $PACKAGING_ROOT /scripts/build-deb.sh"
36- ;;
37- " rpm" )
38- " $PACKAGING_ROOT /scripts/build-rpm.sh"
39- ;;
40- " arch" )
41- " $PACKAGING_ROOT /scripts/build-arch.sh"
42- ;;
43- " appimage" )
44- " $PACKAGING_ROOT /scripts/build-appimage.sh"
45- ;;
46- " flatpak" )
47- " $PACKAGING_ROOT /scripts/build-flatpak.sh"
48- ;;
49- " snap" )
50- " $PACKAGING_ROOT /scripts/build-snap.sh"
51- ;;
52- * )
53- echo " ❌ Unknown format: $format "
54- return 1
55- ;;
56- esac
57-
58- echo " ✅ $format build complete"
58+ local script=" $PACKAGING_ROOT /scripts/build-$format .sh"
59+
60+ echo " ---------------------------------------------------------------------"
61+ echo " Building $format packages..."
62+ echo " ---------------------------------------------------------------------"
63+
64+ if [[ ! -x " $script " ]]; then
65+ if [[ -f " $script " ]]; then
66+ chmod +x " $script "
67+ else
68+ echo " Warning: Build script not found: $script "
69+ BUILD_RESULTS[$format ]=" skipped"
70+ return 0
71+ fi
72+ fi
73+
74+ if " $script " ; then
75+ BUILD_RESULTS[$format ]=" success"
76+ echo " $format build complete"
77+ else
78+ BUILD_RESULTS[$format ]=" failed"
79+ echo " Warning: $format build failed"
80+ fi
5981 echo " "
6082}
6183
62- # Build all formats
63- FORMATS=(" deb" " rpm" " arch" " appimage" " flatpak" " snap" )
84+ # Build release binaries first (shared by multiple formats)
85+ echo " Building release binaries..."
86+ cargo build --release -p terraphim_agent 2>&1 || {
87+ echo " Error: Failed to build release binaries"
88+ exit 1
89+ }
90+ echo " "
6491
92+ # Build each format
6593for format in " ${FORMATS[@]} " ; do
66- build_format " $format "
94+ build_format " $format " || true
6795done
6896
69- # Move all artifacts to release directory
70- echo " 📦 Collecting artifacts..."
71- find " $PACKAGING_ROOT " -name " *.$format " -o -name " *.AppImage" -o -name " *.flatpak" -o -name " *.snap" | while read -r artifact; do
72- cp " $artifact " " $ROOT /release-artifacts/"
73- done
97+ # Collect all artifacts to release directory
98+ echo " ====================================================================="
99+ echo " Collecting artifacts..."
100+ echo " ====================================================================="
101+
102+ # Collect from various output directories
103+ collect_artifacts () {
104+ local src_dir=" $1 "
105+ local pattern=" $2 "
106+
107+ if [[ -d " $src_dir " ]]; then
108+ find " $src_dir " -maxdepth 2 -name " $pattern " -type f 2> /dev/null | while read -r artifact; do
109+ cp -v " $artifact " " $RELEASE_DIR /" 2> /dev/null || true
110+ done
111+ fi
112+ }
113+
114+ # Collect all package types
115+ collect_artifacts " $ROOT /target/debian" " *.deb"
116+ collect_artifacts " $ROOT /target/rpm" " *.rpm"
117+ collect_artifacts " $ROOT /target/arch" " *.pkg.tar*"
118+ collect_artifacts " $ROOT /target/appimage" " *.AppImage"
119+ collect_artifacts " $ROOT /target/flatpak" " *.flatpak"
120+ collect_artifacts " $ROOT /target/snap" " *.snap"
121+
122+ # Also collect from Tauri bundle directory
123+ if [[ -d " $ROOT /desktop/src-tauri/target/release/bundle" ]]; then
124+ collect_artifacts " $ROOT /desktop/src-tauri/target/release/bundle/deb" " *.deb"
125+ collect_artifacts " $ROOT /desktop/src-tauri/target/release/bundle/rpm" " *.rpm"
126+ collect_artifacts " $ROOT /desktop/src-tauri/target/release/bundle/appimage" " *.AppImage"
127+ fi
74128
75129# Generate checksums
76- echo " 🔐 Generating checksums..."
77- cd " $ROOT /release-artifacts"
78- sha256sum * > checksums.txt
130+ if [[ -n " $( ls -A " $RELEASE_DIR " 2> /dev/null) " ]]; then
131+ echo " "
132+ echo " Generating checksums..."
133+ (cd " $RELEASE_DIR " && sha256sum ./* > checksums.txt 2> /dev/null) || true
134+ fi
79135
80136# Display results
81137echo " "
82138echo " ====================================================================="
83- echo " 📋 Build Summary"
139+ echo " Build Summary"
84140echo " ====================================================================="
85- echo " Release artifacts created:"
86- ls -la
87141
88142echo " "
89- echo " 🔐 Checksums available in: checksums.txt"
143+ echo " Build results:"
144+ for format in " ${! BUILD_RESULTS[@]} " ; do
145+ status=" ${BUILD_RESULTS[$format]} "
146+ case " $status " in
147+ " success" ) marker=" [OK]" ;;
148+ " failed" ) marker=" [FAIL]" ;;
149+ " skipped" ) marker=" [SKIP]" ;;
150+ * ) marker=" [?]" ;;
151+ esac
152+ printf " %-10s %s\n" " $format :" " $marker "
153+ done
90154
91- # Verify package sizes
92155echo " "
93- echo " 📊 Package sizes:"
94- for file in * .deb * .rpm * .pkg.tar* * .AppImage * .flatpak * .snap; do
95- if [[ -f " $file " ]]; then
96- size=$( stat -f%z " $file " 2> /dev/null || stat -c%s " $file " 2> /dev/null || echo " unknown" )
97- echo " $file : $( numfmt --to=iec-i --suffix=B " $size " ) "
98- fi
156+ echo " Release artifacts:"
157+ if [[ -d " $RELEASE_DIR " ]] && [[ -n " $( ls -A " $RELEASE_DIR " 2> /dev/null) " ]]; then
158+ ls -lh " $RELEASE_DIR "
159+ else
160+ echo " (no artifacts found)"
161+ fi
162+
163+ echo " "
164+ echo " Checksums available in: $RELEASE_DIR /checksums.txt"
165+
166+ # Package sizes
167+ echo " "
168+ echo " Package sizes:"
169+ shopt -s nullglob
170+ for ext in deb rpm pkg.tar.zst pkg.tar.xz AppImage flatpak snap; do
171+ for file in " $RELEASE_DIR " /* ." $ext " ; do
172+ if [[ -f " $file " ]]; then
173+ size=$( stat -c%s " $file " 2> /dev/null || stat -f%z " $file " 2> /dev/null || echo " 0" )
174+ if command -v numfmt & > /dev/null; then
175+ size_human=$( numfmt --to=iec-i --suffix=B " $size " 2> /dev/null || echo " ${size} B" )
176+ else
177+ size_human=" ${size} B"
178+ fi
179+ printf " %-40s %s\n" " $( basename " $file " ) :" " $size_human "
180+ fi
181+ done
99182done
183+ shopt -u nullglob
100184
185+ # Final status
101186echo " "
102- echo " 🎉 All package formats built successfully!"
103- echo " ====================================================================="
187+ echo " ====================================================================="
188+ failed_count=0
189+ for status in " ${BUILD_RESULTS[@]} " ; do
190+ [[ " $status " == " failed" ]] && (( failed_count++ )) || true
191+ done
192+
193+ if [[ $failed_count -eq 0 ]]; then
194+ echo " All requested package formats built successfully!"
195+ else
196+ echo " Warning: $failed_count format(s) failed to build."
197+ fi
198+ echo " ====================================================================="
199+
200+ exit 0
0 commit comments