#!/usr/bin/env bash # # Build a Debian package for stoke. # # Usage: scripts/build-deb.sh # # Produces dist/stoke__all.deb from a clean staging copy of the # working tree (only src/, package.json and package-lock.json are shipped; # production dependencies are installed fresh with `npm ci --omit=dev`). # # Requirements: bash, node/npm, dpkg-deb, gzip. Runs lintian when available. set -euo pipefail # The payload must be world-readable regardless of the builder's umask # (with umask 077, `stoke` would be unreadable for non-root after install). umask 022 ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" VERSION="$(node -p "require('$ROOT/package.json').version")" MAINTAINER="${DEB_MAINTAINER:-Heavy Duty Builders }" HOMEPAGE="https://forgejo.heavyduty.builders/heavy-duty/stoke" STAGE="$(mktemp -d)" trap 'rm -rf "$STAGE"' EXIT PKG="$STAGE/stoke_${VERSION}_all" LIB="$PKG/usr/lib/stoke" DOC="$PKG/usr/share/doc/stoke" install -d "$PKG/DEBIAN" "$LIB" "$PKG/usr/bin" "$DOC" # --- payload ----------------------------------------------------------------- cp -r "$ROOT/src" "$LIB/src" cp "$ROOT/package.json" "$ROOT/package-lock.json" "$LIB/" (cd "$LIB" && npm ci --omit=dev --silent --no-audit --no-fund) # Launcher: the CLI has a `#!/usr/bin/env node` shebang and resolves its # node_modules relative to its real path, so a symlink is all we need. ln -s ../lib/stoke/src/cli.js "$PKG/usr/bin/stoke" # --- docs (lintian: copyright + Debian changelog) ---------------------------- cat > "$DOC/copyright" < "$STAGE/changelog" < "$DOC/changelog.gz" # Normalize permissions regardless of the builder's umask: no group/other # write anywhere, everything readable, executable entry point. chmod -R go-w "$PKG/usr" chmod -R a+rX "$PKG/usr" chmod 0755 "$LIB/src/cli.js" # --- control ----------------------------------------------------------------- INSTALLED_SIZE="$(du -sk --exclude=DEBIAN "$PKG" | cut -f1)" cat > "$PKG/DEBIAN/control" <= 22.12) Installed-Size: $INSTALLED_SIZE Maintainer: $MAINTAINER Homepage: $HOMEPAGE Description: CLI for the heavy-duty forge (Forgejo) stoke manages the Forgejo instance at forgejo.heavyduty.builders from the command line: authentication, repositories, issues, pull requests, branches, collaborators, organizations, teams and users. EOF # --- build ------------------------------------------------------------------- mkdir -p "$ROOT/dist" dpkg-deb --build --root-owner-group "$PKG" "$ROOT/dist/" >/dev/null DEB="$ROOT/dist/stoke_${VERSION}_all.deb" echo "Built: $DEB" if command -v lintian >/dev/null 2>&1; then # binary-without-manpage is a known, accepted gap for now. lintian --suppress-tags binary-without-manpage "$DEB" || true else echo "Note: lintian not installed; skipping package lint." fi