install-neovim-from-release 2.6 KB

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