BlueGit

timfa posprint

Files

posprint / scripts / build-arch.sh

build-arch.sh

build-arch.sh 2.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 echo "Uses rustup/cargo on PATH; runs makepkg --nodeps if pacman rust/cargo are absent."
23 exit 0
24 ;;
25 *) echo "Unknown option: $arg"; exit 1 ;;
26 esac
27done
28
29want_install() {
30 if [[ "$INSTALL" == "true" ]]; then
31 return 0
32 fi
33 if [[ ! -t 0 ]]; then
34 return 1
35 fi
36 local answer
37 read -r -p "Install the package now with pacman? [y/N] " answer
38 [[ "$answer" =~ ^[Yy]([Ee][Ss])?$ ]]
39}
40
41if ! command -v makepkg &>/dev/null; then
42 echo "makepkg not found. On Arch, install base-devel: sudo pacman -S base-devel"
43 exit 1
44fi
45
46# Ensure rustup toolchains are visible to makepkg's build().
47if [[ -f "$HOME/.cargo/env" ]]; then
48 # shellcheck source=/dev/null
49 source "$HOME/.cargo/env"
50fi
51
52if ! command -v cargo &>/dev/null || ! command -v rustc &>/dev/null; then
53 echo "cargo/rustc not found. Install via rustup (https://rustup.rs) or: sudo pacman -S rust"
54 exit 1
55fi
56
57# PKGBUILD lists pacman rust/cargo as makedepends. rustup installs don't register
58# those packages, so skip dep resolution when the toolchain is already on PATH.
59MAKEPKG_NODEPS=false
60if ! pacman -Q rust &>/dev/null || ! pacman -Q cargo &>/dev/null; then
61 echo "Note: pacman rust/cargo not installed; using toolchain on PATH ($(rustc --version))."
62 echo " makepkg will run with --nodeps."
63 MAKEPKG_NODEPS=true
64fi
65
66if [[ "$SKIP_TESTS" != "true" ]]; then
67 cargo test
68fi
69
70PKGVER="$(grep '^version' Cargo.toml | head -1 | sed -E 's/.*"([^"]+)".*/\1/')"
71# makepkg refuses PKGBUILDs with Windows (CRLF) line endings.
72sed -i "s/\r$//; s/^pkgver=.*/pkgver=${PKGVER}/" packaging/arch/PKGBUILD
73
74cd packaging/arch
75MAKEPKG_FLAGS=(-f --noconfirm)
76if [[ "$AS_ROOT" == "true" ]]; then
77 MAKEPKG_FLAGS+=(--asroot)
78fi
79if [[ "$MAKEPKG_NODEPS" == "true" ]]; then
80 MAKEPKG_FLAGS+=(--nodeps)
81fi
82makepkg "${MAKEPKG_FLAGS[@]}"
83
84shopt -s nullglob
85PACKAGES=(posprint-"${PKGVER}"-*-x86_64.pkg.tar.zst)
86shopt -u nullglob
87if [[ ${#PACKAGES[@]} -eq 0 ]]; then
88 echo "No package produced."
89 exit 1
90fi
91
92echo "Arch package:"
93ls -lh "${PACKAGES[@]}"
94
95if want_install; then
96 echo "Installing with pacman..."
97 sudo pacman -U --noconfirm "${PACKAGES[@]}"
98 echo "Installed."
99fi