1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
#!/bin/sh
# Copyright (C) 2018 Kovid Goyal <kovid at kovidgoyal.net>
#
# Distributed under terms of the GPLv3 license.
{ \unalias command; \unset -f command; } >/dev/null 2>&1
die() { printf "\033[31m%s\033[m\n\r" "$*" > /dev/stderr; exit 1; }
delete_lock_dir() {
trap '' EXIT INT QUIT TERM
[ -n "$lock_dir" ] && {
command rm -rf "$lock_dir"
lock_dir=""
}
}
exec_kitty() {
delete_lock_dir
[ -n "$kitty_exe" ] && exec "$kitty_exe" "$@"
die "Failed to execute kitty"
}
is_wrapped_kitten() {
wrapped_kittens="clipboard icat hyperlinked_grep ask hints unicode_input ssh themes diff show_key transfer query_terminal choose-files"
[ -n "$1" ] && {
case " $wrapped_kittens " in
*" $1 "*) printf "%s" "$1" ;;
esac
}
}
test "(" "$1" = "+kitten" -a -n "$(is_wrapped_kitten "$2")" ")" -o "(" "$1" = "+" -a "$2" = "kitten" -a "$(is_wrapped_kitten "$3")" ")" && {
if [ "$1" = "+kitten" ]; then shift "1"; else shift "2"; fi
exec kitten "$@"
}
lock_dir=""
script_path="$(command readlink -f "$0" 2> /dev/null)"
[ $? = 0 ] || script_path="$0"
script_dir="$(command dirname "$script_path")"
install_dir="$(command dirname "$script_dir")/install"
remote_kitty_version_file="$script_dir/../version"
local_kitty_version_file="$install_dir/installed-kitty-version"
kitty_exe="$install_dir/bin/kitty"
local_kitty_version=""
[ -f "$kitty_exe" -a -x "$kitty_exe" -a "$1" != "+update-kitty" ] && exec_kitty "$@"
case "$(command uname)" in
'Linux') OS="linux";;
'Darwin') OS="macos";;
*) die "kitty pre-built binaries are not available for the $(command uname) operating system";;
esac
if command -v curl 2> /dev/null > /dev/null; then
fetch() {
command curl -fL "$1"
}
fetch_quiet() {
command curl -fsSL "$1"
}
elif command -v wget 2> /dev/null > /dev/null; then
fetch() {
command wget -O- "$1"
}
fetch_quiet() {
command wget --quiet -O- "$1"
}
else
die "Neither curl nor wget available, cannot download kitty"
fi
if [ "$OS" = "linux" ]; then
case "$(command uname -m)" in
amd64|x86_64) arch="x86_64";;
aarch64*) arch="arm64";;
armv8*) arch="arm64";;
arm64) arch="arm64";;
i386) arch="i686";;
i686) arch="i686";;
*) die "Unknown CPU architecture $(command uname -m)";;
esac
fi
release_version=$(fetch_quiet "https://sw.kovidgoyal.net/kitty/current-version.txt")
[ $? -ne 0 -o -z "$release_version" ] && {
[ -n "$local_kitty_version" ] && exec_kitty "$@"
die "Could not get kitty latest release version"
}
if [ "$OS" = "linux" ]; then
url="https://github.com/kovidgoyal/kitty/releases/download/v$release_version/kitty-$release_version-$arch.txz"
else
url="https://github.com/kovidgoyal/kitty/releases/download/v$release_version/kitty-$release_version.dmg"
fi
lock_dir="$script_dir/kitty-install-lock"
if ! command mkdir "$lock_dir" 2> /dev/null; then
ed="$lock_dir"
lock_dir="";
die "Failed to create lock dir another instance of the kitty bootstrap script is running. If you are sure that is not the case delete: $ed";
fi
trap 'delete_lock_dir' EXIT INT QUIT TERM
printf "\033[33mkitty needs to be installed\033[m\n\n"
command rm -rf "$install_dir"
command mkdir -p "$install_dir"
printf "Downloading kitty from: \033[32m%s\033[m\n\n" "$url"
if [ "$OS" = "linux" ]; then
old_umask=$(umask)
umask 000
fetch "$url" | command tar -C "$install_dir" -xJof -
umask "$old_umask"
[ $? = 0 ] || die "Failed to download and install kitty"
else
tdir=$(command mktemp -d "$install_dir/tmp-for-dmg-XXXXXXXXXXXX")
[ $? = 0 ] || die "Creating temp directory failed"
fetch "$url" > "$tdir/kitty.dmg"
command mkdir "$tdir/mp"
command hdiutil attach "$tdir/kitty.dmg" "-mountpoint" "$tdir/mp" || die "Failed to mount kitty.dmg"
command ditto -v "$tdir/mp/kitty.app" "$install_dir/kitty.app"
rc="$?"
command hdiutil detach "$tdir/mp"
command rm -rf "$tdir"
[ "$rc" != "0" ] && die "Failed to copy kitty.app from mounted dmg"
command mkdir "$install_dir/bin"
command ln -sf "$install_dir/kitty.app/Contents/MacOS/kitty" "$install_dir/bin/kitty"
fi
command "$kitty_exe" +runpy "from kitty.constants import str_version; print(end=str_version)" > "$local_kitty_version_file"
exec_kitty "$@"
|