BlueGit

timfa posprint

Files

posprint / scripts / build-arch.sh

build-arch.sh

bc946118 History
build-arch.sh 1.8 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/')"
50# makepkg refuses PKGBUILDs with Windows (CRLF) line endings.
51sed -i "s/\r$//; s/^pkgver=.*/pkgver=${PKGVER}/" packaging/arch/PKGBUILD
52
53cd packaging/arch
54MAKEPKG_FLAGS=(-f --noconfirm)
55if [[ "$AS_ROOT" == "true" ]]; then
56 MAKEPKG_FLAGS+=(--asroot)
57fi
58makepkg "${MAKEPKG_FLAGS[@]}"
59
60shopt -s nullglob
61PACKAGES=(posprint-"${PKGVER}"-*-x86_64.pkg.tar.zst)
62shopt -u nullglob
63if [[ ${#PACKAGES[@]} -eq 0 ]]; then
64 echo "No package produced."
65 exit 1
66fi
67
68echo "Arch package:"
69ls -lh "${PACKAGES[@]}"
70
71if want_install; then
72 echo "Installing with pacman..."
73 sudo pacman -U --noconfirm "${PACKAGES[@]}"
74 echo "Installed."
75fi