-
Notifications
You must be signed in to change notification settings - Fork 45
/
install.sh
92 lines (74 loc) · 2.48 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
#!/usr/bin/env bash
set -euo pipefail
echo -e "Hello, we are gonna install the \033[33mlatest stable\033[39m version of Kool!"
DEFAULT_DOWNLOAD_URL="https://github.com/kool-dev/kool/releases/latest/download"
if [ -z "${DOWNLOAD_URL:-}" ]; then
DOWNLOAD_URL=$DEFAULT_DOWNLOAD_URL
fi
DEFAULT_BIN="/usr/local/bin/kool"
if [ -z "${BIN_PATH:-}" ]; then
BIN_PATH=$DEFAULT_BIN
fi
is_darwin() {
case "$(uname -s)" in
*darwin* ) true ;;
*Darwin* ) true ;;
* ) false;;
esac
}
do_install () {
ARCH=$(uname -m)
PLAT="linux"
if is_darwin; then
PLAT="darwin"
fi
if [ "$ARCH" == "x86_64" ]; then
ARCH="amd64"
fi
if [ "$ARCH" == "aarch64" ]; then
ARCH="arm64"
fi
echo "Downloading latest binary (kool-$PLAT-$ARCH)..."
# TODO: fallback to wget if no curl available
rm -f /tmp/kool_binary
curl -fsSL "$DOWNLOAD_URL/kool-$PLAT-$ARCH" -o /tmp/kool_binary
# check for running kool process which would prevent
# replacing existing version under Linux.
if [ command -v kool &> /dev/null ]; then
if [ ! is_darwin ]; then
running=$(ps aux | grep kool | grep -v grep | wc -l | awk '{ print $1 }')
if [ "$running" != "0" ]; then
echo -e "\033[31;31mThere is a kool process still running. You might need to stop them before we replace the current binary.\033[0m"
fi
fi
fi
echo -e "Moving kool binary to $BIN_PATH..."
if [ -w $(dirname $BIN_PATH) ]; then
mv -f /tmp/kool_binary $BIN_PATH
chmod +x $BIN_PATH
else
echo "(requires sudo)"
sudo mv -f /tmp/kool_binary $BIN_PATH
sudo chmod +x $BIN_PATH
fi
start_success="\033[0;32m"
end_success="\033[0m"
start_error="\033[1;31m"
end_error="\033[0m"
if ! command -v docker &> /dev/null; then
builtin echo -e "${start_error}We could not identify the Docker installed.${end_error}"
builtin echo -e "Please refer to the official documentation to get it: https://docs.docker.com/get-docker/"
exit
fi
composeVersion=$(docker compose version || true)
if [[ ! "$composeVersion" == *"Docker Compose version v2"* ]]; then
builtin echo -e "${start_error}We could not identify Composer V2 installed.${end_error}"
builtin echo -e "Please make sure you are running an updated Docker version that includes Compose V2:"
builtin echo -e " Official Docker installation documentation: https://docs.docker.com/get-docker/"
builtin echo -e " Official Docker Compose V2 documentation: https://docs.docker.com/compose/reference/"
exit
fi
# success
builtin echo -e "${start_success}$(kool -v) installed successfully.${end_success}"
}
do_install