forked from michaelb/sniprun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·92 lines (77 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
#!/usr/bin/env bash
echo "Runnning Sniprun Installer"
local_version=v$(cat Cargo.toml | grep version | cut -d "\"" -f 2)
name="sniprun"
force_build=$1
cargo_build() {
if command -v cargo >/dev/null; then
echo "Building..."
cargo build --release &>/dev/null
echo "Done"
return 0
else
echo "Could not find cargo in \$PATH: the Rust toolchain is required to build Sniprun"
return 1
fi
}
get_latest_release() {
curl --silent "https://api.github.com/repos/michaelb/sniprun/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
download() {
# command -v curl >/dev/null &&
# curl --fail --location "$1" --output target/release/sniprun
echo "Downloading" $1
# curl -s https://api.github.com/repos/michaelb/sniprun/releases/$1 | grep "sniprun" | cut -d ":" -f 2,3 | tr -d \" | wget -qi -
wget -q https://github.com/michaelb/sniprun/releases/download/v0.4.9/sniprun
mkdir -p target/release/
mv -f sniprun target/release/
}
fetch_prebuilt_binary() {
mkdir -p target/release
if (download $1); then
chmod a+x target/release/sniprun
echo "Done"
return 0
else
return 1
fi
}
arch=$(uname)
if [ $arch != "Linux" ]; then
echo "Looks you are not running Linux: Mac users have to compile sniprun themselves and thus need the Rust toolchain"
force_build=1
fi
remote_version=$(get_latest_release)
if [ $force_build ]; then
echo "Compiling sniprun locally:"
neovim_version=$(nvim --version | head -n 1 | cut -d . -f 2) # 4 -> neovim 0.4.x
if [ $neovim_version == "4" ]; then
echo "Sniprun 0.4.9 is the highest version supported on neovim 0.4.x"
git reset --hard v0.4.9
fi
cargo_build
else
tag_to_fetch=$remote_version
neovim_version=$(nvim --version | head -n 1 | cut -d . -f 2) # 4 -> neovim 0.4.x
if [ $neovim_version == "4" ]; then
echo "Sniprun 0.4.9 is the highest version supported on neovim 0.4.x"
git reset --hard v0.4.9
tag_to_fetch="v0.4.9"
fi
#check if release is up to date
success=1
if [ $local_version == $remote_version ]; then
echo "Trying to get a up-to-date precompiled binary"
fetch_prebuilt_binary $tag_to_fetch
success=$?
else
echo "Release version is not up to date, building from source"
cargo_build
success=$?
fi
# if nothing succeeded
if [ $success == 1 ]; then
echo "Could not build (missing rust/cargo toolchain?). Getting an out-of-date release if available"
fetch_prebuilt_binary $tag_to_fetch # get an older release
fi
fi