-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·105 lines (86 loc) · 2.69 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
102
103
104
105
#!/usr/bin/env bash
# Based on https://github.com/CircleCI-Public/github-cli-orb/blob/main/src/scripts/install.sh
set_sudo() {
if [[ $EUID == 0 ]]; then
echo ""
else
echo "sudo"
fi
}
# Function to check if a version is greater than or equal to a given version
version_ge() {
test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"
}
# Function to check if a version is less than or equal to a given version
version_le() {
test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" == "$1"
}
detect_platform() {
case "$(uname -s)-$(uname -m)" in
"Linux-x86_64") echo "linux-amd64" ;;
"Linux-aarch64") echo "linux-arm64" ;;
*) echo "unsupported" ;;
esac
}
download_cc_cli() {
local version=$1
local platform=$2
local file_extension=$3
local download_url="https://github.com/codecomet-io/cli/releases/download/v${version}/codecomet-v${version}-${platform}.${file_extension}"
echo "Downloading the CodeComet CLI from \"$download_url\"..."
if ! curl -sSL "$download_url" -o "cc-cli.$file_extension"; then
echo "Failed to download CodeComet CLI from $download_url" >&2
return 1
fi
}
install_cc_cli() {
local platform=$1
local file_extension=$2
local file_path="cc-cli.$file_extension"
if [ ! -f "$file_path" ]; then
echo "Downloaded file $file_path does not exist." >&2
return 1
fi
echo "Installing the CodeComet CLI..."
set -x; $sudo tar -xzvf "$file_path" -C /usr/local/bin ; set +x
}
sudo=$(set_sudo)
# Check for required commands
for cmd in curl tar; do
if ! command -v "$cmd" &>/dev/null; then
echo "Error: $cmd is required. Please install it and try again." >&2
exit 1
fi
done
# Verify if the CLI is already installed. Exit if it is.
if command -v codecomet >/dev/null 2>&1; then
echo "CodeComet CLI is already installed."
exit 0
fi
version=$1
platform=$(detect_platform)
if [ "$platform" == "unsupported" ]; then
echo "$(uname -a)-$(uname -m) is not supported. If you believe it should be, please consider opening an issue."
exit 1
fi
file_extension="tar.gz"
# Download and install CodeComet CLI
if ! download_cc_cli "$version" "$platform" "$file_extension"; then
echo "Failed to download the CodeComet CLI."
exit 1
fi
if ! install_cc_cli "$platform" "$file_extension"; then
echo "Failed to install the CodeComet CLI."
exit 1
fi
# Clean up
if ! rm "cc-cli.$file_extension"; then
echo "Failed to remove the downloaded file."
fi
# Verify installation
if ! command -v codecomet >/dev/null 2>&1; then
echo "Something went wrong installing the CodeComet CLI. Please try again or open an issue."
exit 1
else
codecomet -h
fi