-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2950121
commit 725caae
Showing
2 changed files
with
41 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,69 @@ | ||
#!/usr/bin/env bash | ||
#!/bin/sh | ||
|
||
|
||
echo "Runnning Sniprun Installer" | ||
local_version=v$(cat Cargo.toml | grep ^version | cut -d "\"" -f 2) | ||
arch=$(uname) | ||
name="sniprun" | ||
force_build=$1 | ||
local_version="v$(grep "^version" Cargo.toml | cut -d '"' -f 2)" | ||
|
||
if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then | ||
force_build=1 | ||
fi | ||
|
||
echo "Runnning $name Installer" | ||
|
||
cargo_build() { | ||
if command -v cargo >/dev/null; then | ||
echo "Building sniprun from source..." | ||
cargo build --release &>/dev/null | ||
echo "Done (status: $?)" | ||
return 0 | ||
echo "Building $name from source..." | ||
cargo build --release >/dev/null 2>&1 | ||
status="$?" | ||
# if download failed | ||
if [ "$status" != 0 ]; then | ||
echo "Failed to build (exit code: $status)" | ||
else | ||
echo "Could not find cargo in \$PATH: the Rust toolchain is required to build Sniprun" | ||
return 1 | ||
echo "Done" | ||
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 the sniprun binary (of the specified version) from Releases | ||
download() { | ||
echo "Downloading sniprun binary: " $1 | ||
curl -fsSL https://github.com/michaelb/sniprun/releases/download/$1/sniprun --output sniprun | ||
mkdir -p target/release/ | ||
mv -f sniprun target/release/ | ||
} | ||
|
||
# call download, make executable, and return status | ||
fetch_prebuilt_binary() { | ||
if (download $1); then | ||
chmod a+x target/release/sniprun | ||
echo "Done" | ||
return 0 | ||
echo "Downloading $name binary: $1" | ||
mkdir -p target/release/ | ||
curl -fsSL "https://github.com/michaelb/sniprun/releases/download/$1/sniprun" --output target/release/sniprun | ||
status="$?" | ||
chmod a+x target/release/sniprun | ||
# if download failed | ||
if [ $status != 0 ]; then | ||
echo "Failed to download $name, check your network or build locally (exit code: $status)" | ||
else | ||
return 1 | ||
echo "Done" | ||
fi | ||
} | ||
|
||
arch=$(uname) | ||
if [[ $arch != "Linux" && $force_build != 1 ]]; then | ||
echo "Looks you are not running Linux: Mac users have to compile sniprun themselves and thus need the Rust toolchain" | ||
if [ "$arch" != "Linux" ] && [ "$force_build" != 1 ]; then | ||
echo "Looks you are not running Linux: $name will be compiled from source, make sure to have the Rust toolchain installed" | ||
force_build=1 | ||
if ! command -v cargo >/dev/null; then | ||
echo "Could not find cargo in \$PATH: the Rust toolchain is required to build $name" | ||
exit 1 | ||
fi | ||
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" | ||
neovim_version=$(nvim --version | head -n 1 | cut -d . -f 2) # 4 -> neovim 0.4.x | ||
if [ "$force_build" ]; then | ||
if [ "$neovim_version" = "4" ]; then | ||
echo "$name 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" | ||
if [ "$neovim_version" = "4" ]; then | ||
echo "$name 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 | ||
|
||
fetch_prebuilt_binary $tag_to_fetch | ||
success=$? | ||
|
||
# if download failed | ||
if [ $success == 1 ]; then | ||
echo "Failed to download sniprun, check your network or build locally?" | ||
fi | ||
fetch_prebuilt_binary "$tag_to_fetch" | ||
fi | ||
|
||
|