install-neovim-from-release 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. if [[ "${RELEASE_VER}" == "latest" ]]; then
  21. declare -r RELEASE_URL="https://github.com/neovim/neovim/releases/${RELEASE_VER}/download/${ARCHIVE_NAME}.tar.gz"
  22. else
  23. declare -r RELEASE_URL="https://github.com/neovim/neovim/releases/download/${RELEASE_VER}/${ARCHIVE_NAME}.tar.gz"
  24. fi
  25. declare -r CHECKSUM_URL="$RELEASE_URL.sha256sum"
  26. DOWNLOAD_DIR="$(mktemp -d)"
  27. readonly DOWNLOAD_DIR
  28. RELEASE_SHA="$(curl -Ls "$CHECKSUM_URL" | awk '{print $1}')"
  29. readonly RELEASE_SHA
  30. function main() {
  31. if [ ! -d "$LV_INSTALL_PREFIX" ]; then
  32. mkdir -p "$LV_INSTALL_PREFIX" || __invalid__prefix__handler
  33. fi
  34. download_neovim
  35. verify_neovim
  36. install_neovim
  37. }
  38. function download_neovim() {
  39. echo "Downloading Neovim's binary from $RELEASE_VER release.."
  40. if ! curl --progress-bar --fail -L "$RELEASE_URL" -o "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz"; then
  41. echo "Download failed. Check that the release/filename are correct."
  42. exit 1
  43. fi
  44. echo "Download complete!"
  45. }
  46. function verify_neovim() {
  47. echo "Verifying the installation.."
  48. DOWNLOADED_SHA="$(openssl dgst -sha256 "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz" | awk '{print $2}')"
  49. if [ "$RELEASE_SHA" != "$DOWNLOADED_SHA" ]; then
  50. echo "Error! checksum mismatch."
  51. echo "Expected: $RELEASE_SHA but got: $DOWNLOADED_SHA"
  52. exit 1
  53. fi
  54. echo "Verification complete!"
  55. }
  56. function install_neovim() {
  57. echo "Installing Neovim.."
  58. pushd "$DOWNLOAD_DIR"
  59. tar -xzf "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz"
  60. popd
  61. if [ ! -d "$DOWNLOAD_DIR/$RELEASE_NAME" ]; then
  62. # fallback to archive name
  63. RELEASE_NAME="$ARCHIVE_NAME"
  64. fi
  65. # https://dev.to/ackshaey/macos-vs-linux-the-cp-command-will-trip-you-up-2p00
  66. cp -r "$DOWNLOAD_DIR/$RELEASE_NAME/." "$LV_INSTALL_PREFIX"
  67. echo "Installation complete!"
  68. echo "Now you can run $LV_INSTALL_PREFIX/bin/nvim"
  69. }
  70. function __invalid__prefix__handler() {
  71. echo "Error! Invalid value for LV_INSTALL_PREFIX: [$INSTALL_PREFIX]"
  72. echo "Please verify that the folder exists and re-run the installer!"
  73. exit 1
  74. }
  75. main "$@"