-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.command
More file actions
executable file
·161 lines (143 loc) · 6.18 KB
/
Copy pathbuild.command
File metadata and controls
executable file
·161 lines (143 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
# C8110 Voice Activated Relay - Build Script
#
# Double-click this file in Finder to build the .eap install packages for
# both Axis architectures (armv7hf and aarch64). You can also run it from
# Terminal with `./build.command`.
#
# The AXIS C8110 Network Audio Bridge runs an NXP i.MX 6SoloX, so
# **armv7hf** is the build to install on a C8110. aarch64 is built too so
# the same package can go on a newer Axis audio device for testing.
#
# (Note that this is the reverse of the sibling C17 Timer project, whose
# C1710 is an i.MX 8M Mini and therefore wants the aarch64 build. Easy to
# grab the wrong file if you have both folders open.)
#
# Requires Docker Desktop, installed and running, with network access
# (it pulls the Axis ACAP Native SDK image the first time).
#
# What this does, in order:
# 1. Reads the current version number from app/manifest.json.
# 2. Moves any .eap files already sitting in this folder from a
# previous build into older-versions/, so this folder only ever
# shows the newest build at a glance, but nothing is ever lost -
# the last known-working build is always still there if a new one
# turns out to be broken.
# 3. Builds a Docker image for armv7hf and extracts the resulting .eap
# into this folder.
# 4. Does the same for aarch64.
# 5. Cleans up the temporary Docker containers used for extraction.
# 6. Bumps the patch version number (the last digit) in
# app/manifest.json by one, so the NEXT time this script runs it
# automatically builds the next version - no need to edit the
# version by hand before each build.
set -e
cd "$(dirname "$0")"
pause_and_exit() {
echo
read -n 1 -s -r -p "Press any key to close this window..."
echo
# The keypress above only unblocks the script - it doesn't actually
# close the Terminal window; whether Terminal does that on its own
# depends on a Terminal.app preference (Settings > Profiles > Shell >
# "When the shell exits") that's often left on "Don't close the
# window". Closing it explicitly here works regardless of that
# setting. Matched by tty (this window's specific pseudo-terminal
# device, e.g. /dev/ttys003) rather than by window title, so this can
# only ever close the one window actually running this script - never
# some other Terminal window that happens to have a similar title.
# The close command runs in a detached, briefly-delayed background
# subshell rather than inline: Terminal won't close a window it still
# considers "running a process," so this gives the script's own shell
# a moment to fully exit first.
# Guarded on the path actually looking like a terminal device: `tty`
# prints "not a tty" when this is run from anything that isn't a Terminal
# window, and handing that to osascript would LAUNCH Terminal.app purely
# to ask it to close a window that was never open.
local this_tty
this_tty="$(tty 2>/dev/null || true)"
case "$this_tty" in
/dev/tty*) ;;
*) this_tty="" ;;
esac
if [ -n "$this_tty" ]; then
( sleep 0.3
osascript -e "tell application \"Terminal\" to close (every window whose tty is \"$this_tty\")" >/dev/null 2>&1
) &
disown
fi
}
trap pause_and_exit EXIT
echo "=========================================="
echo " C8110 Voice Activated Relay - Build"
echo "=========================================="
echo
# --- Check Docker is installed and running ---
if ! command -v docker >/dev/null 2>&1; then
echo "ERROR: Docker was not found."
echo "Install Docker Desktop from https://www.docker.com/products/docker-desktop/ and try again."
exit 1
fi
if ! docker info >/dev/null 2>&1; then
echo "ERROR: Docker doesn't seem to be running."
echo "Open Docker Desktop and wait for it to finish starting, then try again."
exit 1
fi
# --- Read the current version straight out of manifest.json, without ---
# --- reformatting the rest of the file. ---
MANIFEST="app/manifest.json"
VERSION=$(grep -Eo '"version": *"[0-9]+\.[0-9]+\.[0-9]+"' "$MANIFEST" | head -1 | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
if [ -z "$VERSION" ]; then
echo "ERROR: Couldn't find a version number in $MANIFEST."
exit 1
fi
echo "Building version $VERSION..."
echo
VERSION_UNDERSCORE=$(echo "$VERSION" | tr '.' '_')
# --- Move any .eap files already in this folder from a previous ---
# --- build into older-versions/, so this folder only ever shows the ---
# --- newest build at a glance without losing older ones - the last ---
# --- known-working build is always still there to fall back to. ---
OLDER_VERSIONS_DIR="older-versions"
shopt -s nullglob
old_eaps=(*.eap)
if [ ${#old_eaps[@]} -gt 0 ]; then
mkdir -p "$OLDER_VERSIONS_DIR"
echo "Moving ${#old_eaps[@]} old .eap file(s) into $OLDER_VERSIONS_DIR/:"
for f in "${old_eaps[@]}"; do
echo " $f"
mv -f "$f" "$OLDER_VERSIONS_DIR/"
done
echo
fi
shopt -u nullglob
build_arch() {
local arch="$1"
echo "--- Building for $arch ---"
docker build --platform=linux/amd64 --build-arg ARCH="$arch" --tag c8110-var-acap-build .
local container_name="c8110var-extract-$arch-$$"
docker create --name "$container_name" --platform=linux/amd64 c8110-var-acap-build >/dev/null
local eap_name="C8110_Voice_Activated_Relay_${VERSION_UNDERSCORE}_${arch}.eap"
docker cp "$container_name:/opt/app/$eap_name" "./$eap_name"
docker rm "$container_name" >/dev/null
echo "Built: $eap_name"
echo
}
# armv7hf first, because that's the one that goes on a C8110.
build_arch armv7hf
build_arch aarch64
# --- Bump the patch (last) version number for next time, in place, ---
# --- touching only that one line. ---
MAJOR_MINOR="${VERSION%.*}"
PATCH="${VERSION##*.}"
NEXT_PATCH=$((PATCH + 1))
NEXT_VERSION="${MAJOR_MINOR}.${NEXT_PATCH}"
sed -i '' "s/\"version\": *\"${VERSION}\"/\"version\": \"${NEXT_VERSION}\"/" "$MANIFEST"
echo "=========================================="
echo " Build complete!"
echo "=========================================="
echo "Files created in this folder:"
echo " C8110_Voice_Activated_Relay_${VERSION_UNDERSCORE}_armv7hf.eap <- install this one on a C8110"
echo " C8110_Voice_Activated_Relay_${VERSION_UNDERSCORE}_aarch64.eap"
echo
echo "Next build will automatically use version ${NEXT_VERSION}."