-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
executable file
·101 lines (79 loc) · 2.09 KB
/
install.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
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
#!/bin/sh
# shellcheck shell=ash
# shellcheck disable=SC3010,SC3020
set -o errexit
set -o nounset
set -o pipefail
LOCAL_IMAGE='uxg-setup:default'
REMOTE_IMAGE='joshuaspence/uxg-setup'
depends_on() {
command -v "${1}" &>/dev/null || {
echo "Missing dependency: \`${1}\`" >&2
return 1
}
}
header() {
cat <<'EOF'
_ ___ ______ ____ _
| | | \ \/ / ___| | __ ) ___ ___ | |_
| | | |\ / | _ | _ \ / _ \ / _ \| __|
| |_| |/ \ |_| | | |_) | (_) | (_) | |_
\___//_/\_\____| |____/ \___/ \___/ \__|
EOF
}
install() {
if is_installed; then
echo 'UXG-Boot is already installed.' >&2
return 1
fi
IMAGE_ID=$(podman image inspect --format '{{ .ID }}' "${LOCAL_IMAGE}")
IMAGE_VERSION=$(podman image inspect --format '{{ .Labels.version }}' "${LOCAL_IMAGE}")
if [[ "${IMAGE_VERSION}" == '<no value>' ]]; then
echo "Unable to determine version of '${LOCAL_IMAGE}'" >&2
return 1
fi
echo "Updating ${LOCAL_IMAGE} (${IMAGE_ID}) to ${REMOTE_IMAGE}:${IMAGE_VERSION}"
uxg-setup update "${REMOTE_IMAGE}:${IMAGE_VERSION}"
}
is_installed() {
podman image inspect --format '{{ range $k, $v := .RepoTags }}{{ $v }}{{ "\n" }}{{ end }}' "${LOCAL_IMAGE}" 2>/dev/null | grep -q "${REMOTE_IMAGE}"
}
uninstall() {
if ! is_installed; then
echo 'UXG-Boot is not installed.' >&2
return 1
fi
echo "Stopping uxg-setup"
uxg-setup stop
for IMAGE in $(podman image list --quiet "${REMOTE_IMAGE}"); do
# NOTE: I am not sure why the image ID end with `false`.
IMAGE="${IMAGE%false}"
echo "Removing ${REMOTE_IMAGE} (${IMAGE})"
podman image rm --force "${IMAGE}"
done
echo "Resetting uxg-setup"
uxg-setup reset
}
header
depends_on ubnt-device-info
depends_on podman
if [[ $(ubnt-device-info family_short) != 'UXG' ]]; then
echo "Unsupported device: $(ubnt-device-info model)" >&2
exit 1
fi
if ! podman image exists "${LOCAL_IMAGE}"; then
echo "Image '${LOCAL_IMAGE}' not found." >&2
exit 1
fi
case "${1:-install}" in
install)
install
;;
uninstall)
uninstall
;;
*)
echo "Invalid command: ${1}" >&2
exit 1
;;
esac