more work on ssh data transmission

This commit is contained in:
Kovid Goyal
2022-02-23 12:20:34 +05:30
parent 4279f20daf
commit f37d947dd5
7 changed files with 103 additions and 35 deletions

View File

@@ -22,10 +22,15 @@ if [[ -z "$HOSTNAME" ]]; then
else
hostname=$(HOSTNAME)
fi
# ensure $HOME is set
if [[ -z "$HOME" ]]; then HOME=~; fi
# ensure $USER is set
if [[ -z "$USER" ]]; then USER=$(whoami); fi
# ask for the SSH data
data_password="DATA_PASSWORD"
password_filename="PASSWORD_FILENAME"
printf "\eP@kitty-ssh|$password_filename:$data_password:$hostname\e\\"
printf "\eP@kitty-ssh|$hostname:$password_filename:$data_password\e\\"
while IFS= read -r line; do
case "$line" in
@@ -52,28 +57,26 @@ saved_tty_settings=""
if [[ ! -z "$pending_data" ]]; then
printf "\eP@kitty-echo|$(echo -n "$pending_data" | base64)\e\\"
fi
command base64 -d < "$encoded_data_file" | command tar xjf - --no-same-owner
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 echo "Failed to extract data transmitted by ssh kitten over the TTY device" > /dev/stderr; exit 1; fi
if [[ "$rc" != "0" ]]; then echo "Failed to extract data transmitted by ssh kitten over the TTY device" > /dev/stderr; exit 1; fi
# compile terminfo for this system
if [ -x "$(command -v tic)" ]; then
if [[ -x "$(command -v tic)" ]]; then
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
tname=".terminfo.cdb"
fi
tic_out=$(command tic -x -o "$HOME/$tname" ".terminfo/kitty.terminfo" 2>&1)
rc=$?
if [ "$rc" != "0" ]; then echo "$tic_out"; exit 1; fi
if [[ "$rc" != "0" ]]; then echo "$tic_out"; exit 1; fi
export TERMINFO="$HOME/$tname"
fi
# If a command was passed to SSH execute it here
EXEC_CMD
# ensure $USER is set
if [ -z "$USER" ]; then export USER=$(whoami); fi