Files
g15keyboard/packaging/build.sh
T
2026-09-07 17:06:51 +00:00

71 lines
3.7 KiB
Bash

#!/bin/bash
# Installs dependencies and outputs: disposable Debian 13 containers ONLY.
set -euo pipefail
export LC_ALL=C
root=$(cd -- "$(dirname -- "$0")/.." && pwd)
[[ -f /.dockerenv && $EUID == 0 ]] || { echo 'Disposable root Docker container required' >&2; exit 1; }
# shellcheck source=/dev/null
. /etc/os-release
[[ $ID == debian && $VERSION_ID == 13 ]] || exit 1
out=$(realpath "${1:?empty artifact directory required}")
[[ -d $out && -z $(find "$out" -mindepth 1 -print -quit) ]] || exit 1
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
export DEB_BUILD_OPTIONS=${DEB_BUILD_OPTIONS:-parallel=2}
export DEBFULLNAME='G15 packaging contributors' DEBEMAIL='noreply@example.invalid'
git config --global --add safe.directory "$root"
for source in libg15 libg15render g15daemon g15macro g15stats; do
git config --global --add safe.directory "$root/$source"
pin=$(git -C "$root" ls-files --stage -- "$source" | awk '$1 == 160000 {print $2}')
[[ -n $pin && $(git -C "$root/$source" rev-parse HEAD) == "$pin" ]] \
|| { echo "$source: HEAD does not match the committed gitlink pin" >&2; exit 1; }
[[ -z $(git -C "$root/$source" status --porcelain --untracked-files=all) ]] \
|| { echo "$source: submodule has uncommitted or untracked changes; commit or stash them first" >&2; exit 1; }
done
git -C "$root" submodule status --recursive -- libg15 libg15render g15daemon g15macro g15stats > "$out/SUBMODULES"
if grep -q '^[+U-]' "$out/SUBMODULES"; then echo 'Submodule pin mismatch or missing module' >&2; exit 1; fi
for source in libg15 libg15render g15daemon g15macro g15stats; do
mkdir "$work/$source"
cd "$work/$source"
sha=$(git -C "$root/$source" rev-parse HEAD)
export SOURCE_DATE_EPOCH
SOURCE_DATE_EPOCH=$(git -C "$root/$source" show -s --format=%ct HEAD)
mkdir tree
git -C "$root/$source" archive HEAD | tar -x -C tree
[[ ! -d tree/.pc ]] || { echo 'Expected unapplied quilt checkout' >&2; exit 1; }
base=$(dpkg-parsechangelog -l tree/debian/changelog -S Version)
upstream=${base%-*}
[[ $source != g15macro ]] || upstream=1.0.5
upstream+=+g15.git${sha:0:12}
version=$upstream-1
mv tree "$source-$upstream"
tree=$PWD/$source-$upstream
tar --sort=name --mtime="@$SOURCE_DATE_EPOCH" --owner=0 --group=0 --numeric-owner \
--exclude="$source-$upstream/debian" -cJf "${source}_${upstream}.orig.tar.xz" "$source-$upstream"
if [[ $source != g15stats ]]; then
(cd "$tree" && bash "$root/packaging/overlays/v1/apply.sh" "$source" "$root")
fi
if [[ $source == g15daemon ]]; then
mkdir official
(cd official && apt-get source --download-only g15daemon=1.9.5.3-14.1 && dpkg-source --skip-patches -x ./*.dsc source)
diff -u official/source/debian/control "$tree/debian/control"
diff -u official/source/debian/libg15daemon-client1t64.lintian-overrides "$tree/debian/libg15daemon-client1t64.lintian-overrides"
fi
cd "$tree"
sed -i "s/^Maintainer:.*/Maintainer: $DEBFULLNAME <$DEBEMAIL>/" debian/control
dch --newversion "$version" --distribution trixie --force-distribution \
"Export $source commit $sha; see README.local-build for packaging policy."
sed -i "0,/^ -- /s/^ -- .*/ -- $DEBFULLNAME <$DEBEMAIL> $(date -u -R -d "@$SOURCE_DATE_EPOCH")/" debian/changelog
if [[ $source == g15stats ]]; then
printf '%s\n' 'Uses committed Debian packaging without an outer overlay.' > debian/README.local-build
else
cp "$root/packaging/overlays/v1/README.md" debian/README.local-build
fi
apt-get build-dep -y .
dpkg-buildpackage -us -uc -sa
cd ..
cp ./*.deb ./*.dsc ./*.tar.* ./*.buildinfo ./*.changes "$out/"
apt-get install -y ./*.deb
done
cd "$out"
sha256sum -- *.deb *.dsc *.tar.* *.buildinfo *.changes SUBMODULES > SHA256SUMS