-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathinstall.sh
executable file
·71 lines (62 loc) · 1.71 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
#!/usr/bin/env bash
set -u
REPO=https://github.com/liuchengxu/vim-clap
APP=maple
exists() {
command -v "$1" >/dev/null 2>&1
}
download() {
local from=$1
local to=$2
if exists "curl"; then
curl -fLo "$to" "$from"
elif exists 'wget'; then
wget --output-document="$to" "$from"
else
echo 'curl or wget is required'
exit 1
fi
}
remote_latest_tag() {
git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags "$REPO" 'v0.*' \
| tail --lines=1 \
| awk -F "/" '{print $NF}'
}
try_download() {
local remote_latest_tag=$(remote_latest_tag)
echo "bin/$APP is empty, try downloading the latest prebuilt binary $APP $remote_latest_tag from GitHub ..."
local DOWNLOAD_URL="$REPO/releases/download/$remote_latest_tag"
local asset=$1
if [ -z "${TMPDIR+x}" ]; then
rm -f bin/$APP
download "$DOWNLOAD_URL/$asset" bin/$APP
else
local temp=${TMPDIR}/maple
download "$DOWNLOAD_URL/$asset" "$temp"
mv "$temp" bin/$APP
fi
chmod a+x "bin/$APP"
}
download_prebuilt_binary() {
arch=$(uname -sm)
case "${arch}" in
"Linux x86_64")
try_download "$APP"-x86_64-unknown-linux-musl ;;
"Linux aarch64")
try_download "$APP"-aarch64-unknown-linux-musl ;;
"Darwin x86_64")
try_download "$APP"-x86_64-apple-darwin ;;
"Darwin arm64")
try_download "$APP"-aarch64-apple-darwin ;;
*)
echo "No prebuilt maple binary available for this platform ${arch}."
echo "You can compile the binary locally by running `make` or `cargo build --release` if Rust has been installed."
exit 1
;;
esac
}
if [ ! -f "bin/$APP" ]; then
download_prebuilt_binary
else
"bin/$APP" upgrade
fi