144 lines
5.3 KiB
Bash
Executable File
144 lines
5.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Builds Linux release packages into target/release/bundle/.
|
|
# tool/bundle-linux.sh # tarball, .deb and AppImage
|
|
# tool/bundle-linux.sh tar deb # only the formats named (tar, deb, appimage)
|
|
# tool/bundle-linux.sh --install # build, then install into ~/.local
|
|
# The Arch package lives in packaging/arch (makepkg there).
|
|
# The AppImage needs appimagetool on PATH, or APPIMAGETOOL pointing at it.
|
|
# Binaries need the glibc they were built against or newer, so build releases on the
|
|
# oldest distro you want to support (Ubuntu 22.04 covers most desktops).
|
|
set -euo pipefail
|
|
|
|
root="$(cd "$(dirname "$0")/.." && pwd)"
|
|
cd "$root"
|
|
|
|
formats=()
|
|
install=0
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
tar | deb | appimage) formats+=("$arg") ;;
|
|
--install) install=1 ;;
|
|
*) echo "unknown argument: $arg" >&2; exit 2 ;;
|
|
esac
|
|
done
|
|
if [[ ${#formats[@]} -eq 0 && $install -eq 0 ]]; then
|
|
formats=(tar deb appimage)
|
|
fi
|
|
|
|
app_id="it.panov.musyx.desktop"
|
|
version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)"
|
|
arch="$(uname -m)"
|
|
case "$arch" in
|
|
x86_64) deb_arch=amd64 ;;
|
|
aarch64) deb_arch=arm64 ;;
|
|
*) deb_arch="$arch" ;;
|
|
esac
|
|
out="target/release/bundle"
|
|
work="$(mktemp -d)"
|
|
trap 'rm -rf "$work"' EXIT
|
|
|
|
cargo build --release -p musyx
|
|
|
|
# The installed layout, rooted at $1 (a prefix such as /usr): binary, desktop entry,
|
|
# AppStream metadata, hicolor icons and licences.
|
|
stage() {
|
|
local dest="$1"
|
|
install -Dm755 target/release/musyx "$dest/bin/musyx"
|
|
install -Dm644 "packaging/linux/$app_id.desktop" "$dest/share/applications/$app_id.desktop"
|
|
install -Dm644 "packaging/linux/$app_id.metainfo.xml" "$dest/share/metainfo/$app_id.metainfo.xml"
|
|
for size in 16 32 48 64 128 256 512; do
|
|
mkdir -p "$dest/share/icons/hicolor/${size}x${size}/apps"
|
|
magick crates/musyx/assets/icon/musyx.png -resize "${size}x${size}" \
|
|
"$dest/share/icons/hicolor/${size}x${size}/apps/$app_id.png"
|
|
done
|
|
local doc="$dest/share/doc/musyx"
|
|
install -Dm644 LICENSE "$doc/LICENSE"
|
|
install -Dm644 README.md "$doc/README.md"
|
|
install -Dm644 crates/musyx/assets/fonts/OFL-*.txt -t "$doc"
|
|
install -Dm644 crates/musyx/assets/icons/LICENSE.txt "$doc/LICENSE-lucide.txt"
|
|
}
|
|
|
|
mkdir -p "$out"
|
|
|
|
if [[ $install -eq 1 ]]; then
|
|
prefix="${PREFIX:-$HOME/.local}"
|
|
stage "$prefix"
|
|
update-desktop-database "$prefix/share/applications" 2>/dev/null || true
|
|
gtk-update-icon-cache -q -t "$prefix/share/icons/hicolor" 2>/dev/null || true
|
|
echo "Installed musyx $version into $prefix"
|
|
fi
|
|
|
|
for format in "${formats[@]}"; do
|
|
case "$format" in
|
|
tar)
|
|
# Unpack anywhere and run ./install.sh (to ~/.local, or PREFIX=/usr/local with sudo).
|
|
name="musyx-$version-linux-$arch"
|
|
dir="$work/$name"
|
|
stage "$dir/files"
|
|
cat > "$dir/install.sh" <<'SH'
|
|
#!/bin/sh
|
|
# Installs Musyx into $PREFIX (default ~/.local). Run with PREFIX=/usr/local as root for all users.
|
|
set -eu
|
|
prefix="${PREFIX:-$HOME/.local}"
|
|
here="$(cd "$(dirname "$0")" && pwd)"
|
|
mkdir -p "$prefix"
|
|
cp -R "$here/files/." "$prefix/"
|
|
update-desktop-database "$prefix/share/applications" 2>/dev/null || true
|
|
gtk-update-icon-cache -q -t "$prefix/share/icons/hicolor" 2>/dev/null || true
|
|
echo "Installed Musyx into $prefix"
|
|
SH
|
|
chmod 755 "$dir/install.sh"
|
|
tar -C "$work" -czf "$out/$name.tar.gz" "$name"
|
|
echo "Built $out/$name.tar.gz"
|
|
;;
|
|
|
|
deb)
|
|
# Assembled by hand (ar + tar), so dpkg-deb isn't needed on the build machine.
|
|
pkg="$work/deb"
|
|
stage "$pkg/usr"
|
|
installed_kb="$(du -sk "$pkg/usr" | cut -f1)"
|
|
mkdir -p "$pkg/DEBIAN"
|
|
cat > "$pkg/DEBIAN/control" <<CONTROL
|
|
Package: musyx
|
|
Version: $version
|
|
Architecture: $deb_arch
|
|
Maintainer: Yuriy Panov <uriy.panov@gmail.com>
|
|
Installed-Size: $installed_kb
|
|
Depends: libc6, libgcc-s1, libasound2t64 | libasound2, libdbus-1-3, libxkbcommon0, libwayland-client0 | libx11-6
|
|
Recommends: gnome-keyring | kwalletmanager, libvulkan1 | libgl1
|
|
Section: sound
|
|
Priority: optional
|
|
Description: Desktop player for Yandex Music
|
|
An unofficial client for Yandex Music: My Wave, search, your collection,
|
|
podcasts, lyrics and lossless streaming. Not affiliated with Yandex.
|
|
CONTROL
|
|
(cd "$pkg" && find usr -type f -exec md5sum {} + > DEBIAN/md5sums)
|
|
echo "2.0" > "$work/debian-binary"
|
|
tar -C "$pkg/DEBIAN" --owner=0 --group=0 -cJf "$work/control.tar.xz" .
|
|
tar -C "$pkg" --owner=0 --group=0 --exclude=./DEBIAN -cJf "$work/data.tar.xz" .
|
|
deb="$out/musyx_${version}_${deb_arch}.deb"
|
|
rm -f "$deb"
|
|
(cd "$work" && ar rc "$root/$deb" debian-binary control.tar.xz data.tar.xz)
|
|
echo "Built $deb"
|
|
;;
|
|
|
|
appimage)
|
|
tool="${APPIMAGETOOL:-$(command -v appimagetool || true)}"
|
|
if [[ -z "$tool" ]]; then
|
|
echo "appimagetool not found: put it on PATH or set APPIMAGETOOL" >&2
|
|
echo " (https://github.com/AppImage/appimagetool/releases)" >&2
|
|
exit 1
|
|
fi
|
|
appdir="$work/Musyx.AppDir"
|
|
stage "$appdir/usr"
|
|
ln -s usr/bin/musyx "$appdir/AppRun"
|
|
cp "packaging/linux/$app_id.desktop" "$appdir/$app_id.desktop"
|
|
cp "$appdir/usr/share/icons/hicolor/256x256/apps/$app_id.png" "$appdir/$app_id.png"
|
|
ln -s "$app_id.png" "$appdir/.DirIcon"
|
|
image="$out/Musyx-$version-$arch.AppImage"
|
|
ARCH="$arch" "$tool" --no-appstream "$appdir" "$image" >/dev/null
|
|
echo "Built $image"
|
|
;;
|
|
esac
|
|
done
|