Files
marqdo/scripts/ppa-build-source.sh
T
cflmyandCursor 9bc7ef3b5a feat(packaging): scaffold Ubuntu PPA debian/ for marqdo CLI
Add control/rules/changelog and ppa-build-source.sh (cargo vendor + debuild -S).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-17 09:57:11 +08:00

91 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build a signed Ubuntu *source* package for Launchpad PPA.
# Usage: ./scripts/ppa-build-source.sh [series]
# Example: ./scripts/ppa-build-source.sh noble
set -euo pipefail
SERIES="${1:-noble}"
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
need() { command -v "$1" >/dev/null || { echo "missing tool: $1 (sudo apt install $2)"; exit 1; }; }
need cargo cargo
need debuild devscripts
need dpkg-parsechangelog dpkg-dev
VER="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)"
DEB_VER="${VER}-1ppa1~${SERIES}"
PKG_ROOT="${TMPDIR:-/tmp}/marqdo-ppa/${VER}"
BUILD_AREA="${ROOT}/../build-area"
GPG_KEY="${MARQDO_PPA_GPG_KEY:-505943294D04C803}"
echo "==> upstream ${VER} → debian ${DEB_VER} (${SERIES})"
rm -rf "$PKG_ROOT"
mkdir -p "$PKG_ROOT" "$BUILD_AREA"
# Clean export of sources (no target/, .git)
if command -v git >/dev/null && git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
git archive --format=tar HEAD | tar -x -C "$PKG_ROOT"
else
rsync -a --exclude target --exclude .git --exclude build-area "$ROOT"/ "$PKG_ROOT"/
fi
# Ensure debian/ from working tree (may be newer than last commit)
rsync -a "$ROOT/debian/" "$PKG_ROOT/debian/"
# Series-specific changelog entry (rewrite top distribution)
cd "$PKG_ROOT"
# Update changelog top line distribution / version if needed
python3 - <<PY
from pathlib import Path
import re
p = Path("debian/changelog")
text = p.read_text(encoding="utf-8")
text2 = re.sub(
r"^marqdo \([^)]+\) [^;]+;",
"marqdo (${DEB_VER}) ${SERIES};",
text,
count=1,
flags=re.M,
)
p.write_text(text2, encoding="utf-8")
print("changelog:", p.read_text(encoding="utf-8").splitlines()[0])
PY
echo "==> cargo vendor (Launchpad offline)"
mkdir -p .cargo
cargo vendor --locked vendor >/tmp/marqdo-cargo-vendor.conf
# cargo vendor prints config to stdout; also write known-good offline config
cat > .cargo/config.toml <<'EOF'
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor"
EOF
# Orig tarball: upstream version without debian/
cd "$(dirname "$PKG_ROOT")"
ORIG="marqdo_${VER}.orig.tar.xz"
if [ ! -f "$BUILD_AREA/$ORIG" ]; then
tar -cJf "$BUILD_AREA/$ORIG" \
--exclude=debian \
-C "$(dirname "$PKG_ROOT")" "$(basename "$PKG_ROOT")"
fi
# debuild expects ../marqdo_VER.orig.tar.xz relative to package dir parent
ln -sfn "$BUILD_AREA/$ORIG" "marqdo_${VER}.orig.tar.xz"
cd "$PKG_ROOT"
echo "==> debuild -S (key ${GPG_KEY})"
debuild -S -sa -k"${GPG_KEY}" -d
echo "==> artifacts:"
ls -la "$BUILD_AREA"/marqdo_"${DEB_VER}"* 2>/dev/null || ls -la ../marqdo_"${DEB_VER}"*
CHANGES="$(ls -1 ../marqdo_${DEB_VER}_source.changes 2>/dev/null | head -1)"
if [ -n "${CHANGES:-}" ]; then
cp -f ../marqdo_"${DEB_VER}"* "$BUILD_AREA/" 2>/dev/null || true
echo
echo "Upload with:"
echo " dput ppa:cflmy/marqdo $BUILD_AREA/$(basename "$CHANGES")"
fi