2018-06-01 08:01:52 +03:00
|
|
|
#!/bin/sh
|
|
|
|
# Copyright (C) 2018 Kovid Goyal <kovid at kovidgoyal.net>
|
|
|
|
#
|
|
|
|
# Distributed under terms of the GPLv3 license.
|
2021-09-29 05:38:29 +03:00
|
|
|
|
2022-04-04 11:12:20 +03:00
|
|
|
{ \unalias command; \unset -f command; } >/dev/null 2>&1
|
|
|
|
tdir=''
|
|
|
|
cleanup() {
|
|
|
|
[ -n "$tdir" ] && {
|
|
|
|
command rm -rf "$tdir"
|
|
|
|
tdir=''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
die() {
|
|
|
|
cleanup
|
|
|
|
printf "\033[31m%s\033[m\n\r" "$*" > /dev/stderr;
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
detect_network_tool() {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
detect_os() {
|
|
|
|
arch=""
|
|
|
|
case "$(command uname)" in
|
|
|
|
'Darwin') OS="macos";;
|
|
|
|
'Linux')
|
|
|
|
OS="linux"
|
|
|
|
case "$(command uname -m)" in
|
|
|
|
x86_64) arch="x86_64";;
|
|
|
|
aarch64*) arch="arm64";;
|
|
|
|
armv8*) arch="arm64";;
|
|
|
|
i386) arch="i686";;
|
|
|
|
i686) arch="i686";;
|
|
|
|
*) die "Unknown CPU architecture $(command uname -m)";;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*) die "kitty binaries are not available for $(command uname)"
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
expand_tilde() {
|
|
|
|
tilde_less="${1#\~/}"
|
|
|
|
[ "$1" != "$tilde_less" ] && tilde_less="$HOME/$tilde_less"
|
|
|
|
printf '%s' "$tilde_less"
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_args() {
|
|
|
|
dest='~/.local'
|
2022-04-05 13:38:24 +03:00
|
|
|
[ "$OS" = "macos" ] && dest="/Applications"
|
2022-04-04 11:12:20 +03:00
|
|
|
launch='y'
|
|
|
|
installer=''
|
|
|
|
while :; do
|
|
|
|
case "$1" in
|
|
|
|
dest=*) dest="${1#*=}";;
|
|
|
|
launch=*) launch="${1#*=}";;
|
|
|
|
installer=*) installer="${1#*=}";;
|
|
|
|
"") break;;
|
|
|
|
*) die "Unrecognized command line option: $1";;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
dest=$(expand_tilde "${dest}")
|
|
|
|
[ "$launch" != "y" -a "$launch" != "n" ] && die "Unrecognized command line option: launch=$launch"
|
|
|
|
dest="$dest/kitty.app"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
get_file_url() {
|
|
|
|
url="https://github.com/kovidgoyal/kitty/releases/download/$1/kitty-$2"
|
|
|
|
if [ "$OS" = "macos" ]; then
|
|
|
|
url="$url.dmg"
|
|
|
|
else
|
|
|
|
url="$url-$arch.txz"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
get_release_url() {
|
|
|
|
release_version=$(fetch_quiet "https://sw.kovidgoyal.net/kitty/current-version.txt")
|
|
|
|
[ $? -ne 0 -o -z "$release_version" ] && die "Could not get kitty latest release version"
|
|
|
|
get_file_url "v$release_version" "$release_version"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
get_nightly_url() {
|
|
|
|
get_file_url "nightly" "nightly"
|
|
|
|
}
|
|
|
|
|
|
|
|
get_download_url() {
|
|
|
|
installer_is_file="n"
|
|
|
|
case "$installer" in
|
|
|
|
"nightly") get_nightly_url ;;
|
|
|
|
"") get_release_url ;;
|
|
|
|
*) installer_is_file="y" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2023-03-02 11:43:34 +03:00
|
|
|
download_installer() {
|
2022-04-04 11:12:20 +03:00
|
|
|
tdir=$(command mktemp -d "/tmp/kitty-install-XXXXXXXXXXXX")
|
|
|
|
[ "$installer_is_file" != "y" ] && {
|
|
|
|
printf '%s\n\n' "Downloading from: $url"
|
2023-03-02 11:43:34 +03:00
|
|
|
if [ "$OS" = "macos" ]; then
|
|
|
|
installer="$tdir/kitty.dmg"
|
|
|
|
else
|
|
|
|
installer="$tdir/kitty.txz"
|
|
|
|
fi
|
2022-04-04 11:12:20 +03:00
|
|
|
fetch "$url" > "$installer" || die "Failed to download: $url"
|
2023-03-02 11:43:34 +03:00
|
|
|
installer_is_file="y"
|
2022-04-04 11:12:20 +03:00
|
|
|
}
|
2023-03-02 11:43:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
linux_install() {
|
2022-04-04 11:12:20 +03:00
|
|
|
command mkdir "$tdir/mp"
|
2023-03-02 11:43:34 +03:00
|
|
|
command tar -C "$tdir/mp" "-xJof" "$installer" || die "Failed to extract kitty tarball"
|
|
|
|
printf "%s\n" "Installing to $dest"
|
|
|
|
command rm -rf "$dest" || die "Failed to delete $dest"
|
|
|
|
command mv "$tdir/mp" "$dest" || die "Failed to move kitty.app to $dest"
|
2022-04-04 11:12:20 +03:00
|
|
|
}
|
|
|
|
|
2023-03-02 11:43:34 +03:00
|
|
|
macos_install() {
|
|
|
|
command mkdir "$tdir/mp"
|
|
|
|
command hdiutil attach "$installer" "-mountpoint" "$tdir/mp" || die "Failed to mount kitty.dmg"
|
2022-04-04 11:12:20 +03:00
|
|
|
printf "%s\n" "Installing to $dest"
|
|
|
|
command rm -rf "$dest"
|
|
|
|
command mkdir -p "$dest" || die "Failed to create the directory: $dest"
|
2023-03-02 11:43:34 +03:00
|
|
|
command ditto -v "$tdir/mp/kitty.app" "$dest"
|
|
|
|
rc="$?"
|
|
|
|
command hdiutil detach "$tdir/mp"
|
|
|
|
[ "$rc" != "0" ] && die "Failed to copy kitty.app from mounted dmg"
|
2022-04-04 11:12:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
exec_kitty() {
|
|
|
|
if [ "$OS" = "macos" ]; then
|
2022-04-05 13:38:24 +03:00
|
|
|
exec "open" "$dest"
|
2022-04-04 11:12:20 +03:00
|
|
|
else
|
|
|
|
exec "$dest/bin/kitty" "--detach"
|
|
|
|
fi
|
|
|
|
die "Failed to launch kitty"
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
|
|
|
detect_os
|
|
|
|
parse_args "$@"
|
|
|
|
detect_network_tool
|
|
|
|
get_download_url
|
2023-03-02 11:43:34 +03:00
|
|
|
download_installer
|
2022-04-04 11:12:20 +03:00
|
|
|
if [ "$OS" = "macos" ]; then
|
|
|
|
macos_install
|
|
|
|
else
|
|
|
|
linux_install
|
|
|
|
fi
|
2023-03-02 11:43:34 +03:00
|
|
|
cleanup
|
2022-04-04 11:12:20 +03:00
|
|
|
[ "$launch" = "y" ] && exec_kitty
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|