install-neovim-from-release 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env bash
  2. set -eu pipefall
  3. declare -r LV_INSTALL_PREFIX="${INSTALL_PREFIX:-"$HOME/.local"}"
  4. declare -r RELEASE_VER="${RELEASE_VER:-latest}" # can be set to nightly
  5. declare ARCHIVE_NAME
  6. declare RELEASE_NAME
  7. declare OS
  8. OS="$(uname -s)"
  9. if [ "$OS" == "Linux" ]; then
  10. ARCHIVE_NAME="nvim-linux64"
  11. RELEASE_NAME="nvim-linux64"
  12. elif [ "$OS" == "Darwin" ]; then
  13. ARCHIVE_NAME="nvim-macos"
  14. # for some reason the archive has a different name
  15. RELEASE_NAME="nvim-osx64"
  16. else
  17. echo "$OS platform is not supported currently"
  18. exit 1
  19. fi
  20. declare -r RELEASE_URL="https://github.com/neovim/neovim/releases/$RELEASE_VER/download/$ARCHIVE_NAME.tar.gz"
  21. declare -r CHECKSUM_URL="$RELEASE_URL.sha256sum"
  22. DOWNLOAD_DIR="$(mktemp -d)"
  23. readonly DOWNLOAD_DIR
  24. RELEASE_SHA="$(curl -Ls "$CHECKSUM_URL" | awk '{print $1}')"
  25. readonly RELEASE_SHA
  26. function main() {
  27. if [ ! -d "$LV_INSTALL_PREFIX" ]; then
  28. mkdir -p "$LV_INSTALL_PREFIX" || __invalid__prefix__handler
  29. fi
  30. download_neovim
  31. verify_neovim
  32. install_neovim
  33. }
  34. function download_neovim() {
  35. echo "Downloading Neovim's binary from $RELEASE_VER release.."
  36. if ! curl --progress-bar --fail -L "$RELEASE_URL" -o "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz"; then
  37. echo "Download failed. Check that the release/filename are correct."
  38. exit 1
  39. fi
  40. echo "Download complete!"
  41. }
  42. function verify_neovim() {
  43. echo "Verifying the installation.."
  44. DOWNLOADED_SHA="$(openssl dgst -sha256 "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz" | awk '{print $2}')"
  45. if [ "$RELEASE_SHA" != "$DOWNLOADED_SHA" ]; then
  46. echo "Error! checksum mis-match."
  47. echo "Expected: $RELEASE_SHA but got: $DOWNLOADED_SHA"
  48. exit 1
  49. fi
  50. echo "Verification complete!"
  51. }
  52. function install_neovim() {
  53. echo "Installing Neovim.."
  54. pushd "$DOWNLOAD_DIR"
  55. tar -xzf "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz"
  56. popd
  57. # https://dev.to/ackshaey/macos-vs-linux-the-cp-command-will-trip-you-up-2p00
  58. cp -r "$DOWNLOAD_DIR/$RELEASE_NAME/." "$LV_INSTALL_PREFIX"
  59. echo "Installation complete!"
  60. echo "Now you can run $LV_INSTALL_PREFIX/bin/nvim"
  61. }
  62. function __invalid__prefix__handler() {
  63. echo "Error! Invalid value for LV_INSTALL_PREFIX: [$INSTALL_PREFIX]"
  64. echo "Please verify that the folder exists and re-run the installer!"
  65. exit 1
  66. }
  67. main "$@"