diff --git a/pmb/helpers/frontend.py b/pmb/helpers/frontend.py index 6543216b..07ca4004 100644 --- a/pmb/helpers/frontend.py +++ b/pmb/helpers/frontend.py @@ -138,7 +138,8 @@ def sideload(args): arch = args.arch user = args.user 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): diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 029b91a6..598268f9 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -185,6 +185,9 @@ def arguments_sideload(subparser): ret.add_argument("--host", help="ip of the device over wifi" " (defaults to 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" " one set in init") ret.add_argument("--arch", help="use a different architecture than the one" diff --git a/pmb/sideload/__init__.py b/pmb/sideload/__init__.py index 12e69770..e8747f26 100644 --- a/pmb/sideload/__init__.py +++ b/pmb/sideload/__init__.py @@ -10,18 +10,19 @@ import pmb.config.pmaports 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, so it trusts the apks that were signed here. :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")) key = keys[0] key_name = os.path.basename(key) 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") 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, '-S', 'mv', '-n', keyname, "/etc/apk/keys/"] 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") -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. :param user: target device ssh username :param host: target device ssh hostname + :param port: target device ssh port :param paths: list of absolute paths to locally stored apks :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))) 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") 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 add_cmd = pmb.helpers.run.flat_cmd(add_cmd) 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") -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. :param user: target device ssh username :param host: target device ssh hostname + :param port: target device ssh port :param arch: target device architecture :param copy_key: copy the abuild key too :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) 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)