Files
marqdo/scripts/ppa-ship.sh
T
cflmyandCursor e31585842d fix(ppa): bundle Rust toolchain for noble Cargo.lock v4 builds
Document install channels (PPA/GitHub/CDN); release skill supports
full/cli/ext modes with R2+GitHub ext uploads and manual PPA commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-17 10:18:50 +08:00

108 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# One-shot: install packaging tools → build signed source package → dput to Launchpad PPA.
#
# Run in YOUR terminal (needs sudo for apt + GPG passphrase for signing):
# ./scripts/ppa-ship.sh # default series: noble
# ./scripts/ppa-ship.sh resolute # match host /etc/os-release
# ./scripts/ppa-ship.sh noble --no-upload
# sudo ./scripts/ppa-ship.sh noble # also OK — build/sign/upload drop back to $SUDO_USER
#
# PPA: ppa:cflmy/marqdo | key: 505943294D04C803
set -euo pipefail
SERIES="${1:-noble}"
NO_UPLOAD=0
for arg in "${@:2}"; do
case "$arg" in
--no-upload|-n) NO_UPLOAD=1 ;;
*) echo "unknown arg: $arg" >&2; exit 2 ;;
esac
done
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
# Never cargo/debuild/dput as root — GPG lives in the human user's ~/.gnupg
if [ "$(id -u)" -eq 0 ]; then
if [ -z "${SUDO_USER:-}" ] || [ "$SUDO_USER" = root ]; then
echo "error: run as a normal user, or: sudo -u \$USER ./scripts/ppa-ship.sh" >&2
exit 1
fi
REAL_USER="$SUDO_USER"
REAL_HOME="$(getent passwd "$REAL_USER" | cut -d: -f6)"
echo "==> root detected; apt as root, build/upload as ${REAL_USER}"
run_user() {
local upath="${REAL_HOME}/.cargo/bin:/usr/local/bin:/usr/bin:/bin"
sudo -u "$REAL_USER" -H --preserve-env=MARQDO_PPA_GPG_KEY \
env HOME="$REAL_HOME" PATH="$upath" "$@"
}
APT=(apt-get)
else
REAL_USER="$(id -un)"
REAL_HOME="$HOME"
run_user() { "$@"; }
APT=(sudo apt-get)
fi
PPA_TARGET="${MARQDO_PPA:-ppa:cflmy/marqdo}"
PKGS=(build-essential debhelper devscripts dput lintian
dpkg-dev quilt cargo rustc pkg-config libssl-dev ca-certificates
python3 xz-utils)
need_apt=0
for bin in debuild dput dpkg-parsechangelog cargo gpg; do
if ! command -v "$bin" >/dev/null 2>&1; then
need_apt=1
break
fi
done
# dh_auto_* comes from debhelper even if debuild exists from a partial install
if ! dpkg -s debhelper >/dev/null 2>&1; then
need_apt=1
fi
if [ "$need_apt" -eq 1 ]; then
echo "==> installing packaging toolchain (sudo)…"
"${APT[@]}" update -qq
DEBIAN_FRONTEND=noninteractive "${APT[@]}" install -y "${PKGS[@]}"
else
echo "==> packaging tools already present"
fi
echo "==> building source package for series=${SERIES}"
run_user "$ROOT/scripts/ppa-build-source.sh" "$SERIES"
VER="$(sed -n 's/^version = "\(.*\)"/\1/p' "$ROOT/Cargo.toml" | head -1)"
BUILD_AREA="$(cd "$ROOT/.." && pwd)/build-area"
# Prefer changes matching this series; fall back to newest source.changes
CHANGES="$(ls -1t "$BUILD_AREA"/marqdo_*"~${SERIES}"_source.changes 2>/dev/null | head -1 || true)"
if [ -z "${CHANGES:-}" ]; then
CHANGES="$(ls -1t "$BUILD_AREA"/marqdo_*_source.changes 2>/dev/null | head -1 || true)"
fi
if [ -z "${CHANGES:-}" ] || [ ! -f "$CHANGES" ]; then
echo "error: no *_source.changes under $BUILD_AREA" >&2
ls -la "$BUILD_AREA" 2>/dev/null || true
exit 1
fi
echo "==> artifact: $CHANGES"
if command -v lintian >/dev/null 2>&1; then
echo "==> lintian (non-fatal)"
run_user lintian -i "$CHANGES" || true
fi
if [ "$NO_UPLOAD" -eq 1 ]; then
echo
echo "Skip upload (--no-upload). When ready:"
echo " dput ${PPA_TARGET} ${CHANGES}"
exit 0
fi
echo "==> dput ${PPA_TARGET}"
run_user dput --unchecked "${PPA_TARGET}" "$CHANGES"
echo
echo "Done. Watch builds:"
echo " https://launchpad.net/~cflmy/+archive/ubuntu/marqdo/+builds"
echo "Enable the Ubuntu series (${SERIES}) in PPA → Change details if Launchpad rejects the upload."