|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Build Linux packages locally: AppImage, .deb, .rpm |
| 3 | +# Run from repo root: ./linux/packaging/build.sh |
| 4 | +# Requires: flutter, patchelf. Optional: appimagetool (or downloaded), fpm and/or dpkg for packages. |
| 5 | + |
| 6 | +set -e |
| 7 | +cd "$(dirname "$0")/../.." |
| 8 | +REPO_ROOT="$PWD" |
| 9 | + |
| 10 | +if ! command -v patchelf &>/dev/null; then |
| 11 | + echo "patchelf is required. Install it:" |
| 12 | + echo " Fedora: sudo dnf install patchelf" |
| 13 | + echo " Debian/Ubuntu: sudo apt install patchelf" |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +# Optional: skip Flutter build and use existing bundle (e.g. after "flutter build linux") |
| 18 | +SKIP_FLUTTER_BUILD=false |
| 19 | +[ "${1:-}" = "--no-flutter-build" ] || [ "${1:-}" = "-n" ] && SKIP_FLUTTER_BUILD=true |
| 20 | + |
| 21 | +# Version from pubspec.yaml |
| 22 | +VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: *//;s/+.*//;s/ *$//') |
| 23 | +echo "Building Echo $VERSION" |
| 24 | + |
| 25 | +BUNDLE="$REPO_ROOT/build/linux/x64/release/bundle" |
| 26 | +if [ "$SKIP_FLUTTER_BUILD" = true ]; then |
| 27 | + if [ ! -x "$BUNDLE/echo" ]; then |
| 28 | + echo "Bundle not found. Run: flutter build linux" |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | + echo "Using existing bundle (skip Flutter build)" |
| 32 | +else |
| 33 | + flutter pub get |
| 34 | + flutter build linux --release |
| 35 | +fi |
| 36 | +# Flutter Linux engine looks for lib/ and data/ in the executable's directory |
| 37 | +# (executable_dir/lib/libapp.so, executable_dir/data/flutter_assets). So we put |
| 38 | +# lib and data under usr/bin/ for both AppImage and .deb/.rpm. |
| 39 | +STAGING="$REPO_ROOT/build/linux_pkg_staging" |
| 40 | +rm -rf "$STAGING" |
| 41 | +mkdir -p "$STAGING/usr/bin/lib" "$STAGING/usr/bin/data" |
| 42 | + |
| 43 | +# --- Staging: binary, libs, data (all under usr/bin so engine finds them) --- |
| 44 | +cp "$BUNDLE/echo" "$STAGING/usr/bin/echo" |
| 45 | +cp -a "$BUNDLE/lib/"* "$STAGING/usr/bin/lib/" 2>/dev/null || true |
| 46 | +cp -a "$BUNDLE/data/"* "$STAGING/usr/bin/data/" |
| 47 | + |
| 48 | +# Bundle libmpv and libmimalloc (so users don't need to install them) |
| 49 | +ARCH=$(uname -m) |
| 50 | +for lib in libmpv libmimalloc; do |
| 51 | + for dir in /usr/lib64 /usr/lib/$ARCH-linux-gnu /usr/lib; do |
| 52 | + for f in "$dir"/$lib.so*; do |
| 53 | + [ -e "$f" ] && cp -P "$f" "$STAGING/usr/bin/lib/" && break 2 |
| 54 | + done |
| 55 | + done |
| 56 | +done |
| 57 | + |
| 58 | +patchelf --set-rpath '$ORIGIN/lib' "$STAGING/usr/bin/echo" |
| 59 | +chmod +x "$STAGING/usr/bin/echo" |
| 60 | + |
| 61 | +# .deb/.rpm: same layout, binary named echo-music to avoid conflict with coreutils |
| 62 | +PKG_STAGING="$REPO_ROOT/build/linux_pkg_staging_named" |
| 63 | +rm -rf "$PKG_STAGING" |
| 64 | +mkdir -p "$PKG_STAGING/usr/bin/lib" "$PKG_STAGING/usr/bin/data" \ |
| 65 | + "$PKG_STAGING/usr/share/applications" "$PKG_STAGING/usr/share/icons/hicolor/256x256/apps" |
| 66 | +cp "$STAGING/usr/bin/echo" "$PKG_STAGING/usr/bin/echo-music" |
| 67 | +cp -a "$STAGING/usr/bin/lib/"* "$PKG_STAGING/usr/bin/lib/" |
| 68 | +cp -a "$STAGING/usr/bin/data/"* "$PKG_STAGING/usr/bin/data/" |
| 69 | +cp "$REPO_ROOT/icons/Echo_nobg.png" "$PKG_STAGING/usr/share/icons/hicolor/256x256/apps/echo.png" |
| 70 | +cp "$REPO_ROOT/linux/packaging/echo-music.desktop" "$PKG_STAGING/usr/share/applications/echo-music.desktop" |
| 71 | +patchelf --set-rpath '$ORIGIN/lib' "$PKG_STAGING/usr/bin/echo-music" |
| 72 | +chmod +x "$PKG_STAGING/usr/bin/echo-music" |
| 73 | + |
| 74 | +echo "Staging ready at $STAGING" |
| 75 | + |
| 76 | +# --- AppImage --- |
| 77 | +APPDIR="$REPO_ROOT/build/Echo.AppDir" |
| 78 | +rm -rf "$APPDIR" |
| 79 | +mkdir -p "$APPDIR/usr" "$APPDIR/usr/share/icons/hicolor/256x256/apps" |
| 80 | +cp -a "$STAGING/usr/bin" "$APPDIR/usr/" |
| 81 | +cp "$REPO_ROOT/icons/Echo_nobg.png" "$APPDIR/usr/share/icons/hicolor/256x256/apps/echo.png" |
| 82 | +cp "$REPO_ROOT/icons/Echo_nobg.png" "$APPDIR/echo.png" |
| 83 | +cp "$REPO_ROOT/linux/packaging/echo.desktop" "$APPDIR/echo.desktop" |
| 84 | +cp "$REPO_ROOT/linux/packaging/AppRun" "$APPDIR/AppRun" |
| 85 | +chmod +x "$APPDIR/AppRun" |
| 86 | + |
| 87 | +APPIMAGETOOL="" |
| 88 | +if command -v appimagetool &>/dev/null; then |
| 89 | + APPIMAGETOOL=appimagetool |
| 90 | +elif [ -x "$REPO_ROOT/build/appimagetool.AppImage" ]; then |
| 91 | + APPIMAGETOOL="$REPO_ROOT/build/appimagetool.AppImage" |
| 92 | +else |
| 93 | + echo "Downloading appimagetool..." |
| 94 | + curl -sL -o "$REPO_ROOT/build/appimagetool.AppImage" \ |
| 95 | + "https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage" |
| 96 | + chmod +x "$REPO_ROOT/build/appimagetool.AppImage" |
| 97 | + APPIMAGETOOL="$REPO_ROOT/build/appimagetool.AppImage" |
| 98 | +fi |
| 99 | +ARCH=x86_64 "$APPIMAGETOOL" -n "$APPDIR" "$REPO_ROOT/build/Echo-${VERSION}-x86_64.AppImage" |
| 100 | +echo "Built: build/Echo-${VERSION}-x86_64.AppImage" |
| 101 | + |
| 102 | +# --- .deb --- |
| 103 | +if command -v dpkg-deb &>/dev/null; then |
| 104 | + PKG="$REPO_ROOT/build/echo-music_${VERSION}_amd64" |
| 105 | + rm -rf "$PKG" |
| 106 | + mkdir -p "$PKG/DEBIAN" "$PKG/usr/share/applications" "$PKG/usr/share/icons/hicolor/256x256/apps" |
| 107 | + cp -a "$PKG_STAGING/usr/bin" "$PKG/usr/" |
| 108 | + cp "$REPO_ROOT/icons/Echo_nobg.png" "$PKG/usr/share/icons/hicolor/256x256/apps/echo.png" |
| 109 | + cp "$REPO_ROOT/linux/packaging/echo-music.desktop" "$PKG/usr/share/applications/echo-music.desktop" |
| 110 | + sed "s/VERSION/$VERSION/" "$REPO_ROOT/linux/packaging/control.in" > "$PKG/DEBIAN/control" |
| 111 | + dpkg-deb --root-owner-group --build "$PKG" "$REPO_ROOT/build/echo-music_${VERSION}_amd64.deb" |
| 112 | + rm -rf "$PKG" |
| 113 | + echo "Built: build/echo-music_${VERSION}_amd64.deb" |
| 114 | +elif command -v fpm &>/dev/null; then |
| 115 | + fpm -s dir -t deb -n echo-music -v "$VERSION" \ |
| 116 | + --architecture amd64 \ |
| 117 | + --description "Echo Music Desktop - Music player" \ |
| 118 | + -C "$PKG_STAGING" usr |
| 119 | + mv "echo-music_${VERSION}_amd64.deb" "$REPO_ROOT/build/" |
| 120 | + echo "Built: build/echo-music_${VERSION}_amd64.deb" |
| 121 | +else |
| 122 | + echo "Skip .deb: install dpkg or fpm (gem install fpm)" |
| 123 | +fi |
| 124 | + |
| 125 | +# --- .rpm --- |
| 126 | +if command -v fpm &>/dev/null; then |
| 127 | + fpm -s dir -t rpm -n echo-music -v "$VERSION" \ |
| 128 | + --architecture x86_64 \ |
| 129 | + --description "Echo Music Desktop - Music player" \ |
| 130 | + -C "$PKG_STAGING" usr |
| 131 | + mv "$REPO_ROOT/echo-music-${VERSION}-1.x86_64.rpm" "$REPO_ROOT/build/echo-music_${VERSION}_x86_64.rpm" |
| 132 | + echo "Built: build/echo-music_${VERSION}_x86_64.rpm" |
| 133 | +else |
| 134 | + echo "Skip .rpm: install fpm (gem install fpm)" |
| 135 | +fi |
| 136 | + |
| 137 | +echo "Done. Outputs in build/" |
0 commit comments