/
install.sh
executable file
·97 lines (91 loc) · 2.68 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
#!/bin/bash
#
# _________ __
# / ____/ (_)___ / /_
# / /_ / / / __ \/ __/
# / __/ / / / /_/ / /_
# /_/ /_/_/ .___/\__/
# /_/
#
# Flipt installer
#
# Usage:
# curl -fsSL https://github.com/flipt-io/flipt/raw/main/install.sh | sh
set -e
file_issue_prompt() {
echo "If you wish us to support your platform, please file an issue"
echo "https://github.com/flipt-io/flipt/issues/new"
exit 1
}
get_latest_version() {
local res=$(curl -fsSL https://api.github.com/repos/flipt-io/flipt/releases/latest | grep tag_name | cut -d '"' -f 4)
echo "$res"
}
copy() {
if [[ ":$PATH:" == *":$HOME/.local/bin:"* ]]; then
if [ ! -d "$HOME/.local/bin" ]; then
mkdir -p "$HOME/.local/bin"
fi
mv /tmp/flipt "$HOME/.local/bin/flipt"
else
# Try without sudo first, run with sudo only if mv failed without it.
mv /tmp/flipt /usr/local/bin/flipt || (
echo "Cannot write to installation target directory as current user, writing as root."
sudo mv /tmp/flipt /usr/local/bin/flipt
)
fi
}
# This function decides what version will be installed based on the following priority:
# 1. Environment variable `VERSION` is set.
# 2. Latest available on GitHub
function get_version() {
if [[ -z "$VERSION" ]]; then
if [[ -n "$1" ]]; then
VERSION="$1"
else
VERSION=$(get_latest_version)
fi
fi
# ensure version starts with v
if [[ "$VERSION" != v* ]]; then
VERSION="v$VERSION"
fi
echo "$VERSION"
}
function install() {
local version=$(get_version $1);
echo "Installing version $version"
if [[ "$OSTYPE" == "linux"* ]]; then
ARCH=$(uname -m);
OS="linux";
if [[ "$ARCH" != "x86_64" && "$ARCH" != "aarch64" ]]; then
echo "flipt is only available for linux x86_64/arm64 architecture"
file_issue_prompt
fi
if [[ "$ARCH" == "aarch64" ]]; then
ARCH="arm64"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
ARCH=$(uname -m);
OS="darwin";
if [[ "$ARCH" != "arm64" ]]; then
echo "flipt is only available for mac arm64 architecture"
file_issue_prompt
fi
else
echo "flipt isn't supported for your platform - $OSTYPE"
file_issue_prompt
fi
curl -o /tmp/flipt.tar.gz -fsSL https://download.flipt.io/flipt/$version/$OS\_$ARCH.tar.gz
tar -xzf /tmp/flipt.tar.gz -C /tmp
chmod +x /tmp/flipt
copy
echo ""
echo "Flipt installed!"
echo ""
echo "For feedback and support, join our Discord server: https://flipt.io/discord,"
echo "open an issue or discussion on GitHub: https://github.com/flipt-io/flipt/"
echo "or send us an email at [email protected]"
echo ""
}
install "$1"