Files
terminal/scripts/package-linux.sh

137 lines
5.4 KiB
Bash
Executable File

#!/bin/sh
set -eu
umask 022
cd "$(dirname "$0")/.."
if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
echo 'Usage: scripts/package-linux.sh DEB-VERSION OUTPUT-DIR [--with-zx]' >&2
exit 2
fi
deb_version=$1
dpkg --validate-version "$deb_version"
zx_option=${3:-}
case "$zx_option" in ''|--with-zx) ;; *) echo 'Unknown packaging option' >&2; exit 2 ;; esac
output=$(realpath -m -- "$2")
case "$output" in "$PWD"/build/*|"$PWD"/dist) ;; *) echo 'Terminal packages must go under build/ or dist' >&2; exit 2 ;; esac
mkdir -p "$output"
root=$PWD
work=$(mktemp -d "$output/.terminal-package.XXXXXX")
trap 'rm -rf "$work"' EXIT
trap 'exit 1' HUP INT TERM
cd "$work"
# Version-free names keep /releases/latest/download/<name> stable.
deb_root="deb/terminal"
mkdir -p "${deb_root}/DEBIAN" \
"${deb_root}/usr/bin" \
"${deb_root}/usr/share/applications" \
"${deb_root}/usr/share/doc/terminal" \
"${deb_root}/usr/share/icons/hicolor/scalable/apps"
chmod 755 "${deb_root}/DEBIAN"
cp "$root/build/linux-x86_64/bin/terminal" "${deb_root}/usr/bin/terminal"
cp "$root/README.md" "${deb_root}/usr/share/doc/terminal/README.md"
cp "$root/docs/site/favicon.svg" \
"${deb_root}/usr/share/icons/hicolor/scalable/apps/terminal.svg"
cat > "${deb_root}/usr/share/applications/terminal.desktop" <<'EOF'
[Desktop Entry]
Type=Application
Name=Terminal
Comment=Kryon terminal emulator
Exec=terminal
Icon=terminal
Terminal=false
Categories=System;TerminalEmulator;
Keywords=shell;prompt;command;terminal;
EOF
# Depends comes from the binary's real libraries, GTK included.
mkdir -p shlibdeps/debian
printf 'Source: terminal\n\nPackage: terminal\nArchitecture: any\n' \
> shlibdeps/debian/control
shlibdeps=$(cd shlibdeps && dpkg-shlibdeps -O "$work/$deb_root/usr/bin/terminal")
depends=$(printf '%s\n' "$shlibdeps" | sed -n 's/^shlibs:Depends=//p')
test -n "${depends}"
cat > "${deb_root}/DEBIAN/control" <<EOF
Package: terminal
Version: ${deb_version}
Section: x11
Priority: optional
Architecture: amd64
Maintainer: Waozi <[email protected]>
Depends: ${depends}
Recommends: fonts-dejavu-core
Description: Kryon terminal emulator
Terminal is a standalone terminal application using Kryon for windowing,
rendering, input, and platform integration.
EOF
chmod 644 "${deb_root}/DEBIAN/control"
dpkg-deb --build --root-owner-group "${deb_root}" \
terminal-linux-amd64.deb
appdir=AppDir
mkdir -p "${appdir}/usr/bin" \
"${appdir}/usr/share/applications" \
"${appdir}/usr/share/icons/hicolor/scalable/apps"
cp "$root/build/linux-x86_64/bin/terminal" "${appdir}/usr/bin/terminal"
cp "$root/docs/site/favicon.svg" \
"${appdir}/usr/share/icons/hicolor/scalable/apps/terminal.svg"
cp "${deb_root}/usr/share/applications/terminal.desktop" \
"${appdir}/usr/share/applications/terminal.desktop"
# linuxdeploy bundles SDL2, WebP and their dependencies. GTK, GLib,
# Cairo, Pango and GL come from the host: a bundled GTK would not
# match the desktop's themes and modules.
linuxdeploy="$work/linuxdeploy-x86_64.AppImage"
if [ -n "${LINUXDEPLOY_APPIMAGE:-}" ]; then
cp "$LINUXDEPLOY_APPIMAGE" "$linuxdeploy"
else
curl --retry 2 -fsSL -o "$linuxdeploy" \
https://github.com/linuxdeploy/linuxdeploy/releases/download/1-alpha-20251107-1/linuxdeploy-x86_64.AppImage
fi
echo "c20cd71e3a4e3b80c3483cef793cda3f4e990aca14014d23c544ca3ce1270b4d ${linuxdeploy}" |
sha256sum -c -
chmod 755 "${linuxdeploy}"
(
APPIMAGE_EXTRACT_AND_RUN=1 ARCH=x86_64 \
LINUXDEPLOY_OUTPUT_VERSION="${deb_version}" \
LDAI_OUTPUT=terminal-linux-x86_64.AppImage \
"${linuxdeploy}" --appdir "${work}/${appdir}" \
--executable "${work}/${appdir}/usr/bin/terminal" \
--desktop-file "${work}/${appdir}/usr/share/applications/terminal.desktop" \
--icon-file "${work}/${appdir}/usr/share/icons/hicolor/scalable/apps/terminal.svg" \
--exclude-library 'libgtk-3.so*' --exclude-library 'libgdk-3.so*' \
--exclude-library 'libgdk_pixbuf-2.0.so*' --exclude-library 'libglib-2.0.so*' \
--exclude-library 'libgobject-2.0.so*' --exclude-library 'libgio-2.0.so*' \
--exclude-library 'libgmodule-2.0.so*' --exclude-library 'libcairo*' \
--exclude-library 'libpango*' --exclude-library 'libatk*' \
--exclude-library 'libGL.so*' --exclude-library 'libGLX*' \
--output appimage
)
test -x terminal-linux-x86_64.AppImage
set -- terminal-linux-amd64.deb terminal-linux-x86_64.AppImage
if [ "$zx_option" = --with-zx ]; then
guest="$root/build/linux-x86_64/Terminal.zx"
player="$root/build/linux-x86_64/terminal-zx-player"
mkdir zx
install -m 644 "$guest" zx/Terminal.zx
install -m 755 "$player" zx/terminal-zx-player
env -u DISPLAY -u WAYLAND_DISPLAY -u XAUTHORITY -u DBUS_SESSION_BUS_ADDRESS \
-u SESSION_MANAGER HARMONY_DESKTOP_RECOVERY=0 YUE_DESKTOP_RECOVERY=0 \
zx/terminal-zx-player --check
cat > zx/README.txt <<'EOF'
Terminal ZX for Linux x86-64
Keep Terminal.zx in the same directory as terminal-zx-player. Run
./terminal-zx-player to open Terminal, or ./terminal-zx-player --check
to validate the bundle and its host bindings. The player uses the
system SDL2, Cairo, Pango, Fontconfig, GLib, X11 and libcurl libraries.
The guest uses the player's POSIX PTY and terminal screen bindings.
EOF
tar -czf terminal-zx-linux-x86_64.tar.gz -C zx README.txt Terminal.zx terminal-zx-player
cp zx/Terminal.zx Terminal.zx
set -- "$@" Terminal.zx terminal-zx-linux-x86_64.tar.gz
fi
sha256sum "$@" > SHA256SUMS
for file in "$@"; do
mv -f "$file" "$output/$file"
done
mv -f SHA256SUMS "$output/SHA256SUMS"