-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.sh
executable file
·141 lines (119 loc) · 3.4 KB
/
get.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env bash
# helper functions
yell() { echo -e "${RED}FAILED> $* ${NC}" >&2; }
die() { yell "$*"; exit 1; }
try() { "$@" || die "failed executing: $*"; }
log() { echo -e "--> $*"; }
maybe_sudo() { $([ $NEED_SUDO ] && echo sudo) "$@"; }
# console colors
RED='\033[0;31m'
GREEN='\033[0;32m'
PURPLE='\033[0;35m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
NC='\033[0m'
# basic variables
INSTALL_PATH=${INSTALL_PATH:-"/usr/local/bin"}
NEED_SUDO=${NEED_SUDO:-1}
REPO="nhost/mcp-nhost"
# check for existing installation
hasCli=$(which mcp-nhost)
if [ "$?" = "0" ]; then
log ""
log "${GREEN}You already have mcp-nhost at '${hasCli}'${NC}"
export n=3
log "${YELLOW}Downloading again in $n seconds... Press Ctrl+C to cancel.${NC}"
log ""
sleep $n
fi
# check for curl
hasCurl=$(which curl)
if [ "$?" = "1" ]; then
die "You need to install curl to use this script."
fi
# get release version
release=${1:-latest}
log "Getting $release version..."
if [[ "$release" == "latest" ]]; then
version=$(curl --silent "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
else
version=$(curl --silent "https://api.github.com/repos/nhost/mcp-nhost/tags" | grep "name" | sed -E 's/.*"([^"]+)".*/\1/' | grep "^$release$")
fi
# check version exists
if [ ! $version ]; then
log "${YELLOW}"
log "Failed while attempting to install mcp-nhost. Please manually install:"
log ""
log "1. Open your web browser and go to https://github.com/$REPO/releases/latest"
log "2. Download mcp-nhost from latest release for your platform. Name it 'mcp-nhost'."
log "3. chmod +x ./mcp-nhost"
log "4. mv ./mcp-nhost /usr/local/bin/mcp-nhost"
log "${NC}"
die "exiting..."
fi
# show latest version
if [[ "$release" == "latest" ]]; then
log "Latest version is $version"
fi
# get platform
platform='unknown'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
platform='linux'
elif [[ "$unamestr" == 'Darwin' ]]; then
platform='darwin'
elif [[ "$unamestr" == 'Windows' ]]; then
platform='windows'
fi
# die for unknown platform
if [[ "$platform" == 'unknown' ]]; then
die "Unknown OS platform"
fi
# set arch
arch='unknown'
archstr=`uname -m`
if [[ "$archstr" == 'x86_64' ]]; then
arch='amd64'
elif [[ "$archstr" == 'arm64' || "$archstr" == 'aarch64' ]]; then
arch='arm64'
else
arch='386'
fi
# some variables
suffix="-${platform}-${arch}"
if [[ "$platform" != 'windows' ]]; then
extension=".tar.gz"
else
extension='.zip'
fi
# variables for install
targetFile="mcp-nhost-$version$suffix$extension"
url="https://github.com/${REPO}/releases/download/${version}/${targetFile}"
# remove previous download
if [ -e $targetFile ]; then
rm $targetFile
fi
# tell what we are downloading
log "${PURPLE}Downloading mcp-nhost ${version} for ${platform}-${arch} to ${targetFile}${NC}"
# download and extract files
try curl -L -f -o $targetFile "$url"
try chmod +x $targetFile
if [[ "$platform" != 'windows' ]]; then
try tar -xvf $targetFile
else
try unzip $targetFile
fi
try rm ./$targetFile
# install and test
log "${GREEN}Download complete!${NC}"
echo
if [[ "$platform" != 'windows' ]]; then
try sudo mv ./mcp-nhost ${INSTALL_PATH}/mcp-nhost
chmod +x ${INSTALL_PATH}/mcp-nhost
mcp-nhost --version
echo
log "${BLUE}Use mcp-nhost with: mcp-nhost --help${NC}"
else
echo "$platform is not supported yet."
exit 1
fi