BlueGit

timfa posprint

Files

posprint / scripts / make-linux-bin-tarball.sh

make-linux-bin-tarball.sh

make-linux-bin-tarball.sh 1.1 KiB Download Raw
1#!/usr/bin/env bash
2# Pack usr/ from an Arch .pkg.tar.zst into posprint-<ver>-x86_64.tar.gz for AUR posprint-bin.
3set -euo pipefail
4
5ROOT="$(cd "$(dirname "$0")/.." && pwd)"
6PKG_ZST="${1:-}"
7OUT="${2:-}"
8VERSION="${3:-}"
9
10if [[ -z "$PKG_ZST" ]]; then
11 shopt -s nullglob
12 candidates=("$ROOT"/packaging/arch/*.pkg.tar.zst "$ROOT"/dist/*.pkg.tar.zst)
13 shopt -u nullglob
14 if [[ ${#candidates[@]} -eq 0 ]]; then
15 echo "Usage: $0 <posprint-*.pkg.tar.zst> [out.tar.gz] [version]" >&2
16 exit 1
17 fi
18 PKG_ZST="${candidates[0]}"
19fi
20
21if [[ -z "$VERSION" ]]; then
22 VERSION="$(grep '^version = ' "$ROOT/Cargo.toml" | sed -E 's/.*"([^"]+)"/\1/')"
23fi
24VERSION="${VERSION#v}"
25
26if [[ -z "$OUT" ]]; then
27 mkdir -p "$ROOT/dist"
28 OUT="$ROOT/dist/posprint-${VERSION}-x86_64.tar.gz"
29fi
30
31EXTRACT="$(mktemp -d)"
32cleanup() { rm -rf "$EXTRACT"; }
33trap cleanup EXIT
34
35if command -v bsdtar >/dev/null; then
36 bsdtar -C "$EXTRACT" -xf "$PKG_ZST"
37else
38 tar -C "$EXTRACT" -xf "$PKG_ZST"
39fi
40
41if [[ ! -d "$EXTRACT/usr" ]]; then
42 echo "Arch package did not contain usr/: $PKG_ZST" >&2
43 exit 1
44fi
45
46mkdir -p "$(dirname "$OUT")"
47tar -C "$EXTRACT" -czf "$OUT" usr
48echo "Wrote $OUT"