|
1 | 1 | #!/bin/bash |
2 | 2 | # |
3 | | -# Build TinyPilot Debian packages. |
4 | | -# |
5 | | -# Usage: |
6 | | -# build-debian-pkg [target architectures] |
7 | | -# |
8 | | -# target architecture: A comma-separated list of architectures that Docker |
9 | | -# accepts for its --platform argument. If omitted, defaults to |
10 | | -# "linux/arm/v7,linux/amd64". The only supported targets are linux/arm/v7 and |
11 | | -# linux/amd64. |
12 | | -# |
13 | | -# Examples |
14 | | -# build-debian-pkg "linux/arm/v7" |
15 | | -# build-debian-pkg "linux/arm/v7,linux/amd64" |
| 3 | +# Build a TinyPilot Debian package. |
16 | 4 |
|
17 | 5 | # Exit build script on first failure. |
18 | 6 | set -e |
19 | 7 |
|
20 | | -# Echo commands before executing them, by default to stderr. |
21 | | -set -x |
22 | | - |
23 | 8 | # Exit on unset variable. |
24 | 9 | set -u |
25 | 10 |
|
26 | | -BUILD_TARGETS="${1:-linux/arm/v7,linux/amd64}" |
| 11 | +print_help() { |
| 12 | + cat <<EOF |
| 13 | +Usage: ${0##*/} [--help] [--build-targets BUILD_TARGETS] [--tinypilot-version TINYPILOT_VERSION] |
| 14 | +Build a TinyPilot Debian package. |
| 15 | + --help Optional. Display this help and exit. |
| 16 | + --build-targets BUILD_TARGETS Optional. A comma-separated list of architectures |
| 17 | + that Docker accepts for its --platform argument. |
| 18 | + If omitted, defaults to "linux/arm/v7,linux/amd64". |
| 19 | + The only supported targets are "linux/arm/v7" and |
| 20 | + "linux/amd64". |
| 21 | + --tinypilot-version TINYPILOT_VERSION Optional. The version identifier that shall be |
| 22 | + assigned. If omitted, determines the version string |
| 23 | + automatically, in the "x.y.z-i+hhhhhhh" format that |
| 24 | + we use for nightly builds. |
| 25 | +EOF |
| 26 | +} |
27 | 27 |
|
28 | 28 | print_tinypilot_version() { |
29 | 29 | # Format build hash suffix according to SemVer (`-ghhhhhhh` -> `+hhhhhhh`). |
30 | 30 | git describe --tags --long | |
31 | 31 | sed --expression 's/\(-g\([0-9a-f]\{7\}\)\)$/+\2/g' |
32 | 32 | } |
33 | 33 |
|
| 34 | +# Parse command-line arguments. |
| 35 | +BUILD_TARGETS='linux/arm/v7,linux/amd64' |
34 | 36 | TINYPILOT_VERSION="$(print_tinypilot_version)" |
| 37 | +while (( "$#" > 0 )); do |
| 38 | + case "$1" in |
| 39 | + --help) |
| 40 | + print_help |
| 41 | + exit |
| 42 | + ;; |
| 43 | + --build-targets) |
| 44 | + BUILD_TARGETS="$2" |
| 45 | + shift # For flag name. |
| 46 | + shift # For flag value. |
| 47 | + ;; |
| 48 | + --tinypilot-version) |
| 49 | + TINYPILOT_VERSION="$2" |
| 50 | + shift # For flag name. |
| 51 | + shift # For flag value. |
| 52 | + ;; |
| 53 | + *) |
| 54 | + >&2 echo "Unknown argument: $1" |
| 55 | + >&2 echo "Use the '--help' flag for more information" |
| 56 | + exit 1 |
| 57 | + ;; |
| 58 | + esac |
| 59 | +done |
| 60 | +readonly BUILD_TARGETS |
35 | 61 | readonly TINYPILOT_VERSION |
36 | 62 |
|
| 63 | +# Echo commands before executing them, by default to stderr. |
| 64 | +set -x |
| 65 | + |
37 | 66 | PKG_VERSION="$(date '+%Y%m%d%H%M%S')" |
38 | 67 | readonly PKG_VERSION |
39 | 68 |
|
|
0 commit comments