BlueGit

timfa posprint

Files

posprint / scripts / build-arch.sh

build-arch.sh

build-arch.sh 1.7 KiB Download Raw
1#!/usr/bin/env bash
2# Build an Arch Linux pacman package (.pkg.tar.zst) for posprint.
3set -euo pipefail
4
5ROOT="$(cd "$(dirname "$0")/.." && pwd)"
6cd "$ROOT"
7
8SKIP_TESTS=false
9AS_ROOT=false
10INSTALL=false
11
12for arg in "$@"; do
13 case "$arg" in
14 --skip-tests) SKIP_TESTS=true ;;
15 --asroot) AS_ROOT=true ;;
16 --install) INSTALL=true ;;
17 -h|--help)
18 echo "Usage: $0 [--skip-tests] [--asroot] [--install]"
19 echo "Builds packaging/arch/posprint-<ver>-<rel>-x86_64.pkg.tar.zst"
20 echo " --install install the package with pacman after building"
21 echo "Without --install, prompts interactively when stdin is a TTY."
22 exit 0
23 ;;
24 *) echo "Unknown option: $arg"; exit 1 ;;
25 esac
26done
27
28want_install() {
29 if [[ "$INSTALL" == "true" ]]; then
30 return 0
31 fi
32 if [[ ! -t 0 ]]; then
33 return 1
34 fi
35 local answer
36 read -r -p "Install the package now with pacman? [y/N] " answer
37 [[ "$answer" =~ ^[Yy]([Ee][Ss])?$ ]]
38}
39
40if ! command -v makepkg &>/dev/null; then
41 echo "makepkg not found. On Arch, install base-devel: sudo pacman -S base-devel"
42 exit 1
43fi
44
45if [[ "$SKIP_TESTS" != "true" ]]; then
46 cargo test
47fi
48
49PKGVER="$(grep '^version' Cargo.toml | head -1 | sed -E 's/.*"([^"]+)".*/\1/')"
50sed -i "s/^pkgver=.*/pkgver=${PKGVER}/" packaging/arch/PKGBUILD
51
52cd packaging/arch
53MAKEPKG_FLAGS=(-f --noconfirm)
54if [[ "$AS_ROOT" == "true" ]]; then
55 MAKEPKG_FLAGS+=(--asroot)
56fi
57makepkg "${MAKEPKG_FLAGS[@]}"
58
59shopt -s nullglob
60PACKAGES=(posprint-"${PKGVER}"-*-x86_64.pkg.tar.zst)
61shopt -u nullglob
62if [[ ${#PACKAGES[@]} -eq 0 ]]; then
63 echo "No package produced."
64 exit 1
65fi
66
67echo "Arch package:"
68ls -lh "${PACKAGES[@]}"
69
70if want_install; then
71 echo "Installing with pacman..."
72 sudo pacman -U --noconfirm "${PACKAGES[@]}"
73 echo "Installed."
74fi