pmb.sideload: support non-standard SSH port (!2046)

This can be used for example to sideload packages to
pmbootstrap's QEMU which is running on the port 2222
by default, as follows:

  pmbootstrap sideload --host localhost --port 2222 --user user <pkg>

This adds a `--port` parameter to sideload subcommand.
If not specified, port defaults to 22.
This commit is contained in:
Alexey Min 2021-04-06 00:45:39 +03:00
parent 57c830c410
commit 2b620a0fdd
No known key found for this signature in database
GPG Key ID: EBF5ECFFFEE34DED
3 changed files with 19 additions and 11 deletions

View File

@ -138,7 +138,8 @@ def sideload(args):
arch = args.arch arch = args.arch
user = args.user user = args.user
host = args.host host = args.host
pmb.sideload.sideload(args, user, host, arch, args.install_key, args.packages) pmb.sideload.sideload(args, user, host, args.port, arch, args.install_key,
args.packages)
def chroot(args): def chroot(args):

View File

@ -185,6 +185,9 @@ def arguments_sideload(subparser):
ret.add_argument("--host", help="ip of the device over wifi" ret.add_argument("--host", help="ip of the device over wifi"
" (defaults to 172.16.42.1)", " (defaults to 172.16.42.1)",
default="172.16.42.1") default="172.16.42.1")
ret.add_argument("--port", help="SSH port of the device over wifi"
" (defaults to 22)",
default="22")
ret.add_argument("--user", help="use a different username than the" ret.add_argument("--user", help="use a different username than the"
" one set in init") " one set in init")
ret.add_argument("--arch", help="use a different architecture than the one" ret.add_argument("--arch", help="use a different architecture than the one"

View File

@ -10,18 +10,19 @@ import pmb.config.pmaports
import pmb.build import pmb.build
def scp_abuild_key(args, user, host): def scp_abuild_key(args, user, host, port):
""" Copy the building key of the local installation to the target device, """ Copy the building key of the local installation to the target device,
so it trusts the apks that were signed here. so it trusts the apks that were signed here.
:param user: target device ssh username :param user: target device ssh username
:param host: target device ssh hostname """ :param host: target device ssh hostname
:param port: target device ssh port """
keys = glob.glob(os.path.join(args.work, "config_abuild", "*.pub")) keys = glob.glob(os.path.join(args.work, "config_abuild", "*.pub"))
key = keys[0] key = keys[0]
key_name = os.path.basename(key) key_name = os.path.basename(key)
logging.info(f"Copying signing key ({key_name}) to {user}@{host}") logging.info(f"Copying signing key ({key_name}) to {user}@{host}")
command = ['scp', key, f'{user}@{host}:/tmp'] command = ['scp', '-P', port, key, f'{user}@{host}:/tmp']
pmb.helpers.run.user(args, command, output="interactive") pmb.helpers.run.user(args, command, output="interactive")
logging.info(f"Installing signing key at {user}@{host}") logging.info(f"Installing signing key at {user}@{host}")
@ -29,14 +30,15 @@ def scp_abuild_key(args, user, host):
remote_cmd = ['sudo', '-p', pmb.config.sideload_sudo_prompt, remote_cmd = ['sudo', '-p', pmb.config.sideload_sudo_prompt,
'-S', 'mv', '-n', keyname, "/etc/apk/keys/"] '-S', 'mv', '-n', keyname, "/etc/apk/keys/"]
remote_cmd = pmb.helpers.run.flat_cmd(remote_cmd) remote_cmd = pmb.helpers.run.flat_cmd(remote_cmd)
command = ['ssh', '-t', f'{user}@{host}', remote_cmd] command = ['ssh', '-t', '-p', port, f'{user}@{host}', remote_cmd]
pmb.helpers.run.user(args, command, output="tui") pmb.helpers.run.user(args, command, output="tui")
def ssh_install_apks(args, user, host, paths): def ssh_install_apks(args, user, host, port, paths):
""" Copy binary packages via SCP and install them via SSH. """ Copy binary packages via SCP and install them via SSH.
:param user: target device ssh username :param user: target device ssh username
:param host: target device ssh hostname :param host: target device ssh hostname
:param port: target device ssh port
:param paths: list of absolute paths to locally stored apks :param paths: list of absolute paths to locally stored apks
:type paths: list """ :type paths: list """
@ -45,7 +47,7 @@ def ssh_install_apks(args, user, host, paths):
remote_paths.append(os.path.join('/tmp', os.path.basename(path))) remote_paths.append(os.path.join('/tmp', os.path.basename(path)))
logging.info(f"Copying packages to {user}@{host}") logging.info(f"Copying packages to {user}@{host}")
command = ['scp'] + paths + [f'{user}@{host}:/tmp'] command = ['scp', '-P', port] + paths + [f'{user}@{host}:/tmp']
pmb.helpers.run.user(args, command, output="interactive") pmb.helpers.run.user(args, command, output="interactive")
logging.info(f"Installing packages at {user}@{host}") logging.info(f"Installing packages at {user}@{host}")
@ -53,15 +55,17 @@ def ssh_install_apks(args, user, host, paths):
'-S', 'apk', 'add'] + remote_paths '-S', 'apk', 'add'] + remote_paths
add_cmd = pmb.helpers.run.flat_cmd(add_cmd) add_cmd = pmb.helpers.run.flat_cmd(add_cmd)
clean_cmd = pmb.helpers.run.flat_cmd(['rm'] + remote_paths) clean_cmd = pmb.helpers.run.flat_cmd(['rm'] + remote_paths)
command = ['ssh', '-t', f'{user}@{host}', f'{add_cmd}; {clean_cmd}'] command = ['ssh', '-t', '-p', port, f'{user}@{host}',
f'{add_cmd}; {clean_cmd}']
pmb.helpers.run.user(args, command, output="tui") pmb.helpers.run.user(args, command, output="tui")
def sideload(args, user, host, arch, copy_key, pkgnames): def sideload(args, user, host, port, arch, copy_key, pkgnames):
""" Build packages if necessary and install them via SSH. """ Build packages if necessary and install them via SSH.
:param user: target device ssh username :param user: target device ssh username
:param host: target device ssh hostname :param host: target device ssh hostname
:param port: target device ssh port
:param arch: target device architecture :param arch: target device architecture
:param copy_key: copy the abuild key too :param copy_key: copy the abuild key too
:param pkgnames: list of pkgnames to be built """ :param pkgnames: list of pkgnames to be built """
@ -83,6 +87,6 @@ def sideload(args, user, host, arch, copy_key, pkgnames):
paths.append(host_path) paths.append(host_path)
if copy_key: if copy_key:
scp_abuild_key(args, user, host) scp_abuild_key(args, user, host, port)
ssh_install_apks(args, user, host, paths) ssh_install_apks(args, user, host, port, paths)