bootstrap should not fail if no tty present
This commit is contained in:
parent
499b30d175
commit
603684211f
@ -4,16 +4,21 @@
|
|||||||
|
|
||||||
# read the transmitted data from STDIN
|
# read the transmitted data from STDIN
|
||||||
cleanup_on_bootstrap_exit() {
|
cleanup_on_bootstrap_exit() {
|
||||||
[ ! -z "$saved_tty_settings" ] && command stty "$saved_tty_settings"
|
[ -n "$saved_tty_settings" ] && command stty "$saved_tty_settings" 2> /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
die() { printf "\033[31m%s\033[m\n\r" "$*" > /dev/stderr; cleanup_on_bootstrap_exit; exit 1; }
|
die() { printf "\033[31m%s\033[m\n\r" "$*" > /dev/stderr; cleanup_on_bootstrap_exit; exit 1; }
|
||||||
dsc_to_kitty() { printf "\033P@kitty-$1|%s\033\\" "$(printf "%s" "$2" | base64 | tr -d \\n)" > /dev/tty; }
|
dsc_to_kitty() { printf "\033P@kitty-$1|%s\033\\" "$(printf "%s" "$2" | base64 | tr -d \\n)" > /dev/tty; }
|
||||||
debug() { dsc_to_kitty "print" "debug $1"; }
|
debug() { dsc_to_kitty "print" "debug $1"; }
|
||||||
echo_via_kitty() { dsc_to_kitty "echo" "$1"; }
|
echo_via_kitty() { dsc_to_kitty "echo" "$1"; }
|
||||||
saved_tty_settings=$(command stty -g)
|
saved_tty_settings=$(command stty -g 2> /dev/null < /dev/tty)
|
||||||
command stty raw min 1 time 0 -echo || die "stty not available"
|
tty_ok="n"
|
||||||
trap 'cleanup_on_bootstrap_exit' EXIT
|
[ -n "$saved_tty_settings" ] && tty_ok="y"
|
||||||
|
|
||||||
|
if [ "$tty_ok" = "y" ]; then
|
||||||
|
command stty raw min 1 time 0 -echo 2> /dev/null < /dev/tty || die "stty not available"
|
||||||
|
trap 'cleanup_on_bootstrap_exit' EXIT
|
||||||
|
fi
|
||||||
|
|
||||||
data_started="n"
|
data_started="n"
|
||||||
data_complete="n"
|
data_complete="n"
|
||||||
@ -31,7 +36,7 @@ fi
|
|||||||
# ensure $HOME is set
|
# ensure $HOME is set
|
||||||
if [ -z "$HOME" ]; then HOME=~; fi
|
if [ -z "$HOME" ]; then HOME=~; fi
|
||||||
# ensure $USER is set
|
# ensure $USER is set
|
||||||
if [ -z "$USER" ]; then USER=$(whoami); fi
|
if [ -z "$USER" ]; then USER=$(whoami 2> /dev/null); fi
|
||||||
|
|
||||||
# ask for the SSH data
|
# ask for the SSH data
|
||||||
data_password="DATA_PASSWORD"
|
data_password="DATA_PASSWORD"
|
||||||
@ -39,7 +44,7 @@ password_filename="PASSWORD_FILENAME"
|
|||||||
data_complete="n"
|
data_complete="n"
|
||||||
leading_data=""
|
leading_data=""
|
||||||
|
|
||||||
dsc_to_kitty "ssh" "hostname=$hostname:pwfile=$password_filename:pw=$data_password"
|
[ "$tty_ok" = "y" ] && dsc_to_kitty "ssh" "hostname=$hostname:pwfile=$password_filename:pw=$data_password"
|
||||||
record_separator=$(printf "\036")
|
record_separator=$(printf "\036")
|
||||||
|
|
||||||
mv_files_and_dirs() {
|
mv_files_and_dirs() {
|
||||||
@ -102,32 +107,34 @@ get_data() {
|
|||||||
untar_and_read_env "$size"
|
untar_and_read_env "$size"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_data
|
if [ "$tty_ok" = "y" ]; then
|
||||||
command stty "$saved_tty_settings"
|
get_data
|
||||||
saved_tty_settings=""
|
command stty "$saved_tty_settings" 2> /dev/null
|
||||||
if [ -n "$leading_data" ]; then
|
saved_tty_settings=""
|
||||||
|
if [ -n "$leading_data" ]; then
|
||||||
# clear current line as it might have things echoed on it from leading_data
|
# clear current line as it might have things echoed on it from leading_data
|
||||||
# because we only turn off echo in this script whereas the leading bytes could
|
# because we only turn off echo in this script whereas the leading bytes could
|
||||||
# have been sent before the script had a chance to run
|
# have been sent before the script had a chance to run
|
||||||
printf "\r\033[K"
|
printf "\r\033[K"
|
||||||
fi
|
fi
|
||||||
shell_integration_dir="$data_dir/shell-integration"
|
shell_integration_dir="$data_dir/shell-integration"
|
||||||
settings_dir="$data_dir/settings"
|
settings_dir="$data_dir/settings"
|
||||||
[ -f "$HOME/.terminfo/kitty.terminfo" ] || die "Incomplete extraction of ssh data";
|
[ -f "$HOME/.terminfo/kitty.terminfo" ] || die "Incomplete extraction of ssh data";
|
||||||
|
|
||||||
# export TERMINFO
|
# export TERMINFO
|
||||||
tname=".terminfo"
|
tname=".terminfo"
|
||||||
if [ -e "/usr/share/misc/terminfo.cdb" ]; then
|
if [ -e "/usr/share/misc/terminfo.cdb" ]; then
|
||||||
# NetBSD requires this see https://github.com/kovidgoyal/kitty/issues/4622
|
# NetBSD requires this see https://github.com/kovidgoyal/kitty/issues/4622
|
||||||
tname=".terminfo.cdb"
|
tname=".terminfo.cdb"
|
||||||
fi
|
fi
|
||||||
export TERMINFO="$HOME/$tname"
|
export TERMINFO="$HOME/$tname"
|
||||||
|
|
||||||
# compile terminfo for this system
|
# compile terminfo for this system
|
||||||
if [ -x "$(command -v tic)" ]; then
|
if [ -x "$(command -v tic)" ]; then
|
||||||
tic_out=$(command tic -x -o "$HOME/$tname" "$HOME/.terminfo/kitty.terminfo" 2>&1)
|
tic_out=$(command tic -x -o "$HOME/$tname" "$HOME/.terminfo/kitty.terminfo" 2>&1)
|
||||||
rc=$?
|
rc=$?
|
||||||
if [ "$rc" != "0" ]; then die "$tic_out"; fi
|
if [ "$rc" != "0" ]; then die "$tic_out"; fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@ -208,6 +215,14 @@ execute_with_python() {
|
|||||||
# If a command was passed to SSH execute it here
|
# If a command was passed to SSH execute it here
|
||||||
EXEC_CMD
|
EXEC_CMD
|
||||||
|
|
||||||
|
if [ "$tty_ok" = "n" ]; then
|
||||||
|
if [ -z "$(command -v stty)" ]; then
|
||||||
|
printf "%s\n" "stty missing ssh kitten cannot function" > /dev/stderr
|
||||||
|
else
|
||||||
|
printf "%s\n" "stty failed ssh kitten cannot function" > /dev/stderr
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
LOGIN_SHELL="OVERRIDE_LOGIN_SHELL"
|
LOGIN_SHELL="OVERRIDE_LOGIN_SHELL"
|
||||||
if [ -n "$LOGIN_SHELL" ]; then
|
if [ -n "$LOGIN_SHELL" ]; then
|
||||||
login_shell="$LOGIN_SHELL"
|
login_shell="$LOGIN_SHELL"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user