Simplify data transmission
This commit is contained in:
parent
3c28a4f723
commit
a71e7d7eb1
@ -39,7 +39,6 @@ def make_tarfile(hostname: str = '', shell_integration_dest: str = DEFAULT_SHELL
|
||||
|
||||
|
||||
def get_ssh_data(msg: str, shell_integration_dest: str = DEFAULT_SHELL_INTEGRATION_DEST) -> Iterator[bytes]:
|
||||
yield b"KITTY_SSH_DATA_START\n"
|
||||
try:
|
||||
hostname, pwfilename, pw = msg.split(':', 2)
|
||||
except Exception:
|
||||
@ -58,12 +57,9 @@ def get_ssh_data(msg: str, shell_integration_dest: str = DEFAULT_SHELL_INTEGRATI
|
||||
yield b' error while gathering ssh data\n'
|
||||
else:
|
||||
from base64 import standard_b64encode
|
||||
encoded_data = memoryview(standard_b64encode(data))
|
||||
while encoded_data:
|
||||
yield encoded_data[:2048]
|
||||
yield b'\n'
|
||||
encoded_data = encoded_data[2048:]
|
||||
yield b"KITTY_SSH_DATA_END\n"
|
||||
encoded_data = standard_b64encode(data)
|
||||
yield f"{len(encoded_data)}\n".encode('ascii')
|
||||
yield encoded_data
|
||||
|
||||
|
||||
def safe_remove(x: str) -> None:
|
||||
|
||||
@ -42,6 +42,10 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77)
|
||||
t('ssh -p 33 main', port=33)
|
||||
|
||||
def test_ssh_bootstrap_script(self):
|
||||
# test simple untar with only sh
|
||||
with tempfile.TemporaryDirectory() as tdir:
|
||||
self.check_bootstrap('sh', tdir, 'sh', SHELL_INTEGRATION_VALUE='')
|
||||
|
||||
ok_login_shell = ''
|
||||
for sh in ('dash', 'zsh', 'bash', 'posh', 'sh'):
|
||||
q = shutil.which(sh)
|
||||
|
||||
@ -3,18 +3,17 @@
|
||||
# Distributed under terms of the GPLv3 license.
|
||||
|
||||
# read the transmitted data from STDIN
|
||||
saved_tty_settings=$(command stty -g)
|
||||
command stty raw -echo
|
||||
encoded_data_file=$(mktemp)
|
||||
|
||||
cleanup_on_bootstrap_exit() {
|
||||
[ ! -z "$encoded_data_file" ] && command rm -f "$encoded_data_file"
|
||||
[ ! -z "$saved_tty_settings" ] && command stty "$saved_tty_settings"
|
||||
}
|
||||
trap 'cleanup_on_bootstrap_exit' EXIT
|
||||
|
||||
die() { echo "$*" >/dev/stderr; cleanup_on_bootstrap_exit; exit 1; }
|
||||
debug() { printf "\033P@kitty-print|%s\033\\" "$(printf "%s" "debug: $1" | base64)"; }
|
||||
|
||||
saved_tty_settings=$(command stty -g)
|
||||
command stty raw min 1 time 0 || die "stty not available"
|
||||
trap 'cleanup_on_bootstrap_exit' EXIT
|
||||
|
||||
data_started="n"
|
||||
data_complete="n"
|
||||
pending_data=""
|
||||
@ -34,38 +33,25 @@ data_password="DATA_PASSWORD"
|
||||
password_filename="PASSWORD_FILENAME"
|
||||
pending_data=""
|
||||
data_complete="n"
|
||||
printf "\033P@kitty-ssh|%s:%s:%s\033\\" "$hostname" "$password_filename" "$data_password"
|
||||
|
||||
while [ "$data_complete" = "n" ]; do
|
||||
IFS= read -r line || die "Incomplete ssh data";
|
||||
case "$line" in
|
||||
*"KITTY_SSH_DATA_START")
|
||||
prefix=$(command expr "$line" : "\(.*\)KITTY_SSH_DATA_START")
|
||||
pending_data="$pending_data$prefix"
|
||||
data_started="y";
|
||||
printf "\033P@kitty-ssh|%s:%s:%s\033\\" "$hostname" "$password_filename" "$data_password"
|
||||
IFS= read -r size || die "Failed to read data size";
|
||||
case "$size" in
|
||||
" "*)
|
||||
die "$size";
|
||||
;;
|
||||
"KITTY_SSH_DATA_END")
|
||||
data_complete="y";
|
||||
;;
|
||||
*)
|
||||
if [ "$data_started" = "y" ]; then
|
||||
printf "%s" "$line" >> "$encoded_data_file"
|
||||
else
|
||||
pending_data="$pending_data$line\n"
|
||||
fi
|
||||
"")
|
||||
die "Got empty size";
|
||||
;;
|
||||
esac
|
||||
done
|
||||
command head -c "$size" < /dev/stdin | command base64 -d | command tar xjf - --no-same-owner -C "$HOME"
|
||||
rc="$?"
|
||||
command stty "$saved_tty_settings"
|
||||
saved_tty_settings=""
|
||||
if [ "$rc" != "0" ]; then die "Failed to extract data transmitted by ssh kitten over the TTY device"; fi
|
||||
if [ -n "$pending_data" ]; then
|
||||
printf "\033P@kitty-echo|%s\033\\" "$(printf "%s" "$pending_data" | base64)"
|
||||
fi
|
||||
command base64 -d < "$encoded_data_file" | command tar xjf - --no-same-owner -C "$HOME"
|
||||
rc=$?
|
||||
command rm -f "$encoded_data_file"
|
||||
encoded_data_file=""
|
||||
if [ "$rc" != "0" ]; then die "Failed to extract data transmitted by ssh kitten over the TTY device"; fi
|
||||
if [ ! -f "$HOME/.terminfo/kitty.terminfo" ]; then die "Extracted data transmitted by ssh kitten is incomplete"; fi
|
||||
|
||||
# export TERMINFO
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user