160 lines
3.8 KiB
Bash
Executable File
160 lines
3.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
APP_DIR="$REPO_ROOT/apps/chanora_flutter"
|
|
PUBSPEC="$APP_DIR/pubspec.yaml"
|
|
OBOE_DIR="$(cd "$REPO_ROOT/.." && pwd)/oboe-rs"
|
|
DIST_DIR="$REPO_ROOT/dist/linux"
|
|
STAGE_DIR="$(mktemp -d "${TMPDIR:-/tmp}/chanora-linux-deb.XXXXXX")"
|
|
PKG_ROOT="$STAGE_DIR/package"
|
|
INSTALL_ROOT="$PKG_ROOT/opt/chanora"
|
|
ICON_SRC="$APP_DIR/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png"
|
|
|
|
cleanup() {
|
|
rm -rf "$STAGE_DIR"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
require_cmd() {
|
|
local cmd=$1
|
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
|
echo "ERROR: required command '$cmd' is not on PATH." >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
require_file() {
|
|
local path=$1
|
|
local label=$2
|
|
if [[ ! -f "$path" ]]; then
|
|
echo "ERROR: missing $label at $path" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
resolve_arch() {
|
|
if command -v dpkg >/dev/null 2>&1; then
|
|
dpkg --print-architecture
|
|
return
|
|
fi
|
|
|
|
case "$(uname -m)" in
|
|
x86_64) echo "amd64" ;;
|
|
aarch64 | arm64) echo "arm64" ;;
|
|
*)
|
|
echo "ERROR: unsupported Linux architecture '$(uname -m)'" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
flutter_linux_arch() {
|
|
case "$1" in
|
|
amd64) echo "x64" ;;
|
|
arm64) echo "arm64" ;;
|
|
*)
|
|
echo "ERROR: unsupported Flutter Linux architecture '$1'" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
main() {
|
|
require_cmd flutter
|
|
require_cmd dpkg-deb
|
|
require_file "$PUBSPEC" "Flutter pubspec"
|
|
require_file "$ICON_SRC" "launcher icon"
|
|
|
|
if [[ ! -f "$OBOE_DIR/Cargo.toml" ]]; then
|
|
cat >&2 <<EOF
|
|
ERROR: missing sibling oboe-rs checkout at:
|
|
$OBOE_DIR
|
|
|
|
This repository's Android-targeted Rust manifest currently depends on a local
|
|
oboe-rs fork, so Cargo manifest loading fails until that sibling checkout
|
|
exists. Clone it before running this script:
|
|
|
|
git clone https://github.com/edisonjwa/oboe-rs.git "$OBOE_DIR"
|
|
EOF
|
|
exit 1
|
|
fi
|
|
|
|
local app_version
|
|
app_version="$(sed -n 's/^version:[[:space:]]*//p' "$PUBSPEC" | head -n1)"
|
|
if [[ -z "$app_version" ]]; then
|
|
echo "ERROR: could not read version from $PUBSPEC" >&2
|
|
exit 1
|
|
fi
|
|
|
|
local deb_version
|
|
deb_version="${app_version/-/~}"
|
|
|
|
local arch
|
|
arch="$(resolve_arch)"
|
|
local flutter_arch
|
|
flutter_arch="$(flutter_linux_arch "$arch")"
|
|
|
|
(
|
|
cd "$APP_DIR"
|
|
flutter pub get
|
|
flutter build linux --release
|
|
)
|
|
|
|
local bundle_dir="$APP_DIR/build/linux/$flutter_arch/release/bundle"
|
|
local app_binary="$bundle_dir/chanora_flutter"
|
|
require_file "$app_binary" "Linux release bundle binary"
|
|
|
|
mkdir -p \
|
|
"$PKG_ROOT/DEBIAN" \
|
|
"$INSTALL_ROOT" \
|
|
"$PKG_ROOT/usr/bin" \
|
|
"$PKG_ROOT/usr/share/applications" \
|
|
"$PKG_ROOT/usr/share/icons/hicolor/256x256/apps"
|
|
|
|
cp -R "$bundle_dir/." "$INSTALL_ROOT/"
|
|
|
|
cat >"$PKG_ROOT/DEBIAN/control" <<EOF
|
|
Package: chanora
|
|
Version: $deb_version
|
|
Section: net
|
|
Priority: optional
|
|
Architecture: $arch
|
|
Maintainer: Chanora Project Contributors
|
|
Depends: libasound2, libgtk-3-0, libpulse0, libsdl2-2.0-0, libstdc++6
|
|
Description: Chanora voice client for TeamSpeak-compatible servers
|
|
Chanora is a Flutter + Rust voice client for TeamSpeak-compatible servers.
|
|
EOF
|
|
|
|
cat >"$PKG_ROOT/usr/bin/chanora" <<'EOF'
|
|
#!/bin/sh
|
|
exec /opt/chanora/chanora_flutter "$@"
|
|
EOF
|
|
chmod 0755 "$PKG_ROOT/usr/bin/chanora"
|
|
|
|
cat >"$PKG_ROOT/usr/share/applications/chanora.desktop" <<'EOF'
|
|
[Desktop Entry]
|
|
Type=Application
|
|
Name=Chanora
|
|
GenericName=Voice Client
|
|
Comment=Voice client for TeamSpeak-compatible servers
|
|
Exec=/usr/bin/chanora
|
|
Icon=chanora
|
|
Terminal=false
|
|
Categories=Network;Chat;AudioVideo;
|
|
StartupNotify=true
|
|
EOF
|
|
|
|
cp "$ICON_SRC" "$PKG_ROOT/usr/share/icons/hicolor/256x256/apps/chanora.png"
|
|
|
|
mkdir -p "$DIST_DIR"
|
|
local output="$DIST_DIR/chanora_${deb_version}_${arch}.deb"
|
|
dpkg-deb --build --root-owner-group "$PKG_ROOT" "$output" >/dev/null
|
|
|
|
printf 'Built Linux package: %s\n' "$output"
|
|
}
|
|
|
|
main "$@"
|