mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 13:45:45 -05:00
Merge branch 'dev' into chroot-bootpart
This commit is contained in:
commit
539be06e8e
1 changed files with 16 additions and 9 deletions
25
ssh.py
25
ssh.py
|
@ -1,30 +1,37 @@
|
||||||
|
from typing import Optional
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import subprocess
|
import subprocess
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from config import config
|
from config import config
|
||||||
from constants import SSH_COMMON_OPTIONS, SSH_DEFAULT_HOST, SSH_DEFAULT_PORT
|
from constants import SSH_COMMON_OPTIONS, SSH_DEFAULT_HOST, SSH_DEFAULT_PORT
|
||||||
from wrapper import enforce_wrap
|
|
||||||
|
|
||||||
|
|
||||||
@click.command(name='ssh')
|
@click.command(name='ssh')
|
||||||
def cmd_ssh():
|
@click.argument('cmd', nargs=-1)
|
||||||
"""Establish SSH connection over USB to device"""
|
@click.option('--user', '-u', help='the SSH username', default=None)
|
||||||
enforce_wrap()
|
@click.option('--host', '-h', help='the SSH host', default=SSH_DEFAULT_HOST)
|
||||||
run_ssh_command()
|
@click.option('--port', '-p', help='the SSH port', type=int, default=SSH_DEFAULT_PORT)
|
||||||
|
def cmd_ssh(cmd: list[str], user: str, host: str, port: int):
|
||||||
|
"""Establish SSH connection to device"""
|
||||||
|
run_ssh_command(list(cmd), user=user, host=host, port=port)
|
||||||
|
|
||||||
|
|
||||||
def run_ssh_command(cmd: list[str] = [], user: str = None, host: str = SSH_DEFAULT_HOST, port: int = SSH_DEFAULT_PORT):
|
def run_ssh_command(cmd: list[str] = [], user: Optional[str] = None, host: str = SSH_DEFAULT_HOST, port: int = SSH_DEFAULT_PORT):
|
||||||
if not user:
|
if not user:
|
||||||
user = config.get_profile()['username']
|
user = config.get_profile()['username']
|
||||||
keys = find_ssh_keys()
|
keys = find_ssh_keys()
|
||||||
key_args = []
|
extra_args = []
|
||||||
if len(keys) > 0:
|
if len(keys) > 0:
|
||||||
key_args = ['-i', keys[0]]
|
extra_args += ['-i', keys[0]]
|
||||||
|
if config.runtime['verbose']:
|
||||||
|
extra_args += ['-v']
|
||||||
|
logging.info(f'Opening SSH connection to {host}')
|
||||||
return subprocess.run([
|
return subprocess.run([
|
||||||
'ssh',
|
'ssh',
|
||||||
] + key_args + SSH_COMMON_OPTIONS + [
|
] + extra_args + SSH_COMMON_OPTIONS + [
|
||||||
'-p',
|
'-p',
|
||||||
str(port),
|
str(port),
|
||||||
f'{user}@{host}',
|
f'{user}@{host}',
|
||||||
|
|
Loading…
Add table
Reference in a new issue