Files
pixstrip/build-appimage.sh

106 lines
3.6 KiB
Bash

#!/bin/bash
set -euo pipefail
# Build Pixstrip AppImage
# Requires: cargo, linuxdeploy (with gtk plugin), appimagetool
# Usage: ./build-appimage.sh [--release]
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
BUILD_TYPE="release"
CARGO_FLAGS="--release"
if [[ "${1:-}" == "--debug" ]]; then
BUILD_TYPE="debug"
CARGO_FLAGS=""
fi
APP_ID="live.lashman.Pixstrip"
APP_DIR="$SCRIPT_DIR/AppDir"
TOOLS_DIR="$SCRIPT_DIR/build-tools"
echo "=== Building Pixstrip AppImage ($BUILD_TYPE) ==="
# Step 1: Build binaries
echo "--- Building binaries ---"
cargo build $CARGO_FLAGS --workspace
# Step 2: Create AppDir structure
echo "--- Creating AppDir ---"
rm -rf "$APP_DIR"
mkdir -p "$APP_DIR/usr/bin"
mkdir -p "$APP_DIR/usr/share/applications"
mkdir -p "$APP_DIR/usr/share/icons/hicolor/scalable/apps"
mkdir -p "$APP_DIR/usr/share/metainfo"
# Step 3: Copy binaries
cp "target/$BUILD_TYPE/pixstrip-gtk" "$APP_DIR/usr/bin/pixstrip-gtk"
cp "target/$BUILD_TYPE/pixstrip-cli" "$APP_DIR/usr/bin/pixstrip"
# Step 4: Copy desktop file, icon, metainfo
cp "data/$APP_ID.desktop" "$APP_DIR/usr/share/applications/"
cp "data/icons/hicolor/scalable/apps/$APP_ID.svg" "$APP_DIR/usr/share/icons/hicolor/scalable/apps/"
cp "data/$APP_ID.metainfo.xml" "$APP_DIR/usr/share/metainfo/"
# Symlinks required by AppImage spec
ln -sf "usr/share/applications/$APP_ID.desktop" "$APP_DIR/$APP_ID.desktop"
ln -sf "usr/share/icons/hicolor/scalable/apps/$APP_ID.svg" "$APP_DIR/$APP_ID.svg"
# Step 5: Create AppRun
cat > "$APP_DIR/AppRun" << 'APPRUN'
#!/bin/bash
SELF="$(readlink -f "$0")"
HERE="${SELF%/*}"
export PATH="${HERE}/usr/bin:${PATH}"
export LD_LIBRARY_PATH="${HERE}/usr/lib:${HERE}/usr/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH:-}"
export XDG_DATA_DIRS="${HERE}/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
export GI_TYPELIB_PATH="${HERE}/usr/lib/x86_64-linux-gnu/girepository-1.0:${GI_TYPELIB_PATH:-}"
exec "${HERE}/usr/bin/pixstrip-gtk" "$@"
APPRUN
chmod +x "$APP_DIR/AppRun"
# Step 6: Bundle shared libraries
echo "--- Bundling libraries ---"
mkdir -p "$TOOLS_DIR"
# Download linuxdeploy if not present
if [[ ! -x "$TOOLS_DIR/linuxdeploy" ]]; then
echo "Downloading linuxdeploy..."
wget -q -O "$TOOLS_DIR/linuxdeploy" \
"https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage"
chmod +x "$TOOLS_DIR/linuxdeploy"
fi
# Download linuxdeploy GTK plugin if not present
if [[ ! -x "$TOOLS_DIR/linuxdeploy-plugin-gtk.sh" ]]; then
echo "Downloading linuxdeploy GTK plugin..."
wget -q -O "$TOOLS_DIR/linuxdeploy-plugin-gtk.sh" \
"https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh"
chmod +x "$TOOLS_DIR/linuxdeploy-plugin-gtk.sh"
fi
# Use linuxdeploy to bundle dependencies
export DEPLOY_GTK_VERSION=4
"$TOOLS_DIR/linuxdeploy" \
--appdir "$APP_DIR" \
--desktop-file "$APP_DIR/usr/share/applications/$APP_ID.desktop" \
--icon-file "$APP_DIR/usr/share/icons/hicolor/scalable/apps/$APP_ID.svg" \
--plugin gtk
# Step 7: Build the AppImage
echo "--- Creating AppImage ---"
# Download appimagetool if not present
if [[ ! -x "$TOOLS_DIR/appimagetool" ]]; then
echo "Downloading appimagetool..."
wget -q -O "$TOOLS_DIR/appimagetool" \
"https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage"
chmod +x "$TOOLS_DIR/appimagetool"
fi
VERSION="0.1.0"
"$TOOLS_DIR/appimagetool" "$APP_DIR" "Pixstrip-${VERSION}-x86_64.AppImage"
echo ""
echo "=== AppImage built: Pixstrip-${VERSION}-x86_64.AppImage ==="
echo "Size: $(du -h "Pixstrip-${VERSION}-x86_64.AppImage" | cut -f1)"