-
-
Notifications
You must be signed in to change notification settings - Fork 431
/
Copy path00-podman.sh
executable file
·115 lines (100 loc) · 2.59 KB
/
00-podman.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
if which unifi-os >/dev/null 2>&1; then
echo 'Cowardly refusing to install on UDM 1.x'
exit 1
fi
udm_model() {
case "$(ubnt-device-info model || true)" in
"UniFi Dream Machine SE")
echo "udmse"
;;
"UniFi Dream Machine Pro")
echo "udmpro"
;;
"UniFi Dream Machine")
echo "udm"
;;
"UniFi Dream Router")
echo "udr"
;;
*)
echo "unknown"
;;
esac
}
DESIRED_ZIPFILE='udmse-podman-install.zip'
case "$(udm_model)" in
udmse | udmpro)
DESIRED_ZIPFILE="$(udm_model)-podman-install.zip"
;;
udm)
# base UDM works fine with udmpro podman version, but has issues with udmse variant
DESIRED_ZIPFILE="udmpro-podman-install.zip"
;;
*)
# shrug
# udmse-podman-install.zip seems to work fine on UDM 2.4.x
true
;;
esac
# Get DataDir location
DATA_DIR="/data"
case "$(ubnt-device-info firmware || true)" in
1*)
DATA_DIR="/mnt/data"
;;
2* | 3* | 4*)
DATA_DIR="/data"
;;
*)
echo "ERROR: No persistent storage found." 1>&2
exit 1
;;
esac
CACHE_DIR="${DATA_DIR}/podman/cache"
INSTALL_ROOT="${DATA_DIR}/podman/install"
CONF_DIR="${DATA_DIR}/podman/conf"
mkdir -p "${CACHE_DIR}" "${INSTALL_ROOT}" "${CONF_DIR}"
URL="https://unifi.boostchicken.io/${DESIRED_ZIPFILE}"
if [ "$1" = '--download-only' ]; then
echo "downloading ${URL}" &&
curl -Lsfo "${CACHE_DIR}/${DESIRED_ZIPFILE}" "${URL}" &&
echo "downloaded ${URL}"
exit $?
fi
if podman version >/dev/null 2>&1; then
if [ "$1" = '--force' ]; then
echo 'overwriting existing podman install (--force)'
else
echo 'podman is already installed; skipping'
exit 0
fi
fi
if [ -f "${CACHE_DIR}/${DESIRED_ZIPFILE}" ]; then
echo "(using cache at ${CACHE_DIR}/${DESIRED_ZIPFILE})"
elif echo "downloading ${URL}" &&
curl -Lsfo "${CACHE_DIR}/${DESIRED_ZIPFILE}" "${URL}"; then
echo "downloaded ${URL}"
else
echo 'download failed'
exit 1
fi
unzip -o "${CACHE_DIR}/${DESIRED_ZIPFILE}" -d "${CACHE_DIR}" >/dev/null
unzip -o "${CACHE_DIR}/podman-install.zip" -d "${INSTALL_ROOT}" >/dev/null
rm -f "${CACHE_DIR}/podman-install.zip"
for SOURCE in $(find "${INSTALL_ROOT}" -not -type d); do
TARGET="$(expr "${SOURCE}" : "${INSTALL_ROOT}\(.*\)")"
mkdir -p "$(dirname "${TARGET}")"
ln -sf "${SOURCE}" "${TARGET}"
done
# fix missing config files
for CONFIG in $(cd "${CONF_DIR}" && echo *); do
[ -e "${CONF_DIR}/${CONFIG}" ] || continue
ln -sf "${CONF_DIR}/${CONFIG}" "/etc/containers/${CONFIG}"
done
if podman version >/dev/null 2>&1; then
echo "podman $(podman version -f '{{.Client.Version}}') was installed successfully"
exit 0
fi
echo 'Something went wrong'
exit 1