#!/bin/bash set -euo pipefail usage() { echo "Usage: $0 GUI.AppImage-or-AppDir SERVER_BINARY SERVER_DB_MODE OUTPUT.AppImage" >&2 } if [[ $# -ne 4 ]]; then usage exit 2 fi script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" gui_bundle="$(realpath -- "$1")" server_binary="$(realpath -- "$2")" server_db_mode="$3" output_parent="$(dirname -- "$4")" mkdir -p "$output_parent" output="$(cd -- "$output_parent" && pwd)/$(basename -- "$4")" if [[ "$server_db_mode" != embedded && "$server_db_mode" != external ]]; then echo "SERVER_DB_MODE must be embedded or external, got: $server_db_mode" >&2 exit 2 fi if [[ ! -d "$gui_bundle" && ! -x "$gui_bundle" ]]; then echo "GUI bundle is neither an AppDir nor an executable AppImage: $gui_bundle" >&2 exit 1 fi if [[ ! -x "$server_binary" ]]; then echo "Server binary is not executable: $server_binary" >&2 exit 1 fi work_dir="$(mktemp -d /tmp/komp-ac-appimage.XXXXXX)" cleanup() { case "$work_dir" in /tmp/komp-ac-appimage.*) rm -rf -- "$work_dir" ;; *) echo "Refusing to remove unexpected temporary directory: $work_dir" >&2 ;; esac } trap cleanup EXIT INT TERM HUP app_dir="$work_dir/squashfs-root" if [[ -d "$gui_bundle" ]]; then mkdir "$app_dir" cp -a -- "$gui_bundle/." "$app_dir/" else ( cd -- "$work_dir" "$gui_bundle" --appimage-extract >/dev/null ) fi if [[ ! -e "$app_dir/AppRun" ]]; then echo "The GUI AppImage did not contain an AppRun entry point" >&2 exit 1 fi mv -- "$app_dir/AppRun" "$app_dir/AppRun.gui" install -Dm755 "$script_dir/AppRun" "$app_dir/AppRun" install -Dm755 "$server_binary" "$app_dir/usr/bin/komp-ac-server" install -d "$app_dir/usr/share/komp-ac" printf '%s\n' "$server_db_mode" > "$app_dir/usr/share/komp-ac/server-db-mode" # Tauri names the root icon after productName (`komp_ac.png`) while its desktop # entry names the Rust binary (`Icon=client-gui2`). AppImage packers require the # desktop icon name to resolve at the AppDir root. if [[ -f "$app_dir/komp_ac.png" && ! -e "$app_dir/client-gui2.png" ]]; then ln -s komp_ac.png "$app_dir/client-gui2.png" fi if [[ -n "${APPIMAGETOOL:-}" ]]; then ARCH=x86_64 "$APPIMAGETOOL" "$app_dir" "$output" elif command -v appimagetool >/dev/null 2>&1; then ARCH=x86_64 appimagetool "$app_dir" "$output" else cache_home="${XDG_CACHE_HOME:-${HOME:?HOME is not set}/.cache}" appimage_plugin="$cache_home/tauri/linuxdeploy-plugin-appimage.AppImage" if [[ ! -x "$appimage_plugin" ]]; then echo "No AppImage packer found; set APPIMAGETOOL to appimagetool's executable path" >&2 exit 1 fi ARCH=x86_64 \ LDAI_NO_APPSTREAM=1 \ LDAI_OUTPUT="$output" \ "$appimage_plugin" --appimage-extract-and-run --appdir="$app_dir" fi echo "Created $output"