kitten 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/sh
  2. # Copyright (C) 2018 Kovid Goyal <kovid at kovidgoyal.net>
  3. #
  4. # Distributed under terms of the GPLv3 license.
  5. { \unalias command; \unset -f command; } >/dev/null 2>&1
  6. die() {
  7. if [ -e /dev/stderr ]; then
  8. printf "\033[31m%s\033[m\n\r" "$*" > /dev/stderr;
  9. elif [ -e /dev/fd/2 ]; then
  10. printf "\033[31m%s\033[m\n\r" "$*" > /dev/fd/2;
  11. else
  12. printf "\033[31m%s\033[m\n\r" "$*";
  13. fi
  14. exit 1;
  15. }
  16. exec_kitty() {
  17. [ -n "$kitty_exe" ] && exec "$kitty_exe" "$@"
  18. die "Failed to execute kitty"
  19. }
  20. script_path="$(command readlink -f "$0" 2> /dev/null)"
  21. [ $? = 0 ] || script_path="$0"
  22. script_dir="$(command dirname "$script_path")"
  23. install_dir="$(command dirname "$script_dir")/install-tool"
  24. remote_kitty_version_file="$script_dir/../version"
  25. local_kitty_version_file="$install_dir/installed-kitten-version"
  26. kitty_exe="$install_dir/kitten"
  27. local_kitty_version=""
  28. [ -f "$kitty_exe" -a -x "$kitty_exe" ] && exec_kitty "$@"
  29. # Use kitten from the downloaded kitty installation, if available.
  30. embed_exe="$(command dirname "$script_dir")/install/bin/kitten"
  31. [ -f "$embed_exe" -a -x "$embed_exe" ] && {
  32. kitty_exe="$embed_exe"
  33. exec_kitty "$@"
  34. }
  35. case "$(command uname)" in
  36. 'Linux') OS="linux";;
  37. 'Darwin') OS="darwin";;
  38. 'FreeBSD') OS="freebsd";;
  39. 'NetBSD') OS="netbsd";;
  40. 'OpenBSD') OS="openbsd";;
  41. 'DragonFlyBSD') OS="dragonfly";;
  42. *) die "kitten pre-built binaries are not available for the $(command uname) operating system";;
  43. esac
  44. if command -v curl 2> /dev/null > /dev/null; then
  45. fetch() {
  46. command curl -fL "$1"
  47. }
  48. fetch_quiet() {
  49. command curl -fsSL "$1"
  50. }
  51. elif command -v wget 2> /dev/null > /dev/null; then
  52. fetch() {
  53. command wget -O- "$1"
  54. }
  55. fetch_quiet() {
  56. command wget --quiet -O- "$1"
  57. }
  58. else
  59. die "Neither curl nor wget available, cannot download kitten"
  60. fi
  61. case "$(command uname -m)" in
  62. amd64|x86_64) arch="amd64";;
  63. aarch64*) arch="arm64";;
  64. armv8*) arch="arm64";;
  65. arm64) arch="arm64";;
  66. arm|armv7l) arch="arm";;
  67. i386) arch="386";;
  68. i686) arch="386";;
  69. *) die "Unknown CPU architecture $(command uname -m)";;
  70. esac
  71. url="https://github.com/kovidgoyal/kitty/releases/latest/download/kitten-$OS-$arch"
  72. printf "\033[33mkitten needs to be installed\033[m\n\n"
  73. command mkdir -p "$install_dir"
  74. printf "Downloading kitten from: \033[32m%s\033[m\n\n" "$url"
  75. download_dest="$(command mktemp "$kitty_exe.XXXXXXXXXX")"
  76. fetch "$url" > "$download_dest" || {
  77. command rm -f "$download_dest"
  78. die "Failed to download kitten"
  79. }
  80. command chmod 755 "$download_dest"
  81. command mv "$download_dest" "$kitty_exe"
  82. command "$kitty_exe" --version | cut -d" " -f2 > "$local_kitty_version_file"
  83. exec_kitty "$@"