-
Notifications
You must be signed in to change notification settings - Fork 1
/
preload.sh
72 lines (61 loc) · 2.06 KB
/
preload.sh
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
#!/usr/bin/env bash
set -eu
# keep container running after exit
trap 'tail -f /dev/null' EXIT
echo "balena CLI:"
balena version
docker version
mkdir -p /images
# keep the filenames somewhat unique
target_img="${PRELOAD_FLEET_SLUG/\//-/}"
target_img="${target_img}-${PRELOAD_DEVICE_TYPE}"
target_img="${target_img}-${PRELOAD_OS_VERSION}"
target_img="${target_img}-${PRELOAD_RELEASE}"
target_img="/images/${target_img//[^[:alnum:]_-]}.img"
# balena login with api key
echo "Logging in..."
balena login --token "${CLI_API_KEY}"
# download the specified os version
echo "Downloading OS version '${PRELOAD_OS_VERSION}' for device '${PRELOAD_DEVICE_TYPE}'..."
balena os download "${PRELOAD_DEVICE_TYPE}" \
--version "${PRELOAD_OS_VERSION}" \
--output "${target_img}" \
--debug
if [ -n "${IMAGE_MD5SUM:-}" ]
then
echo "Verifying the OS image md5sum '${IMAGE_MD5SUM}'..."
md5sum /root/.balena/cache/* | tee /dev/stderr | grep -q "${IMAGE_MD5SUM}" || true
md5sum "${target_img}" | tee /dev/stderr | grep -q "${IMAGE_MD5SUM}" || { echo "${target_img} failed verification!" ; exit 1 ; }
fi
# configure the downloaded os
echo "Configuring OS image with '${PRELOAD_NETWORK}'..."
balena os configure "${target_img}" \
--fleet "${PRELOAD_FLEET_SLUG}" \
--config-network "${PRELOAD_NETWORK}" \
--config-wifi-ssid "${PRELOAD_WIFI_SSID:-}" \
--config-wifi-key "${PRELOAD_WIFI_KEY:-}" \
--device-type "${PRELOAD_DEVICE_TYPE}" \
--debug
# preload the fleet containers and optionally pin the release
echo "Preloading image with release '${PRELOAD_RELEASE}'..."
case ${PRELOAD_PINNED} in
y)
balena preload "${target_img}" \
--fleet "${PRELOAD_FLEET_SLUG}" \
--commit "${PRELOAD_RELEASE}" \
--pin-device-to-release \
--debug
;;
n)
balena preload "${target_img}" \
--fleet "${PRELOAD_FLEET_SLUG}" \
--commit "${PRELOAD_RELEASE}" \
--debug
;;
*)
echo "PRELOAD_PINNED must be 'y' or 'n'"
exit 1
;;
esac
echo "Preload complete!"
echo "Images can be downloaded via file server on port 80."