forked from mintoolkit/mint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-slim.sh
executable file
·99 lines (85 loc) · 2.43 KB
/
install-slim.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
#!/usr/bin/env bash
function get_slim() {
local DIST=""
local EXT=""
local FILENAME=""
local KERNEL=""
local MACHINE=""
local TMP_DIR=""
local URL=""
local VER=""
# Get the current released tag_name
VER=$(curl -sL https://api.github.com/repos/docker-slim/docker-slim/releases \
| grep tag_name | head -n1 | cut -d'"' -f4)
if [ -n "${VER}" ]; then
URL="https://downloads.dockerslim.com/releases/${VER}"
else
echo "ERROR! Could not retrieve the current Slim version number."
exit 1
fi
# Get kernel name and machine architecture.
KERNEL=$(uname -s)
MACHINE=$(uname -m)
# Determine the target distrubution
if [ "${KERNEL}" == "Linux" ]; then
EXT="tar.gz"
if [ "${MACHINE}" == "x86_64" ]; then
DIST="linux"
elif [ "${MACHINE}" == "armv7l" ]; then
DIST="linux_arm"
elif [ "${MACHINE}" == "aarch64" ]; then
DIST="linux_arm64"
fi
elif [ "${KERNEL}" == "Darwin" ]; then
EXT="zip"
if [ "${MACHINE}" == "x86_64" ]; then
DIST="mac"
elif [ "${MACHINE}" == "arm64" ]; then
DIST="mac_m1"
fi
else
echo "ERROR! ${KERNEL} is not a supported platform."
exit 1
fi
# Was a known distribution detected?
if [ -z "${DIST}" ]; then
echo "ERROR! ${MACHINE} is not a supported architecture."
exit 1
fi
# Derive the filename
FILENAME="dist_${DIST}.${EXT}"
echo " - Downloading ${URL}/${FILENAME}"
TMP_DIR=$(mktemp -d)
curl -sLo "${TMP_DIR}/${FILENAME}" "${URL}/${FILENAME}"
echo " - Unpacking ${FILENAME}"
if [ "${EXT}" == "zip" ]; then
unzip -qq -o "${TMP_DIR}/${FILENAME}" -d "${TMP_DIR}"
elif [ "${EXT}" == "tar.gz" ]; then
tar -xf "${TMP_DIR}/${FILENAME}" --directory "${TMP_DIR}"
else
echo "ERROR! Unexpected file extension."
exit 1
fi
# /usr/local/bin should be present on Linux and macOS hosts. Just be sure.
if [ -d /usr/local/bin ]; then
echo " - Placing slim in /usr/local/bin"
mv "${TMP_DIR}/dist_${DIST}/slim" /usr/local/bin/
mv "${TMP_DIR}/dist_${DIST}/slim-sensor" /usr/local/bin/
chmod +x /usr/local/bin/slim
chmod +x /usr/local/bin/slim-sensor
echo " - Cleaning up"
rm -rf "${TMP_DIR}"
echo -en " - "
slim --version
else
echo "ERROR! /usr/local/bin is not present. Install aborted."
rm -rf "${TMP_DIR}"
exit 1
fi
}
echo "Slim scripted install"
if [ "$(id -u)" -ne 0 ]; then
echo "ERROR! You must run this script as root."
exit 1
fi
get_slim