Vectrum
Sign In
86 lines · 3.5 KB · Shell
#!/usr/bin/env bash
# Builds Vectrum Code in release mode and writes two artifacts to ./build:
#   build/vectrum-code                       plain binary
#   build/Vectrum_Code-<version>-<arch>.AppImage
#
# appimagetool is used from $PATH if present, otherwise downloaded once into
# build/.tools. Set APPIMAGETOOL=/path/to/appimagetool to use a specific one.
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD="$ROOT/build"
TOOLS="$BUILD/.tools"
APPDIR="$BUILD/AppDir"

NAME="vectrum-code"
PRETTY="Vectrum Code"
VERSION="$(sed -n 's/^version *= *"\(.*\)"/\1/p' "$ROOT/Cargo.toml" | head -n1)"
ARCH="$(uname -m)"

log() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }

# ── 1. Binary ────────────────────────────────────────────────────────────────
log "Building $NAME $VERSION (release, $ARCH)"
cargo build --release --manifest-path "$ROOT/Cargo.toml"

TARGET_DIR="$(cargo metadata --format-version 1 --no-deps --manifest-path "$ROOT/Cargo.toml" |
    sed -n 's/.*"target_directory":"\([^"]*\)".*/\1/p')"
mkdir -p "$BUILD"
install -m755 "$TARGET_DIR/release/$NAME" "$BUILD/$NAME"
log "Binary: build/$NAME"

# ── 2. AppDir ────────────────────────────────────────────────────────────────
rm -rf "$APPDIR"
mkdir -p "$APPDIR/usr/bin" \
         "$APPDIR/usr/share/applications" \
         "$APPDIR/usr/share/icons/hicolor/scalable/apps"

install -m755 "$BUILD/$NAME" "$APPDIR/usr/bin/$NAME"

cat > "$APPDIR/usr/share/applications/$NAME.desktop" <<EOF
[Desktop Entry]
Type=Application
Name=$PRETTY
Comment=A T3 Code-style GUI for Claude Code
Exec=$NAME
Icon=$NAME
Terminal=false
Categories=Development;IDE;
StartupWMClass=$NAME
EOF

install -m644 "$ROOT/assets/icons/$NAME.svg" "$APPDIR/usr/share/icons/hicolor/scalable/apps/$NAME.svg"

cat > "$APPDIR/AppRun" <<'EOF'
#!/bin/sh
HERE="$(dirname "$(readlink -f "$0")")"
exec "$HERE/usr/bin/vectrum-code" "$@"
EOF
chmod +x "$APPDIR/AppRun"

ln -sf "usr/share/applications/$NAME.desktop" "$APPDIR/$NAME.desktop"
ln -sf "usr/share/icons/hicolor/scalable/apps/$NAME.svg" "$APPDIR/$NAME.svg"
ln -sf "$NAME.svg" "$APPDIR/.DirIcon"

# ── 3. appimagetool ──────────────────────────────────────────────────────────
APPIMAGETOOL="${APPIMAGETOOL:-$(command -v appimagetool || true)}"
if [[ -z "$APPIMAGETOOL" ]]; then
    APPIMAGETOOL="$TOOLS/appimagetool-$ARCH.AppImage"
    if [[ ! -x "$APPIMAGETOOL" ]]; then
        log "Downloading appimagetool"
        mkdir -p "$TOOLS"
        curl -fL --progress-bar -o "$APPIMAGETOOL.part" \
            "https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-$ARCH.AppImage"
        chmod +x "$APPIMAGETOOL.part"
        mv "$APPIMAGETOOL.part" "$APPIMAGETOOL"
    fi
fi

# ── 4. AppImage ──────────────────────────────────────────────────────────────
OUT="$BUILD/${PRETTY// /_}-$VERSION-$ARCH.AppImage"
log "Packaging AppImage"
# Extract-and-run so this works on systems without FUSE (containers, CI).
APPIMAGE_EXTRACT_AND_RUN=1 ARCH="$ARCH" "$APPIMAGETOOL" --no-appstream "$APPDIR" "$OUT"
rm -rf "$APPDIR"

log "AppImage: ${OUT#"$ROOT"/}"