Files
tongtong a0b77a3e7a feat(installer): 增加 Windows 和 Linux 安装包脚本
- 增加 Inno Setup 安装器及运行库安装支持
- 增加 deb、rpm、AppImage 打包与完整 Release 目录校验
- 修复 WSL 打包权限和安装路径,补充构建说明及换行规则
2026-11-28 02:50:41 +08:00

125 lines
5.8 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
FORMAT=all
BUNDLE=""
VERSION="$(sed -nE 's/^version: ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' "$ROOT/flutter_sender/pubspec.yaml")"
usage() { echo "Usage: bash installer/linux/package.sh [--format all|deb|rpm|appimage] [--bundle RELEASE_BUNDLE] [--version X.Y.Z]"; }
while (($#)); do
case "$1" in
--format|--bundle|--version)
(($# >= 2)) || { usage; exit 2; }
case "$1" in --format) FORMAT="$2";; --bundle) BUNDLE="$2";; --version) VERSION="$2";; esac
shift 2;;
-h|--help) usage; exit 0;;
*) usage; exit 2;;
esac
done
[[ "$FORMAT" =~ ^(all|deb|rpm|appimage)$ ]] || { usage; exit 2; }
[[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo 'Invalid version' >&2; exit 2; }
[[ "$(uname -s)" == Linux && "$(uname -m)" == x86_64 ]] || { echo 'Linux x86_64 required' >&2; exit 1; }
need() { command -v "$1" >/dev/null || { echo "Required tool missing: $1" >&2; exit 1; }; }
need file
if [[ "$FORMAT" == all || "$FORMAT" == deb ]]; then need dpkg-deb; fi
if [[ "$FORMAT" == all || "$FORMAT" == rpm ]]; then need rpmbuild; fi
APPIMAGETOOL="${APPIMAGETOOL:-appimagetool}"
if [[ "$FORMAT" == all || "$FORMAT" == appimage ]]; then need "$APPIMAGETOOL"; fi
mkdir -p "$ROOT/dist/linux"
WORK="$(mktemp -d "${TMPDIR:-/tmp}/ttstdconnect-package.XXXXXX")"
# Use the Linux filesystem: WSL /mnt drives may expose every directory as 0777,
# which dpkg-deb rejects even after chmod. Keep staging for inspection.
echo "Staging: $WORK"
if [[ -z "$BUNDLE" ]]; then
for tool in cargo flutter dart go cmake; do need "$tool"; done
export CARGO_TARGET_DIR="$ROOT/rust_core/target/linux-package"
(cd "$ROOT/rust_core" && cargo check --offline && cargo test --offline --lib && cargo build --release --offline)
(cd "$ROOT/flutter_sender" && flutter pub get && dart analyze lib &&
flutter build linux --release --no-pub --config-only &&
cmake -S linux -B build/linux/x64/release -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$ROOT/flutter_sender/build/linux/x64/release/bundle" &&
flutter build linux --release --no-pub)
BUNDLE="$WORK/bundle"
mkdir -p "$BUNDLE"
cp -a "$ROOT/flutter_sender/build/linux/x64/release/bundle/." "$BUNDLE/"
cp "$CARGO_TARGET_DIR/release/libttstdconnect_core.so" "$BUNDLE/"
(cd "$ROOT/signaling_server" && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "$BUNDLE/signaling_server" .)
fi
BUNDLE="$(cd "$BUNDLE" && pwd)"
for item in ttstd_sender libttstdconnect_core.so signaling_server lib/libflutter_linux_gtk.so lib/libapp.so data/flutter_assets; do
[[ -e "$BUNDLE/$item" ]] || { echo "Incomplete Release bundle: $item" >&2; exit 1; }
done
for binary in ttstd_sender libttstdconnect_core.so signaling_server; do
file "$BUNDLE/$binary" | grep -q 'ELF 64-bit.*x86-64' || { echo "Not Linux x86_64: $binary" >&2; exit 1; }
done
APPDIR="$WORK/AppDir"
mkdir -p "$APPDIR/opt/ttstdconnect" "$APPDIR/usr/bin" "$APPDIR/usr/share/applications" "$APPDIR/usr/share/icons/hicolor/256x256/apps"
cp -a "$BUNDLE/." "$APPDIR/opt/ttstdconnect/"
chmod 755 "$APPDIR/opt/ttstdconnect/ttstd_sender" "$APPDIR/opt/ttstdconnect/signaling_server"
ln -s ../../opt/ttstdconnect/ttstd_sender "$APPDIR/usr/bin/ttstdconnect"
cp "$ROOT/installer/linux/ttstdconnect.desktop" "$APPDIR/usr/share/applications/"
cp "$ROOT/flutter_sender/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png" "$APPDIR/usr/share/icons/hicolor/256x256/apps/ttstdconnect.png"
find "$APPDIR" -type d -exec chmod 755 {} +
find "$APPDIR" -type f -exec chmod 644 {} +
chmod 755 "$APPDIR/opt/ttstdconnect/ttstd_sender" "$APPDIR/opt/ttstdconnect/signaling_server"
OUT="$ROOT/dist/linux"
GLIBC_VERSION="$(getconf GNU_LIBC_VERSION | awk '{print $2}')"
if [[ "$FORMAT" == all || "$FORMAT" == deb ]]; then
DEB="$WORK/deb"
mkdir -p "$DEB/DEBIAN"
chmod 755 "$DEB/DEBIAN"
cp -a "$APPDIR/." "$DEB/"
cat > "$DEB/DEBIAN/control" <<EOF
Package: ttstdconnect
Version: $VERSION
Section: net
Priority: optional
Architecture: amd64
Maintainer: TTSTD <maintainer@ttstd.invalid>
Depends: libgtk-3-0, libglib2.0-0, libstdc++6, libc6 (>= $GLIBC_VERSION), libgcc-s1
Description: TTSTDConnect desktop sender
Flutter desktop client with Rust core and local signaling server.
EOF
dpkg-deb --build --root-owner-group "$DEB" "$OUT/ttstdconnect_${VERSION}_amd64.deb"
fi
if [[ "$FORMAT" == all || "$FORMAT" == rpm ]]; then
RPM="$WORK/rpm"
mkdir -p "$RPM"/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
cat > "$RPM/SPECS/ttstdconnect.spec" <<EOF
Name: ttstdconnect
Version: $VERSION
Release: 1
Summary: TTSTDConnect desktop sender
License: Proprietary
BuildArch: x86_64
Requires: gtk3, glib2, libstdc++, glibc >= $GLIBC_VERSION
%description
Flutter desktop client with Rust core and local signaling server.
%prep
%build
%install
mkdir -p %{buildroot}
cp -a "$APPDIR/." %{buildroot}/
%files
%defattr(-,root,root,-)
/opt/ttstdconnect
/usr/bin/ttstdconnect
/usr/share/applications/ttstdconnect.desktop
/usr/share/icons/hicolor/256x256/apps/ttstdconnect.png
EOF
rpmbuild -bb --define "_topdir $RPM" --define '_build_id_links none' --define 'debug_package %{nil}' "$RPM/SPECS/ttstdconnect.spec"
cp "$RPM/RPMS/x86_64/ttstdconnect-$VERSION-1.x86_64.rpm" "$OUT/"
fi
if [[ "$FORMAT" == all || "$FORMAT" == appimage ]]; then
cp "$ROOT/installer/linux/ttstdconnect.desktop" "$APPDIR/"
cp "$APPDIR/usr/share/icons/hicolor/256x256/apps/ttstdconnect.png" "$APPDIR/"
cat > "$APPDIR/AppRun" <<'EOF'
#!/bin/sh
APPDIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
export LD_LIBRARY_PATH="$APPDIR/opt/ttstdconnect/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
exec "$APPDIR/opt/ttstdconnect/ttstd_sender" "$@"
EOF
chmod 755 "$APPDIR/AppRun"
ARCH=x86_64 "$APPIMAGETOOL" "$APPDIR" "$OUT/TTSTDConnect-$VERSION-x86_64.AppImage"
fi
echo "Packages: $OUT"