|
| 1 | +#!/bin/bash |
| 2 | +# Build AppImage for imtools |
| 3 | +# Requirements: zig, appimagetool (or linuxdeploy) |
| 4 | +# |
| 5 | +# Usage: |
| 6 | +# ./build-appimage.sh |
| 7 | +# ./build-appimage.sh --arch aarch64 # Cross-compile for ARM64 |
| 8 | + |
| 9 | +set -e |
| 10 | + |
| 11 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 12 | +PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" |
| 13 | +BUILD_DIR="$PROJECT_ROOT/build-appimage" |
| 14 | +APPDIR="$BUILD_DIR/AppDir" |
| 15 | +VERSION="${VERSION:-1.0.0}" |
| 16 | +ARCH="${ARCH:-x86_64}" |
| 17 | + |
| 18 | +# Parse arguments |
| 19 | +while [[ $# -gt 0 ]]; do |
| 20 | + case $1 in |
| 21 | + --arch) |
| 22 | + ARCH="$2" |
| 23 | + shift 2 |
| 24 | + ;; |
| 25 | + *) |
| 26 | + echo "Unknown option: $1" |
| 27 | + exit 1 |
| 28 | + ;; |
| 29 | + esac |
| 30 | +done |
| 31 | + |
| 32 | +echo "Building imtools AppImage v${VERSION} for ${ARCH}" |
| 33 | + |
| 34 | +# Clean previous build |
| 35 | +rm -rf "$BUILD_DIR" |
| 36 | +mkdir -p "$APPDIR/usr/bin" |
| 37 | +mkdir -p "$APPDIR/usr/share/applications" |
| 38 | +mkdir -p "$APPDIR/usr/share/icons/hicolor/256x256/apps" |
| 39 | +mkdir -p "$APPDIR/usr/share/doc/imtools" |
| 40 | + |
| 41 | +# Build imtools |
| 42 | +cd "$PROJECT_ROOT" |
| 43 | +case $ARCH in |
| 44 | + x86_64) |
| 45 | + zig build -Doptimize=ReleaseSafe -Dtarget=x86_64-linux-musl |
| 46 | + ;; |
| 47 | + aarch64) |
| 48 | + zig build -Doptimize=ReleaseSafe -Dtarget=aarch64-linux-musl |
| 49 | + ;; |
| 50 | + *) |
| 51 | + echo "Unsupported architecture: $ARCH" |
| 52 | + exit 1 |
| 53 | + ;; |
| 54 | +esac |
| 55 | + |
| 56 | +# Copy binary |
| 57 | +cp zig-out/bin/imtools "$APPDIR/usr/bin/" |
| 58 | +chmod +x "$APPDIR/usr/bin/imtools" |
| 59 | + |
| 60 | +# Copy documentation |
| 61 | +cp README.md LICENSE "$APPDIR/usr/share/doc/imtools/" |
| 62 | +cp -r docs "$APPDIR/usr/share/doc/imtools/" |
| 63 | + |
| 64 | +# Create .desktop file |
| 65 | +cat > "$APPDIR/usr/share/applications/imtools.desktop" << 'EOF' |
| 66 | +[Desktop Entry] |
| 67 | +Type=Application |
| 68 | +Name=imtools |
| 69 | +GenericName=Image Tools |
| 70 | +Comment=Fast image manipulation CLI tool |
| 71 | +Exec=imtools %F |
| 72 | +Icon=imtools |
| 73 | +Categories=Graphics;Utility; |
| 74 | +Terminal=true |
| 75 | +MimeType=image/png;image/jpeg;image/gif;image/bmp;image/webp; |
| 76 | +Keywords=image;wallpaper;duplicate;convert;sort; |
| 77 | +EOF |
| 78 | + |
| 79 | +# Copy desktop file to AppDir root (required by AppImage) |
| 80 | +cp "$APPDIR/usr/share/applications/imtools.desktop" "$APPDIR/" |
| 81 | + |
| 82 | +# Create simple icon (placeholder - replace with actual icon) |
| 83 | +cat > "$APPDIR/usr/share/icons/hicolor/256x256/apps/imtools.svg" << 'EOF' |
| 84 | +<?xml version="1.0" encoding="UTF-8"?> |
| 85 | +<svg width="256" height="256" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg"> |
| 86 | + <rect width="256" height="256" rx="32" fill="#2d3748"/> |
| 87 | + <text x="128" y="160" font-family="monospace" font-size="120" font-weight="bold" fill="#48bb78" text-anchor="middle">im</text> |
| 88 | +</svg> |
| 89 | +EOF |
| 90 | + |
| 91 | +# Create symlink for icon at root |
| 92 | +ln -sf usr/share/icons/hicolor/256x256/apps/imtools.svg "$APPDIR/imtools.svg" |
| 93 | + |
| 94 | +# Create AppRun script |
| 95 | +cat > "$APPDIR/AppRun" << 'EOF' |
| 96 | +#!/bin/bash |
| 97 | +SELF=$(readlink -f "$0") |
| 98 | +HERE=${SELF%/*} |
| 99 | +export PATH="${HERE}/usr/bin:${PATH}" |
| 100 | +exec "${HERE}/usr/bin/imtools" "$@" |
| 101 | +EOF |
| 102 | +chmod +x "$APPDIR/AppRun" |
| 103 | + |
| 104 | +# Download appimagetool if not available |
| 105 | +APPIMAGETOOL="$BUILD_DIR/appimagetool" |
| 106 | +if ! command -v appimagetool &> /dev/null && [ ! -f "$APPIMAGETOOL" ]; then |
| 107 | + echo "Downloading appimagetool..." |
| 108 | + case $ARCH in |
| 109 | + x86_64) |
| 110 | + TOOL_ARCH="x86_64" |
| 111 | + ;; |
| 112 | + aarch64) |
| 113 | + TOOL_ARCH="aarch64" |
| 114 | + ;; |
| 115 | + esac |
| 116 | + wget -q "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-${TOOL_ARCH}.AppImage" -O "$APPIMAGETOOL" |
| 117 | + chmod +x "$APPIMAGETOOL" |
| 118 | +fi |
| 119 | + |
| 120 | +# Build AppImage |
| 121 | +cd "$BUILD_DIR" |
| 122 | +if command -v appimagetool &> /dev/null; then |
| 123 | + ARCH=$ARCH appimagetool AppDir "imtools-${VERSION}-${ARCH}.AppImage" |
| 124 | +else |
| 125 | + ARCH=$ARCH "$APPIMAGETOOL" AppDir "imtools-${VERSION}-${ARCH}.AppImage" |
| 126 | +fi |
| 127 | + |
| 128 | +echo "" |
| 129 | +echo "AppImage created: $BUILD_DIR/imtools-${VERSION}-${ARCH}.AppImage" |
| 130 | +echo "" |
| 131 | +echo "To test:" |
| 132 | +echo " chmod +x imtools-${VERSION}-${ARCH}.AppImage" |
| 133 | +echo " ./imtools-${VERSION}-${ARCH}.AppImage help" |
0 commit comments