BlueGit

timfa posprint

Files

posprint / scripts / build-linux.sh

build-linux.sh

build-linux.sh 1.8 KiB Download Raw
1#!/usr/bin/env bash
2set -euo pipefail
3
4ROOT="$(cd "$(dirname "$0")/.." && pwd)"
5cd "$ROOT"
6
7BUILD_DEB=false
8SKIP_TESTS=false
9INSTALL=false
10
11for arg in "$@"; do
12 case "$arg" in
13 --deb) BUILD_DEB=true ;;
14 --skip-tests) SKIP_TESTS=true ;;
15 --install) INSTALL=true ;;
16 -h|--help)
17 echo "Usage: $0 [--deb] [--skip-tests] [--install]"
18 echo "Builds target/release/posprint (and optionally a .deb)."
19 echo " --deb also build a Debian package with cargo-deb"
20 echo " --install install the .deb with apt after building (implies --deb)"
21 echo "Without --install, prompts interactively for .deb install when stdin is a TTY."
22 exit 0
23 ;;
24 *) echo "Unknown option: $arg"; exit 1 ;;
25 esac
26done
27
28if [[ "$INSTALL" == "true" ]]; then
29 BUILD_DEB=true
30fi
31
32want_install() {
33 if [[ "$INSTALL" == "true" ]]; then
34 return 0
35 fi
36 if [[ ! -t 0 ]]; then
37 return 1
38 fi
39 local answer
40 read -r -p "Install the .deb now with apt? [y/N] " answer
41 [[ "$answer" =~ ^[Yy]([Ee][Ss])?$ ]]
42}
43
44echo "Building posprint for Linux (x86_64)..."
45
46if [[ "$SKIP_TESTS" != "true" ]]; then
47 cargo test
48fi
49
50cargo build --release
51BIN="$ROOT/target/release/posprint"
52echo "OK: $BIN"
53ls -lh "$BIN"
54
55if [[ "$BUILD_DEB" == "true" ]]; then
56 if ! command -v cargo-deb &>/dev/null; then
57 echo "Installing cargo-deb..."
58 cargo install cargo-deb --locked
59 fi
60 cargo deb
61 shopt -s nullglob
62 DEBS=("$ROOT"/target/debian/*.deb)
63 shopt -u nullglob
64 if [[ ${#DEBS[@]} -eq 0 ]]; then
65 echo "No .deb produced."
66 exit 1
67 fi
68 echo "Debian packages:"
69 ls -lh "${DEBS[@]}"
70
71 if want_install; then
72 echo "Installing with apt..."
73 # Relative path so apt treats it as a local package file.
74 sudo apt-get install -y "${DEBS[@]}"
75 echo "Installed."
76 fi
77fi