120 lines
4.4 KiB
Bash
Executable File
120 lines
4.4 KiB
Bash
Executable File
#!/bin/sh
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
# build-deb -- build the Debian package of MeshTerm for an amd64 Linux desktop.
|
|
#
|
|
# Usage: scripts/linux-amd64/build-deb.sh [REVISION]
|
|
#
|
|
# Run it on amd64 Debian 13 ("Trixie") with Python 3.13, for example in a debian:trixie
|
|
# container. The package holds compiled code, so it must be built on the system that it
|
|
# is for. The CI workflow .gitea/workflows/upstream-release.yml runs it.
|
|
#
|
|
# The package depends only on python3. All else is inside it:
|
|
#
|
|
# /usr/lib/meshterm/site MeshTerm and its Python packages, compiled to bytecode
|
|
# /usr/bin/meshterm the command line and the TUI
|
|
# /usr/share/doc/meshterm/ LICENSE, NOTICE, THIRD-PARTY-NOTICES.txt, and copyright
|
|
#
|
|
# REVISION is the Debian revision, 1 by default. Use letters, digits, ".", "+" and "~".
|
|
set -eu
|
|
umask 022
|
|
|
|
HERE=$(cd "$(dirname "$0")" && pwd)
|
|
SOURCE=$(cd "$HERE/../.." && pwd)
|
|
REVISION=${1:-1}
|
|
PYTHON=/usr/bin/python3
|
|
ARCH=amd64
|
|
|
|
die() {
|
|
echo "build-deb: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
command -v dpkg-deb >/dev/null || die "no dpkg-deb here. Run this on Debian."
|
|
[ "$(dpkg --print-architecture)" = "$ARCH" ] || die "this is not $ARCH. The package holds $ARCH code."
|
|
[ "$("$PYTHON" -c 'import sys; print("%d.%d" % sys.version_info[:2])')" = 3.13 ] ||
|
|
die "$PYTHON is not Python 3.13. The package is for Debian 13."
|
|
case "$REVISION" in
|
|
"" | [!0-9A-Za-z]* | *[!0-9A-Za-z.+~]*) die "the revision '$REVISION' is not a valid Debian revision" ;;
|
|
esac
|
|
|
|
VERSION=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' "$SOURCE/meshterm/__init__.py")
|
|
[ -n "$VERSION" ] || die "no __version__ in $SOURCE/meshterm/__init__.py"
|
|
DEB_VERSION="$VERSION-$REVISION"
|
|
|
|
WORK=$(mktemp -d)
|
|
trap 'rm -rf "$WORK"' EXIT
|
|
STAGE="$WORK/root"
|
|
LIB="$STAGE/usr/lib/meshterm"
|
|
DOC="$STAGE/usr/share/doc/meshterm"
|
|
|
|
echo "building meshterm $DEB_VERSION ($ARCH) from $SOURCE"
|
|
|
|
# A venv for the tools of the build only. Its base is the system Python, so the compiled
|
|
# packages that its pip builds are correct for the Python that runs them.
|
|
"$PYTHON" -m venv "$WORK/venv"
|
|
"$WORK/venv/bin/pip" install --quiet --upgrade pip packaging
|
|
|
|
# MeshTerm and its packages. --no-compile, because the bytecode is compiled below.
|
|
"$WORK/venv/bin/pip" install --quiet --no-compile --target "$LIB/site" "$SOURCE"
|
|
rm -rf "$LIB/site/bin"
|
|
|
|
# The licences: MeshTerm's own, and the licence of each package in the site directory.
|
|
mkdir -p "$DOC"
|
|
cp "$SOURCE/LICENSE" "$SOURCE/NOTICE" "$DOC/"
|
|
"$WORK/venv/bin/python" "$SOURCE/packaging/notices.py" "$DOC/THIRD-PARTY-NOTICES.txt" "$LIB/site"
|
|
cat >"$DOC/copyright" <<EOF
|
|
MeshTerm $VERSION
|
|
Source: https://github.com/jpmartineau/MeshTerm
|
|
|
|
MeshTerm is licensed under the Apache License, Version 2.0. Refer to LICENSE and NOTICE in
|
|
this directory. The name "MeshTerm" and its logo are trademarks. NOTICE has the terms.
|
|
|
|
The Python packages in /usr/lib/meshterm/site have their own licences. Refer to
|
|
THIRD-PARTY-NOTICES.txt in this directory.
|
|
|
|
This package is a build of a fork of MeshTerm. It is not an official release.
|
|
EOF
|
|
|
|
# Bytecode. The user cannot write in /usr/lib, so Python cannot cache bytecode there.
|
|
"$PYTHON" -m compileall -q -j 0 --invalidation-mode unchecked-hash "$LIB/site" >/dev/null
|
|
|
|
# The wrapper. -s keeps the packages of the user's own site directory out.
|
|
mkdir -p "$STAGE/usr/bin"
|
|
cat >"$STAGE/usr/bin/meshterm" <<'EOF'
|
|
#!/bin/sh
|
|
# MeshTerm's command line and TUI.
|
|
export PYTHONPATH=/usr/lib/meshterm/site
|
|
exec /usr/bin/python3 -s -m meshterm "$@"
|
|
EOF
|
|
chmod 755 "$STAGE/usr/bin/meshterm"
|
|
|
|
# Make sure that the bundle runs before it is packaged.
|
|
check() {
|
|
MESHTERM_HOME="$WORK/home" PYTHONPATH="$LIB/site" "$PYTHON" -s "$@" >/dev/null
|
|
}
|
|
check -m meshterm --help
|
|
check -m meshterm contacts --help
|
|
check -m meshterm specimen
|
|
|
|
mkdir -p "$STAGE/DEBIAN"
|
|
cat >"$STAGE/DEBIAN/control" <<EOF
|
|
Package: meshterm
|
|
Version: $DEB_VERSION
|
|
Architecture: $ARCH
|
|
Maintainer: ${DEB_MAINTAINER:-MeshTerm fork build <noreply@localhost>}
|
|
Installed-Size: $(du -sk "$STAGE" | cut -f1)
|
|
Depends: python3 (>= 3.13), python3 (<< 3.14)
|
|
Suggests: python3-tk
|
|
Section: hamradio
|
|
Priority: optional
|
|
Homepage: https://meshterm.net
|
|
Description: full-featured TUI MeshCore client for the terminal
|
|
MeshTerm is a full-featured TUI MeshCore client. It connects to a companion
|
|
over USB, Bluetooth, or TCP. This is a build of a fork, not an official release.
|
|
EOF
|
|
|
|
mkdir -p "$SOURCE/dist"
|
|
OUT="$SOURCE/dist/meshterm_${DEB_VERSION}_${ARCH}.deb"
|
|
dpkg-deb --root-owner-group -Zxz --build "$STAGE" "$OUT" >/dev/null
|
|
echo "built $OUT ($(du -h "$OUT" | cut -f1))"
|