diff --git a/kittens/ssh/copy.py b/kittens/ssh/copy.py index e20927fa8..781788a2e 100644 --- a/kittens/ssh/copy.py +++ b/kittens/ssh/copy.py @@ -75,7 +75,8 @@ def get_arcname(loc: str, dest: Optional[str], home: str) -> str: if arcname.startswith(home): arcname = os.path.relpath(arcname, home) arcname = os.path.normpath(arcname).replace(os.sep, '/') - return arcname + prefix = 'root' if arcname.startswith('/') else 'home/' + return prefix + arcname class CopyInstruction(NamedTuple): diff --git a/kittens/ssh/main.py b/kittens/ssh/main.py index 897086838..9f5873c4d 100644 --- a/kittens/ssh/main.py +++ b/kittens/ssh/main.py @@ -100,11 +100,11 @@ def make_tarfile(ssh_opts: SSHOptions, base_env: Dict[str, str]) -> bytes: rd = ssh_opts.remote_dir.rstrip('/') for location, ci in ssh_opts.copy.items(): tf.add(location, arcname=ci.arcname, filter=filter_from_globs(*ci.exclude_patterns)) - add_data_as_file(tf, 'kitty-ssh-kitten-data.sh', env_script) + add_data_as_file(tf, 'data.sh', env_script) if ksi: - arcname = rd + '/shell-integration' + arcname = 'home/' + rd + '/shell-integration' tf.add(shell_integration_dir, arcname=arcname, filter=filter_from_globs(f'{arcname}/ssh/bootstrap.*')) - tf.add(terminfo_dir, arcname='.terminfo', filter=normalize_tarinfo) + tf.add(terminfo_dir, arcname='home/.terminfo', filter=normalize_tarinfo) return buf.getvalue() diff --git a/kitty_tests/ssh.py b/kitty_tests/ssh.py index 4b97f8489..cc79c9666 100644 --- a/kitty_tests/ssh.py +++ b/kitty_tests/ssh.py @@ -48,10 +48,7 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77) def test_ssh_config_parsing(self): def parse(conf): - with tempfile.NamedTemporaryFile(suffix='test.conf') as cf: - cf.write(conf.encode('utf-8')) - cf.flush() - return load_config(cf.name) + return load_config(overrides=conf.splitlines()) def for_host(hostname, conf): if isinstance(conf, str): @@ -72,6 +69,9 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77) def all_possible_sh(self): return tuple(sh for sh in ('dash', 'zsh', 'bash', 'posh', 'sh') if shutil.which(sh)) + def test_ssh_copy(self): + pass + def test_ssh_env_vars(self): for sh in self.all_possible_sh: with self.subTest(sh=sh), tempfile.TemporaryDirectory() as tdir: diff --git a/shell-integration/ssh/bootstrap.sh b/shell-integration/ssh/bootstrap.sh index ddefd4899..cb7e8c94e 100644 --- a/shell-integration/ssh/bootstrap.sh +++ b/shell-integration/ssh/bootstrap.sh @@ -37,6 +37,14 @@ leading_data="" dsc_to_kitty "ssh" "hostname=$hostname:pwfile=$password_filename:pw=$data_password" record_separator=$(printf "\036") +mv_files_and_dirs() { + cwd="$PWD"; + cd "$1"; + command find . -type d -exec mkdir -p "$2/{}" ";" + command find . -type f -exec mv "{}" "$2/{}" ";" + cd "$cwd"; +} + untar_and_read_env() { # extract the tar file atomically, in the sense that any file from the # tarfile is only put into place after it has been fully written to disk @@ -47,15 +55,11 @@ untar_and_read_env() { # does not limit itself to reading -c bytes only from the pipe so we can potentially lose # some trailing data, for instance if the user starts typing. Cant be helped. command head -c "$1" < /dev/tty | command base64 -d | command tar xjf - --no-same-owner -C "$tdir"; - data_file="$tdir/kitty-ssh-kitten-data.sh"; + data_file="$tdir/data.sh"; [ -f "$data_file" ] && . "$data_file"; data_dir="$HOME/$KITTY_SSH_KITTEN_DATA_DIR" - command rm -f "$data_file"; - cwd="$PWD"; - cd "$tdir"; - command find . -type d -exec mkdir -p "${HOME}/{}" ";" - command find . -type f -exec mv "{}" "${HOME}/{}" ";" - cd "$cwd"; + mv_files_and_dirs "$tdir/home" "$HOME" + [ -e "$tdir/root" ] && mv_files_and_dirs "$tdir/root" "" command rm -rf "$tdir"; [ -z "KITTY_SSH_KITTEN_DATA_DIR" ] && die "Failed to read SSH data from tty"; unset KITTY_SSH_KITTEN_DATA_DIR;