Repository navigation
Expand file tree
/
Copy pathcreate-appimage-cli.sh
More file actions
executable file
·496 lines (427 loc) · 18.5 KB
/
Copy pathcreate-appimage-cli.sh
File metadata and controls
executable file
·496 lines (427 loc) · 18.5 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
#!/bin/sh
set -e
# Script to create AppImage for CLI-only rpi-imager
# This creates a minimal AppImage that only supports command-line operation
# Parse command line arguments
ARCH=$(uname -m) # Default to current architecture
CLEAN_BUILD=1
QT_ROOT_ARG=""
usage() {
echo "Usage: $0 [options]"
echo "Options:"
echo " --arch=ARCH Target architecture (x86_64, aarch64, armhf)"
echo " --qt-root=PATH Path to Qt installation directory"
echo " --no-clean Don't clean build directory"
echo " -h, --help Show this help message"
echo ""
echo "This script creates an AppImage optimized for CLI-only operation:"
echo " - Forces CLI mode (no GUI components)"
echo " - Uses only Qt Core libraries"
echo " - Minimal size by excluding all GUI dependencies"
echo " - Perfect for headless/server environments"
exit 1
}
for arg in "$@"; do
case $arg in
--arch=*)
ARCH="${arg#*=}"
;;
--qt-root=*)
QT_ROOT_ARG="${arg#*=}"
;;
--no-clean)
CLEAN_BUILD=0
;;
--packaging=*)
APPIMAGE_PACKAGING="${arg#*=}"
;;
-h|--help)
usage
;;
*)
echo "Unknown option: $arg"
usage
;;
esac
done
# Resolve Qt root path argument if provided (expand ~ and convert to absolute path)
if [ -n "$QT_ROOT_ARG" ]; then
# Expand tilde if present at the start
case "$QT_ROOT_ARG" in
"~"/*) QT_ROOT_ARG="$HOME/${QT_ROOT_ARG#\~/}" ;;
"~") QT_ROOT_ARG="$HOME" ;;
esac
# Convert to absolute path if it exists
if [ -e "$QT_ROOT_ARG" ]; then
QT_ROOT_ARG=$(cd "$QT_ROOT_ARG" && pwd)
else
echo "Warning: Specified Qt root path does not exist: $QT_ROOT_ARG"
echo "Will attempt to use it anyway, but this may fail..."
fi
fi
# Validate architecture (armv6l/armv7l from uname on 32-bit Pi OS → armhf)
case "$ARCH" in
armv6l|armv7l) ARCH=armhf ;;
esac
if [ "$ARCH" != "x86_64" ] && [ "$ARCH" != "aarch64" ] && [ "$ARCH" != "armhf" ]; then
echo "Error: Architecture must be one of: x86_64, aarch64, armhf" >&2
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TOP="$SCRIPT_DIR"
# shellcheck disable=SC1091
. "$TOP/debian/lib.sh"
export_cmake_parallel
sh "$TOP/debian/fetch-vendor-deps.sh"
APPIMAGE_PACKAGING=${APPIMAGE_PACKAGING:-all}
TOOL_ARCH=$(appimage_resolve_tool_arch)
echo "Building CLI-only AppImage for architecture: $ARCH (packaging tools: $TOOL_ARCH, mode: $APPIMAGE_PACKAGING)"
if [ "$ARCH" != "$TOOL_ARCH" ]; then
echo "create-appimage-cli: cross packaging — build in chroot, pack with $TOOL_ARCH tools on the host"
fi
# Extract project information from CMakeLists.txt
SOURCE_DIR="src/"
CMAKE_FILE="${SOURCE_DIR}CMakeLists.txt"
# Get version from git tag (same approach as CMake)
GIT_VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "0.0.0-unknown")
# Extract numeric version components for compatibility
# Match versions like: v1.2.3, 1.2.3, v1.2.3-extra, etc.
MAJOR=$(echo "$GIT_VERSION" | sed -n 's/^v\{0,1\}\([0-9]\{1,\}\)\.[0-9]\{1,\}\.[0-9]\{1,\}.*/\1/p')
MINOR=$(echo "$GIT_VERSION" | sed -n 's/^v\{0,1\}[0-9]\{1,\}\.\([0-9]\{1,\}\)\.[0-9]\{1,\}.*/\1/p')
PATCH=$(echo "$GIT_VERSION" | sed -n 's/^v\{0,1\}[0-9]\{1,\}\.[0-9]\{1,\}\.\([0-9]\{1,\}\).*/\1/p')
if [ -n "$MAJOR" ] && [ -n "$MINOR" ] && [ -n "$PATCH" ]; then
PROJECT_VERSION="$MAJOR.$MINOR.$PATCH"
else
MAJOR="0"
MINOR="0"
PATCH="0"
PROJECT_VERSION="0.0.0"
echo "Warning: Could not parse version from git tag: $GIT_VERSION"
fi
# Extract project name (lowercase for AppImage naming convention)
PROJECT_NAME=$(grep "project(" "$CMAKE_FILE" | head -1 | sed 's/project(\([^[:space:]]*\).*/\1/' | tr '[:upper:]' '[:lower:]')
echo "Building $PROJECT_NAME version $GIT_VERSION (numeric: $PROJECT_VERSION) for CLI-only operation"
QT_VERSION=""
QT_DIR=""
# Reject desktop Qt paths — CLI AppImages must use gcc_*_cli builds only.
validate_cli_qt_dir() {
_dir=$1
case "$_dir" in
*/gcc_64_cli|*/gcc_arm64_cli|*/gcc_arm32_cli) return 0 ;;
esac
echo "Error: CLI AppImages require a CLI-only Qt build (gcc_*_cli), not desktop Qt." >&2
echo " Refusing: $_dir" >&2
echo " Build one with: ./qt/build-qt-cli.sh" >&2
exit 1
}
# The pack stage only wraps an AppDir built earlier, so it never needs Qt — even
# when target arch == tool arch (host-arch chroot build packed on the host).
if [ "$APPIMAGE_PACKAGING" != pack ]; then
# Check if Qt root is specified via command line argument (highest priority)
if [ -n "$QT_ROOT_ARG" ]; then
echo "Using Qt from command line argument: $QT_ROOT_ARG"
QT_DIR="$QT_ROOT_ARG"
# Check if Qt6_ROOT is explicitly set in environment
elif [ -n "$Qt6_ROOT" ]; then
echo "Using Qt from Qt6_ROOT environment variable: $Qt6_ROOT"
QT_DIR="$Qt6_ROOT"
# Auto-detect CLI Qt in QT_CACHE, then /opt/Qt (gcc_*_cli only)
else
_qt_search_dirs=""
if [ -n "${QT_CACHE:-}" ] && [ -d "$QT_CACHE" ]; then
case "$ARCH" in
x86_64) _qt_deb_arch=amd64 ;;
aarch64) _qt_deb_arch=arm64 ;;
armhf) _qt_deb_arch=armhf ;;
*) _qt_deb_arch="" ;;
esac
if [ -n "$_qt_deb_arch" ] && [ -d "$QT_CACHE/$_qt_deb_arch" ]; then
_qt_search_dirs="$QT_CACHE/$_qt_deb_arch"
fi
fi
if [ -z "$_qt_search_dirs" ] && [ -d "/opt/Qt" ]; then
_qt_search_dirs="/opt/Qt"
fi
if [ -n "$_qt_search_dirs" ]; then
echo "Checking for CLI Qt installations in $_qt_search_dirs..."
NEWEST_QT=$(find -L "$_qt_search_dirs" -maxdepth 1 -type d -name "6.*" | sort -V | tail -n 1)
if [ -n "$NEWEST_QT" ]; then
QT_VERSION=$(basename "$NEWEST_QT")
if [ "$ARCH" = "x86_64" ]; then
if [ -d "$NEWEST_QT/gcc_64_cli" ]; then
QT_DIR="$NEWEST_QT/gcc_64_cli"
fi
elif [ "$ARCH" = "aarch64" ]; then
if [ -d "$NEWEST_QT/gcc_arm64_cli" ]; then
QT_DIR="$NEWEST_QT/gcc_arm64_cli"
fi
elif [ "$ARCH" = "armhf" ]; then
if [ -d "$NEWEST_QT/gcc_arm32_cli" ]; then
QT_DIR="$NEWEST_QT/gcc_arm32_cli"
fi
fi
if [ -n "$QT_DIR" ]; then
echo "Found CLI Qt $QT_VERSION for $ARCH at $QT_DIR"
elif [ -n "$QT_VERSION" ]; then
echo "Found Qt $QT_VERSION, but no CLI build for $ARCH (gcc_*_cli)"
QT_VERSION=""
fi
fi
fi
fi
# If Qt not found, suggest building it
if [ -z "$QT_DIR" ]; then
echo "Error: No CLI-only Qt installation found for $ARCH" >&2
echo "Desktop Qt (gcc_64, gcc_arm64, …) must not be used for CLI AppImages." >&2
if [ -f "./qt/build-qt-cli.sh" ]; then
echo "Build a CLI-only Qt with:" >&2
echo " debian/ensure-qt.sh <arch>" >&2
echo "Or specify the CLI Qt path with:" >&2
echo " $0 --qt-root=/opt/Qt/VERSION/gcc_*_cli" >&2
else
echo "Specify the CLI Qt path with:" >&2
echo " $0 --qt-root=/path/to/gcc_*_cli" >&2
fi
exit 1
fi
validate_cli_qt_dir "$QT_DIR"
# Check Qt version (do not execute foreign-arch qmake on the build host)
if [ -f "$QT_DIR/bin/qmake" ]; then
if [ "$ARCH" = "$TOOL_ARCH" ] || [ -n "${RPI_IMAGER_CHROOT:-}" ]; then
QT_VERSION=$("$QT_DIR/bin/qmake" -query QT_VERSION)
echo "Qt version: $QT_VERSION"
elif [ -z "$QT_VERSION" ]; then
QT_VERSION=$(basename "$(dirname "$QT_DIR")")
echo "Qt version: $QT_VERSION (from cache path; foreign-arch qmake not executed on host)"
fi
fi
fi
if [ "$APPIMAGE_PACKAGING" = pack ]; then
echo "create-appimage-cli: using AppDir from build stage (pack)"
fi
# Configuration
BUILD_TYPE="MinSizeRel" # Optimize for size
# Location of AppDir and output file
APPDIR="$PWD/AppDir-cli-$ARCH"
OUTPUT_FILE="$PWD/Raspberry_Pi_Imager-${GIT_VERSION}-cli-${ARCH}.AppImage"
# Tools directory for downloaded binaries
TOOLS_DIR="$PWD/appimage-tools"
mkdir -p "$TOOLS_DIR"
# Download linuxdeploy and plugins if they don't exist
echo "Ensuring linuxdeploy tools are available..."
# Choose packaging tools for the machine running this script (TOOL_ARCH).
LINUXDEPLOY=""
APPIMAGETOOL=""
# linuxdeploy has no armhf build; those targets fall back to appimagetool below.
if [ "$ARCH" = "$TOOL_ARCH" ] && { [ "$TOOL_ARCH" = "x86_64" ] || [ "$TOOL_ARCH" = "aarch64" ]; }; then
LINUXDEPLOY="$TOOLS_DIR/linuxdeploy-$TOOL_ARCH.AppImage"
appimage_download_tool "$LINUXDEPLOY" \
"https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-$TOOL_ARCH.AppImage"
fi
APPIMAGETOOL="$TOOLS_DIR/appimagetool-$TOOL_ARCH.AppImage"
appimage_download_tool "$APPIMAGETOOL" \
"https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-$TOOL_ARCH.AppImage"
if [ "$APPIMAGE_PACKAGING" = pack ] && [ ! -d "$APPDIR/usr/bin" ]; then
echo "Error: AppDir missing for pack stage: $APPDIR" >&2
exit 1
fi
if [ "$APPIMAGE_PACKAGING" != pack ]; then
# Set up build directory
BUILD_DIR="build-cli-$ARCH"
# Clean up previous builds if requested
if [ "$CLEAN_BUILD" -eq 1 ]; then
echo "Cleaning previous build..."
rm -rf "$APPDIR" "$BUILD_DIR"
fi
mkdir -p "$APPDIR"
mkdir -p "$BUILD_DIR"
echo "Building rpi-imager CLI-only for $ARCH..."
# Configure and build with CMake
cd "$BUILD_DIR"
# Set architecture-specific CMake flags
CMAKE_EXTRA_FLAGS=""
if [ "$ARCH" = "aarch64" ] && [ "$(uname -m)" = "x86_64" ]; then
# Cross-compiling from x86_64 to aarch64
echo "Cross-compiling from $(uname -m) to $ARCH"
CMAKE_EXTRA_FLAGS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=aarch64"
elif [ "$ARCH" = "armhf" ] && [ "$(uname -m)" = "x86_64" ]; then
# Cross-compiling from x86_64 to armhf (Pi 1 / Pi 2 32-bit OS)
echo "Cross-compiling from $(uname -m) to $ARCH"
CMAKE_EXTRA_FLAGS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=arm"
fi
# Add Qt path to CMake flags
CMAKE_EXTRA_FLAGS="$CMAKE_EXTRA_FLAGS -DQt6_ROOT=$QT_DIR"
# Build CLI-only version
CMAKE_EXTRA_FLAGS="$CMAKE_EXTRA_FLAGS -DBUILD_CLI_ONLY=ON"
# shellcheck disable=SC2086
cmake -G Ninja "../$SOURCE_DIR" -DCMAKE_BUILD_TYPE="$BUILD_TYPE" -DCMAKE_INSTALL_PREFIX=/usr $CMAKE_EXTRA_FLAGS
cmake --build . --parallel "$(cmake_build_jobs)"
echo "Creating CLI-only AppDir..."
# Install to AppDir
DESTDIR="$APPDIR" cmake --install .
cd ..
# Desktop file and icon are already installed by CMake
# Create the AppRun file for CLI operation
cat > "$APPDIR/AppRun" << 'EOF'
#!/bin/sh
HERE="$(dirname "$(readlink -f "${0}")")"
# Set up paths
export PATH="${HERE}/usr/bin:${PATH}"
export LD_LIBRARY_PATH="${HERE}/usr/lib:${LD_LIBRARY_PATH}"
# Execute the CLI-only binary directly (no --cli flag needed, it's built-in)
exec "${HERE}/usr/bin/rpi-imager-cli" "$@"
EOF
chmod +x "$APPDIR/AppRun"
# Manual Qt deployment for CLI-only (minimal)
echo "Deploying minimal Qt dependencies for CLI-only operation..."
# Copy only essential Qt libraries (CLI-only)
mkdir -p "$APPDIR/usr/lib"
cp -d "$QT_DIR/lib/libQt6Core.so"* "$APPDIR/usr/lib/"
cp -d "$QT_DIR/lib/libQt6Network.so"* "$APPDIR/usr/lib/" 2>/dev/null || true
# Note: No GUI libraries (QtGui, QtQuick, QtWidgets, QtSvg, etc.)
# Copy minimal plugins (no GUI plugins needed)
mkdir -p "$APPDIR/usr/plugins/platforms"
# Note: No platform plugins needed for CLI-only operation
# Copy only essential network plugins
mkdir -p "$APPDIR/usr/plugins"
cp -r "$QT_DIR/plugins/tls" "$APPDIR/usr/plugins/" 2>/dev/null || true
# CLI-specific optimizations
echo "Applying CLI-only optimizations..."
# Remove any GUI-related files that might have been included
rm -rf "$APPDIR/usr/qml" 2>/dev/null || true
rm -rf "$APPDIR/usr/plugins/platforms" 2>/dev/null || true
rm -rf "$APPDIR/usr/plugins/imageformats" 2>/dev/null || true
rm -rf "$APPDIR/usr/plugins/iconengines" 2>/dev/null || true
rm -rf "$APPDIR/usr/share/fonts" 2>/dev/null || true
rm -rf "$APPDIR/usr/translations" 2>/dev/null || true
# Remove GUI libraries if they somehow got included
rm -f "$APPDIR/usr/lib/libQt6Gui.so"* 2>/dev/null || true
rm -f "$APPDIR/usr/lib/libQt6Quick.so"* 2>/dev/null || true
rm -f "$APPDIR/usr/lib/libQt6Qml.so"* 2>/dev/null || true
rm -f "$APPDIR/usr/lib/libQt6Widgets.so"* 2>/dev/null || true
rm -f "$APPDIR/usr/lib/libQt6Svg.so"* 2>/dev/null || true
rm -f "$APPDIR/usr/lib/libQt"*"QuickControls"*.so* 2>/dev/null || true
# Bundle the non-host-coupled dependency closure of Qt Core/Network and the TLS
# backends. Without this the CLI relies on the host for ICU, PCRE2, zstd and
# friends; ICU is soname-pinned per Debian release, so leaving it out would tie
# the package to a single distro version.
appimage_deploy_lib_closure "$APPDIR" "$QT_DIR/lib" || exit 1
# Remove development files to save space
find "$APPDIR" -name "*.a" -delete 2>/dev/null || true
find "$APPDIR" -name "*.la" -delete 2>/dev/null || true
find "$APPDIR" -name "*.prl" -delete 2>/dev/null || true
# Strip binaries to reduce size
find "$APPDIR" -type f -executable -exec strip {} \; 2>/dev/null || true
echo "Stripping shared libraries..."
SAVED_DIR="$PWD"
cd "$APPDIR"
SO_FILES=$(find . -name "*.so*" 2>/dev/null || true)
if [ -n "$SO_FILES" ]; then
echo "$SO_FILES"
# shellcheck disable=SC2086
strip --strip-unneeded $SO_FILES 2>/dev/null || true
fi
cd "$SAVED_DIR"
fi
if [ "$APPIMAGE_PACKAGING" = build ]; then
prepare_appdir_for_appimagetool "$APPDIR" com.raspberrypi.rpi-imager-cli
echo "create-appimage-cli: build stage complete (AppDir at $APPDIR)"
exit 0
fi
echo "Creating CLI-only AppImage..."
# Remove old symlinks for CLI variant only
rm -f "$PWD/rpi-imager-cli.AppImage"
rm -f "$PWD/rpi-imager-cli-$ARCH.AppImage"
if [ -n "$LINUXDEPLOY" ] && [ -f "$LINUXDEPLOY" ] && [ "$ARCH" = "$TOOL_ARCH" ] && [ "$APPIMAGE_PACKAGING" = all ]; then
# Create AppImage using linuxdeploy
# Explicitly specify the desktop file to ensure correct naming
LD_LIBRARY_PATH="$QT_DIR/lib:$LD_LIBRARY_PATH" "$LINUXDEPLOY" --appdir="$APPDIR" \
--desktop-file="$APPDIR/usr/share/applications/com.raspberrypi.rpi-imager-cli.desktop" \
--output=appimage \
--exclude-library="libwayland-*" \
--exclude-library="libX11*" \
--exclude-library="libxcb*" \
--exclude-library="libXext*" \
--exclude-library="libLLVM*" \
--exclude-library="libgallium*" \
--exclude-library="libXrender*" \
--exclude-library="libGL*" \
--exclude-library="libEGL*" \
--exclude-library="libsystemd*"
# Remove libsystemd if it slipped through --exclude-library
# It must come from the host system to work with lsblk/libmount/DBus
# (see https://github.com/raspberrypi/rpi-imager/issues/1304, #1577)
rm -f "$APPDIR/usr/lib/libsystemd"*
# Rename the output file from linuxdeploy's default name to our versioned name
# linuxdeploy creates: Raspberry_Pi_Imager_(CLI)-${ARCH}.AppImage (based on Name= in desktop file)
LINUXDEPLOY_OUTPUT="Raspberry_Pi_Imager_(CLI)-${ARCH}.AppImage"
if [ -f "$LINUXDEPLOY_OUTPUT" ]; then
echo "Renaming '$LINUXDEPLOY_OUTPUT' to '$(basename "$OUTPUT_FILE")'"
mv "$LINUXDEPLOY_OUTPUT" "$OUTPUT_FILE"
elif [ -f "$OUTPUT_FILE" ]; then
echo "Output file already exists: $OUTPUT_FILE"
else
echo "Warning: Expected linuxdeploy output '$LINUXDEPLOY_OUTPUT' not found"
echo "Looking for any matching AppImage..."
ls -la ./*.AppImage 2>/dev/null || true
fi
elif [ -n "${APPIMAGETOOL:-}" ] && [ -f "$APPIMAGETOOL" ]; then
appimage_pack_with_tool "$APPIMAGETOOL" "$APPDIR" "$OUTPUT_FILE" \
"$ARCH" "$TOOL_ARCH" com.raspberrypi.rpi-imager-cli || exit 1
else
# Manual AppImage creation (basic implementation)
echo "Creating AppImage manually (basic implementation)..."
# This is a simplified approach - for full AppImage creation,
# you would need appimagetool or similar
tar czf "${OUTPUT_FILE%.AppImage}.tar.gz" -C "$APPDIR" .
echo "Created compressed archive: ${OUTPUT_FILE%.AppImage}.tar.gz"
echo "Note: Full AppImage creation requires appimagetool for $ARCH"
fi
if [ -f "$OUTPUT_FILE" ]; then
echo "CLI-only AppImage created at $OUTPUT_FILE"
# Create symlinks for debian packaging and user convenience
# Primary symlink matches debian/rpi-imager-cli.install expectations
DEBIAN_SYMLINK="$PWD/rpi-imager-cli-$ARCH.AppImage"
if [ -L "$DEBIAN_SYMLINK" ] || [ -f "$DEBIAN_SYMLINK" ]; then
rm -f "$DEBIAN_SYMLINK"
fi
ln -s "$(basename "$OUTPUT_FILE")" "$DEBIAN_SYMLINK"
echo "Created symlink: $DEBIAN_SYMLINK -> $(basename "$OUTPUT_FILE")"
# Additional architecture-independent symlink for convenience
SIMPLE_SYMLINK="$PWD/rpi-imager-cli.AppImage"
if [ -L "$SIMPLE_SYMLINK" ] || [ -f "$SIMPLE_SYMLINK" ]; then
rm -f "$SIMPLE_SYMLINK"
fi
ln -s "$(basename "$OUTPUT_FILE")" "$SIMPLE_SYMLINK"
echo "Created symlink: $SIMPLE_SYMLINK -> $(basename "$OUTPUT_FILE")"
# Show size comparison if desktop AppImage exists
# Desktop AppImage uses GIT_VERSION and has -desktop- suffix
REGULAR_APPIMAGE="$PWD/Raspberry_Pi_Imager-${GIT_VERSION}-desktop-${ARCH}.AppImage"
if [ -f "$REGULAR_APPIMAGE" ]; then
CLI_SIZE=$(stat -f%z "$OUTPUT_FILE" 2>/dev/null || stat -c%s "$OUTPUT_FILE" 2>/dev/null || echo "unknown")
REGULAR_SIZE=$(stat -f%z "$REGULAR_APPIMAGE" 2>/dev/null || stat -c%s "$REGULAR_APPIMAGE" 2>/dev/null || echo "unknown")
if [ "$CLI_SIZE" != "unknown" ] && [ "$REGULAR_SIZE" != "unknown" ]; then
REDUCTION=$((100 - (CLI_SIZE * 100 / REGULAR_SIZE)))
echo "Size comparison:"
echo " CLI AppImage: $(( CLI_SIZE / 1024 / 1024 )) MB"
echo " Regular AppImage: $(( REGULAR_SIZE / 1024 / 1024 )) MB"
echo " Size reduction: ${REDUCTION}%"
fi
fi
echo ""
echo "CLI-only AppImage build completed successfully for $ARCH architecture."
echo ""
echo "This AppImage is optimized for CLI-only operation:"
echo " - Automatically forces CLI mode (no GUI)"
echo " - Minimal Qt dependencies (Core + Network only)"
echo " - No QML, GUI libraries, or graphics dependencies"
echo " - Perfect for headless/server environments"
echo ""
echo "Usage examples:"
echo " ./$(basename "$OUTPUT_FILE") image.img /dev/sdX"
echo " ./$(basename "$OUTPUT_FILE") --help"
echo " ./$(basename "$OUTPUT_FILE") --version"
else
echo "AppImage creation completed, but output file verification failed."
echo "Check the build process for any errors."
fi