helpers: drop args from helpers.run functions (MR 2252)

Now we can run commands without needs args available!

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-05-24 18:24:34 +02:00 committed by Oliver Smith
parent 02f04ba3a8
commit 05c86be11c
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
42 changed files with 161 additions and 160 deletions

View file

@ -70,10 +70,10 @@ def generate(args: PmbArgs, pkgname):
aportgen = pmb.config.work / "aportgen" aportgen = pmb.config.work / "aportgen"
if os.path.exists(aportgen): if os.path.exists(aportgen):
pmb.helpers.run.user(args, ["rm", "-r", aportgen]) pmb.helpers.run.user(["rm", "-r", aportgen])
if args.fork_alpine: if args.fork_alpine:
upstream = pmb.aportgen.core.get_upstream_aport(args, pkgname) upstream = pmb.aportgen.core.get_upstream_aport(args, pkgname)
pmb.helpers.run.user(args, ["cp", "-r", upstream, pmb.helpers.run.user(["cp", "-r", upstream,
aportgen]) aportgen])
pmb.aportgen.core.rewrite(args, pkgname, replace_simple={ pmb.aportgen.core.rewrite(args, pkgname, replace_simple={
"# Contributor:*": None, "# Maintainer:*": None}) "# Contributor:*": None, "# Maintainer:*": None})
@ -83,7 +83,7 @@ def generate(args: PmbArgs, pkgname):
# Move to the aports folder # Move to the aports folder
if os.path.exists(path_target): if os.path.exists(path_target):
pmb.helpers.run.user(args, ["rm", "-r", path_target]) pmb.helpers.run.user(["rm", "-r", path_target])
pmb.helpers.run.user( pmb.helpers.run.user(
args, ["mv", aportgen, path_target]) args, ["mv", aportgen, path_target])

View file

@ -24,7 +24,7 @@ def generate(args: PmbArgs, pkgname):
tempdir = Path("/tmp/aportgen") tempdir = Path("/tmp/aportgen")
aportgen = pmb.config.work / "aportgen" aportgen = pmb.config.work / "aportgen"
pmb.chroot.root(args, ["rm", "-rf", tempdir]) pmb.chroot.root(args, ["rm", "-rf", tempdir])
pmb.helpers.run.user(args, ["mkdir", "-p", aportgen, pmb.helpers.run.user(["mkdir", "-p", aportgen,
Chroot.native() / tempdir]) Chroot.native() / tempdir])
# Write the APKBUILD # Write the APKBUILD
@ -74,4 +74,4 @@ def generate(args: PmbArgs, pkgname):
pmb.build.init_abuild_minimal(args) pmb.build.init_abuild_minimal(args)
pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", tempdir]) pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", tempdir])
pmb.chroot.user(args, ["abuild", "checksum"], working_dir=tempdir) pmb.chroot.user(args, ["abuild", "checksum"], working_dir=tempdir)
pmb.helpers.run.user(args, ["cp", apkbuild_path, aportgen]) pmb.helpers.run.user(["cp", apkbuild_path, aportgen])

View file

@ -175,7 +175,7 @@ def get_upstream_aport(args: PmbArgs, pkgname, arch=None):
channel_cfg = pmb.config.pmaports.read_config_channel(args) channel_cfg = pmb.config.pmaports.read_config_channel(args)
branch = channel_cfg["branch_aports"] branch = channel_cfg["branch_aports"]
logging.info(f"Checkout aports.git branch: {branch}") logging.info(f"Checkout aports.git branch: {branch}")
if pmb.helpers.run.user(args, ["git", "checkout", branch], if pmb.helpers.run.user(["git", "checkout", branch],
aports_upstream_path, check=False): aports_upstream_path, check=False):
logging.info("NOTE: run 'pmbootstrap pull' and try again") logging.info("NOTE: run 'pmbootstrap pull' and try again")
logging.info("NOTE: if it still fails, your aports.git was cloned with" logging.info("NOTE: if it still fails, your aports.git was cloned with"

View file

@ -237,7 +237,7 @@ def generate_deviceinfo(args: PmbArgs, pkgname, name, manufacturer, year, arch,
content += content_uuu content += content_uuu
# Write to file # Write to file
pmb.helpers.run.user(args, ["mkdir", "-p", pmb.config.work / "aportgen"]) pmb.helpers.run.user(["mkdir", "-p", pmb.config.work / "aportgen"])
path = pmb.config.work / "aportgen/deviceinfo" path = pmb.config.work / "aportgen/deviceinfo"
with open(path, "w", encoding="utf-8") as handle: with open(path, "w", encoding="utf-8") as handle:
for line in content.rstrip().split("\n"): for line in content.rstrip().split("\n"):
@ -258,7 +258,7 @@ def generate_modules_initfs(args: PmbArgs):
""" """
# Write to file # Write to file
pmb.helpers.run.user(args, ["mkdir", "-p", pmb.config.work / "aportgen"]) pmb.helpers.run.user(["mkdir", "-p", pmb.config.work / "aportgen"])
path = pmb.config.work / "aportgen/modules-initfs" path = pmb.config.work / "aportgen/modules-initfs"
with open(path, "w", encoding="utf-8") as handle: with open(path, "w", encoding="utf-8") as handle:
for line in content.rstrip().split("\n"): for line in content.rstrip().split("\n"):
@ -308,7 +308,7 @@ def generate_apkbuild(args: PmbArgs, pkgname, name, arch, flash_method):
""" """
# Write the file # Write the file
pmb.helpers.run.user(args, ["mkdir", "-p", pmb.config.work / "aportgen"]) pmb.helpers.run.user(["mkdir", "-p", pmb.config.work / "aportgen"])
path = pmb.config.work / "aportgen/APKBUILD" path = pmb.config.work / "aportgen/APKBUILD"
with open(path, "w", encoding="utf-8") as handle: with open(path, "w", encoding="utf-8") as handle:
for line in content.rstrip().split("\n"): for line in content.rstrip().split("\n"):

View file

@ -22,7 +22,7 @@ def generate(args: PmbArgs, pkgname):
else: else:
raise ValueError(f"Invalid prefix '{prefix}', expected gcc, gcc4 or" raise ValueError(f"Invalid prefix '{prefix}', expected gcc, gcc4 or"
" gcc6.") " gcc6.")
pmb.helpers.run.user(args, ["cp", "-r", upstream, pmb.config.work / "aportgen"]) pmb.helpers.run.user(["cp", "-r", upstream, pmb.config.work / "aportgen"])
# Rewrite APKBUILD # Rewrite APKBUILD
fields = { fields = {

View file

@ -24,7 +24,7 @@ def generate(args: PmbArgs, pkgname):
tempdir = Path("/tmp/aportgen") tempdir = Path("/tmp/aportgen")
aportgen = pmb.config.work / "aportgen" aportgen = pmb.config.work / "aportgen"
pmb.chroot.root(args, ["rm", "-rf", tempdir]) pmb.chroot.root(args, ["rm", "-rf", tempdir])
pmb.helpers.run.user(args, ["mkdir", "-p", aportgen, pmb.helpers.run.user(["mkdir", "-p", aportgen,
Chroot.native() / tempdir]) Chroot.native() / tempdir])
# Write the APKBUILD # Write the APKBUILD
@ -64,4 +64,4 @@ def generate(args: PmbArgs, pkgname):
pmb.build.init_abuild_minimal(args) pmb.build.init_abuild_minimal(args)
pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", tempdir]) pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", tempdir])
pmb.chroot.user(args, ["abuild", "checksum"], working_dir=tempdir) pmb.chroot.user(args, ["abuild", "checksum"], working_dir=tempdir)
pmb.helpers.run.user(args, ["cp", apkbuild_path, aportgen]) pmb.helpers.run.user(["cp", apkbuild_path, aportgen])

View file

@ -115,7 +115,7 @@ def generate(args: PmbArgs, pkgname):
deviceinfo = pmb.parse.deviceinfo(args, device) deviceinfo = pmb.parse.deviceinfo(args, device)
# Symlink commonly used patches # Symlink commonly used patches
pmb.helpers.run.user(args, ["mkdir", "-p", pmb.config.work / "aportgen"]) pmb.helpers.run.user(["mkdir", "-p", pmb.config.work / "aportgen"])
patches = [ patches = [
"gcc7-give-up-on-ilog2-const-optimizations.patch", "gcc7-give-up-on-ilog2-const-optimizations.patch",
"gcc8-fix-put-user.patch", "gcc8-fix-put-user.patch",
@ -123,7 +123,7 @@ def generate(args: PmbArgs, pkgname):
"kernel-use-the-gnu89-standard-explicitly.patch", "kernel-use-the-gnu89-standard-explicitly.patch",
] ]
for patch in patches: for patch in patches:
pmb.helpers.run.user(args, ["ln", "-s", pmb.helpers.run.user(["ln", "-s",
"../../.shared-patches/linux/" + patch, "../../.shared-patches/linux/" + patch,
(pmb.config.work / "aportgen" / patch)]) (pmb.config.work / "aportgen" / patch)])

View file

@ -24,7 +24,7 @@ def generate(args: PmbArgs, pkgname):
tempdir = Path("/tmp/aportgen") tempdir = Path("/tmp/aportgen")
aportgen = pmb.config.work / "aportgen" aportgen = pmb.config.work / "aportgen"
pmb.chroot.root(args, ["rm", "-rf", tempdir]) pmb.chroot.root(args, ["rm", "-rf", tempdir])
pmb.helpers.run.user(args, ["mkdir", "-p", aportgen, pmb.helpers.run.user(["mkdir", "-p", aportgen,
Chroot.native() / tempdir]) Chroot.native() / tempdir])
# Write the APKBUILD # Write the APKBUILD
@ -100,4 +100,4 @@ def generate(args: PmbArgs, pkgname):
pmb.build.init_abuild_minimal(args) pmb.build.init_abuild_minimal(args)
pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", tempdir]) pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", tempdir])
pmb.chroot.user(args, ["abuild", "checksum"], working_dir=tempdir) pmb.chroot.user(args, ["abuild", "checksum"], working_dir=tempdir)
pmb.helpers.run.user(args, ["cp", apkbuild_path, aportgen]) pmb.helpers.run.user(["cp", apkbuild_path, aportgen])

View file

@ -23,7 +23,7 @@ def update(args: PmbArgs, pkgname):
# Copy modified APKBUILD back # Copy modified APKBUILD back
source = Chroot.native() / "home/pmos/build/APKBUILD" source = Chroot.native() / "home/pmos/build/APKBUILD"
target = f"{os.fspath(pmb.helpers.pmaports.find(args, pkgname))}/" target = f"{os.fspath(pmb.helpers.pmaports.find(args, pkgname))}/"
pmb.helpers.run.user(args, ["cp", source, target]) pmb.helpers.run.user(["cp", source, target])
def verify(args: PmbArgs, pkgname): def verify(args: PmbArgs, pkgname):

View file

@ -95,10 +95,10 @@ def modify_apkbuild(args: PmbArgs, pkgname: str, aport: Path):
apkbuild_path = aport + "/APKBUILD" apkbuild_path = aport + "/APKBUILD"
apkbuild = pmb.parse.apkbuild(apkbuild_path) apkbuild = pmb.parse.apkbuild(apkbuild_path)
if os.path.exists(pmb.config.work / "aportgen"): if os.path.exists(pmb.config.work / "aportgen"):
pmb.helpers.run.user(args, ["rm", "-r", pmb.config.work / "aportgen"]) pmb.helpers.run.user(["rm", "-r", pmb.config.work / "aportgen"])
pmb.helpers.run.user(args, ["mkdir", pmb.config.work / "aportgen"]) pmb.helpers.run.user(["mkdir", pmb.config.work / "aportgen"])
pmb.helpers.run.user(args, ["cp", "-r", apkbuild_path, pmb.helpers.run.user(["cp", "-r", apkbuild_path,
pmb.config.work / "aportgen"]) pmb.config.work / "aportgen"])
pkgver = pmb.build._package.get_pkgver(apkbuild["pkgver"], pkgver = pmb.build._package.get_pkgver(apkbuild["pkgver"],
@ -153,7 +153,7 @@ def run_abuild(args: PmbArgs, pkgname: str, arch: str, apkbuild_path: Path, kbui
build_path / "src" / kbuild_out]) build_path / "src" / kbuild_out])
cmd: List[PathString] = ["cp", apkbuild_path, chroot / build_path / "APKBUILD"] cmd: List[PathString] = ["cp", apkbuild_path, chroot / build_path / "APKBUILD"]
pmb.helpers.run.root(args, cmd) pmb.helpers.run.root(cmd)
# Create the apk package # Create the apk package
env = {"CARCH": arch, env = {"CARCH": arch,

View file

@ -162,7 +162,7 @@ def menuconfig(args: PmbArgs, pkgname: str, use_oldconfig):
logging.info("Copy kernel config back to aport-folder") logging.info("Copy kernel config back to aport-folder")
config = "config-" + apkbuild["_flavor"] + "." + arch config = "config-" + apkbuild["_flavor"] + "." + arch
target = aport / config target = aport / config
pmb.helpers.run.user(args, ["cp", source, target]) pmb.helpers.run.user(["cp", source, target])
pmb.build.checksum.update(args, pkgname) pmb.build.checksum.update(args, pkgname)
# Check config # Check config

View file

@ -44,11 +44,11 @@ def newapkbuild(args: PmbArgs, folder, args_passed, force=False):
question = "Continue and delete its contents?" question = "Continue and delete its contents?"
if not force and not pmb.helpers.cli.confirm(args, question): if not force and not pmb.helpers.cli.confirm(args, question):
raise RuntimeError("Aborted.") raise RuntimeError("Aborted.")
pmb.helpers.run.user(args, ["rm", "-r", target]) pmb.helpers.run.user(["rm", "-r", target])
# Copy the aport (without the extracted src folder) # Copy the aport (without the extracted src folder)
logging.info("Create " + target) logging.info("Create " + target)
pmb.helpers.run.user(args, ["mkdir", "-p", target]) pmb.helpers.run.user(["mkdir", "-p", target])
for path in build_outside.glob("/*"): for path in build_outside.glob("/*"):
if not path.is_dir(): if not path.is_dir():
pmb.helpers.run.user(args, ["cp", path, target]) pmb.helpers.run.user(["cp", path, target])

View file

@ -28,10 +28,10 @@ def copy_to_buildpath(args: PmbArgs, package, chroot: Chroot=Chroot.native()):
# Clean up folder # Clean up folder
build = chroot / "home/pmos/build" build = chroot / "home/pmos/build"
if build.exists(): if build.exists():
pmb.helpers.run.root(args, ["rm", "-rf", build]) pmb.helpers.run.root(["rm", "-rf", build])
# Copy aport contents with resolved symlinks # Copy aport contents with resolved symlinks
pmb.helpers.run.root(args, ["mkdir", "-p", build]) pmb.helpers.run.root(["mkdir", "-p", build])
for entry in aport.iterdir(): for entry in aport.iterdir():
file = entry.name file = entry.name
# Don't copy those dirs, as those have probably been generated by running `abuild` # Don't copy those dirs, as those have probably been generated by running `abuild`
@ -40,7 +40,7 @@ def copy_to_buildpath(args: PmbArgs, package, chroot: Chroot=Chroot.native()):
if file in ["src", "pkg"]: if file in ["src", "pkg"]:
logging.warning(f"WARNING: Not copying {file}, looks like a leftover from abuild") logging.warning(f"WARNING: Not copying {file}, looks like a leftover from abuild")
continue continue
pmb.helpers.run.root(args, ["cp", "-rL", aport / file, build / file]) pmb.helpers.run.root(["cp", "-rL", aport / file, build / file])
pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", pmb.chroot.root(args, ["chown", "-R", "pmos:pmos",
"/home/pmos/build"], chroot) "/home/pmos/build"], chroot)

View file

@ -49,7 +49,7 @@ def update_repository_list(args: PmbArgs, suffix: Chroot, postmarketos_mirror=Tr
for line in handle: for line in handle:
lines_old.append(line[:-1]) lines_old.append(line[:-1])
else: else:
pmb.helpers.run.root(args, ["mkdir", "-p", path.parent]) pmb.helpers.run.root(["mkdir", "-p", path.parent])
# Up to date: Save cache, return # Up to date: Save cache, return
lines_new = pmb.helpers.repo.urls(args, postmarketos_mirror=postmarketos_mirror) lines_new = pmb.helpers.repo.urls(args, postmarketos_mirror=postmarketos_mirror)
@ -64,9 +64,9 @@ def update_repository_list(args: PmbArgs, suffix: Chroot, postmarketos_mirror=Tr
# Update the file # Update the file
logging.debug(f"({suffix}) update /etc/apk/repositories") logging.debug(f"({suffix}) update /etc/apk/repositories")
if path.exists(): if path.exists():
pmb.helpers.run.root(args, ["rm", path]) pmb.helpers.run.root(["rm", path])
for line in lines_new: for line in lines_new:
pmb.helpers.run.root(args, ["sh", "-c", "echo " pmb.helpers.run.root(["sh", "-c", "echo "
f"{shlex.quote(line)} >> {path}"]) f"{shlex.quote(line)} >> {path}"])
update_repository_list(args, suffix, postmarketos_mirror, True) update_repository_list(args, suffix, postmarketos_mirror, True)
@ -229,7 +229,7 @@ def install_run_apk(args: PmbArgs, to_add, to_add_local, to_del, chroot: Chroot)
# Virtual package related commands don't actually install or remove # Virtual package related commands don't actually install or remove
# packages, but only mark the right ones as explicitly installed. # packages, but only mark the right ones as explicitly installed.
# They finish up almost instantly, so don't display a progress bar. # They finish up almost instantly, so don't display a progress bar.
pmb.helpers.run.root(args, [apk_static, "--no-progress"] + command) pmb.helpers.run.root([apk_static, "--no-progress"] + command)
def install(args: PmbArgs, packages, chroot: Chroot, build=True): def install(args: PmbArgs, packages, chroot: Chroot, build=True):

View file

@ -86,7 +86,7 @@ def verify_signature(args: PmbArgs, files, sigkey_path):
""" """
logging.debug(f"Verify apk.static signature with {sigkey_path}") logging.debug(f"Verify apk.static signature with {sigkey_path}")
try: try:
pmb.helpers.run.user(args, ["openssl", "dgst", "-sha1", "-verify", pmb.helpers.run.user(["openssl", "dgst", "-sha1", "-verify",
sigkey_path, "-signature", files[ sigkey_path, "-signature", files[
"sig"]["temp_path"], "sig"]["temp_path"],
files["apk"]["temp_path"]]) files["apk"]["temp_path"]])
@ -119,7 +119,7 @@ def extract(args: PmbArgs, version, apk_path):
logging.debug("Verify the version reported by the apk.static binary" logging.debug("Verify the version reported by the apk.static binary"
f" (must match the package version {version})") f" (must match the package version {version})")
os.chmod(temp_path, os.stat(temp_path).st_mode | stat.S_IEXEC) os.chmod(temp_path, os.stat(temp_path).st_mode | stat.S_IEXEC)
version_bin = pmb.helpers.run.user_output(args, [temp_path, "--version"]) version_bin = pmb.helpers.run.user_output([temp_path, "--version"])
version_bin = version_bin.split(" ")[1].split(",")[0] version_bin = version_bin.split(" ")[1].split(",")[0]
if not version.startswith(f"{version_bin}-r"): if not version.startswith(f"{version_bin}-r"):
os.unlink(temp_path) os.unlink(temp_path)

View file

@ -53,8 +53,7 @@ def register(args: PmbArgs, arch):
# Register in binfmt_misc # Register in binfmt_misc
logging.info("Register qemu binfmt (" + arch_qemu + ")") logging.info("Register qemu binfmt (" + arch_qemu + ")")
register = "/proc/sys/fs/binfmt_misc/register" register = "/proc/sys/fs/binfmt_misc/register"
pmb.helpers.run.root( pmb.helpers.run.root(["sh", "-c", 'echo "' + code + '" > ' + register])
args, ["sh", "-c", 'echo "' + code + '" > ' + register])
def unregister(args: PmbArgs, arch): def unregister(args: PmbArgs, arch):
@ -63,4 +62,4 @@ def unregister(args: PmbArgs, arch):
if not os.path.exists(binfmt_file): if not os.path.exists(binfmt_file):
return return
logging.info("Unregister qemu binfmt (" + arch_qemu + ")") logging.info("Unregister qemu binfmt (" + arch_qemu + ")")
pmb.helpers.run.root(args, ["sh", "-c", "echo -1 > " + binfmt_file]) pmb.helpers.run.root(["sh", "-c", "echo -1 > " + binfmt_file])

View file

@ -40,9 +40,9 @@ def copy_resolv_conf(args: PmbArgs, chroot: Chroot):
resolv_path = chroot / host resolv_path = chroot / host
if os.path.exists(host): if os.path.exists(host):
if not resolv_path.exists() or not filecmp.cmp(host, resolv_path): if not resolv_path.exists() or not filecmp.cmp(host, resolv_path):
pmb.helpers.run.root(args, ["cp", host, resolv_path]) pmb.helpers.run.root(["cp", host, resolv_path])
else: else:
pmb.helpers.run.root(args, ["touch", resolv_path]) pmb.helpers.run.root(["touch", resolv_path])
def mark_in_chroot(args: PmbArgs, chroot: Chroot=Chroot.native()): def mark_in_chroot(args: PmbArgs, chroot: Chroot=Chroot.native()):
@ -53,7 +53,7 @@ def mark_in_chroot(args: PmbArgs, chroot: Chroot=Chroot.native()):
""" """
in_chroot_file = chroot / "in-pmbootstrap" in_chroot_file = chroot / "in-pmbootstrap"
if not in_chroot_file.exists(): if not in_chroot_file.exists():
pmb.helpers.run.root(args, ["touch", in_chroot_file]) pmb.helpers.run.root(["touch", in_chroot_file])
def setup_qemu_emulation(args: PmbArgs, chroot: Chroot): def setup_qemu_emulation(args: PmbArgs, chroot: Chroot):
@ -84,13 +84,13 @@ def init_keys(args: PmbArgs):
target = pmb.config.work / "config_apk_keys" / key.name target = pmb.config.work / "config_apk_keys" / key.name
if not target.exists(): if not target.exists():
# Copy as root, so the resulting files in chroots are owned by root # Copy as root, so the resulting files in chroots are owned by root
pmb.helpers.run.root(args, ["cp", key, target]) pmb.helpers.run.root(["cp", key, target])
def init_usr_merge(args: PmbArgs, chroot: Chroot): def init_usr_merge(args: PmbArgs, chroot: Chroot):
logging.info(f"({chroot}) merge /usr") logging.info(f"({chroot}) merge /usr")
script = f"{pmb.config.pmb_src}/pmb/data/merge-usr.sh" script = f"{pmb.config.pmb_src}/pmb/data/merge-usr.sh"
pmb.helpers.run.root(args, ["sh", "-e", script, "CALLED_FROM_PMB", pmb.helpers.run.root(["sh", "-e", script, "CALLED_FROM_PMB",
chroot.path]) chroot.path])
@ -148,7 +148,7 @@ def init(args: PmbArgs, chroot: Chroot=Chroot.native(), usr_merge=UsrMerge.AUTO,
# Initialize cache # Initialize cache
apk_cache = pmb.config.work / f"cache_apk_{arch}" apk_cache = pmb.config.work / f"cache_apk_{arch}"
pmb.helpers.run.root(args, ["ln", "-s", "-f", "/var/cache/apk", pmb.helpers.run.root(["ln", "-s", "-f", "/var/cache/apk",
chroot / "etc/apk/cache"]) chroot / "etc/apk/cache"])
# Initialize /etc/apk/keys/, resolv.conf, repositories # Initialize /etc/apk/keys/, resolv.conf, repositories

View file

@ -20,7 +20,7 @@ def create_device_nodes(args: PmbArgs, chroot: Chroot):
for dev in pmb.config.chroot_device_nodes: for dev in pmb.config.chroot_device_nodes:
path = chroot / "dev" / str(dev[4]) path = chroot / "dev" / str(dev[4])
if not path.exists(): if not path.exists():
pmb.helpers.run.root(args, ["mknod", pmb.helpers.run.root(["mknod",
"-m", str(dev[0]), # permissions "-m", str(dev[0]), # permissions
path, # name path, # name
str(dev[1]), # type str(dev[1]), # type
@ -60,20 +60,20 @@ def mount_dev_tmpfs(args: PmbArgs, chroot: Chroot=Chroot.native()):
return return
# Create the $chroot/dev folder and mount tmpfs there # Create the $chroot/dev folder and mount tmpfs there
pmb.helpers.run.root(args, ["mkdir", "-p", dev]) pmb.helpers.run.root(["mkdir", "-p", dev])
pmb.helpers.run.root(args, ["mount", "-t", "tmpfs", pmb.helpers.run.root(["mount", "-t", "tmpfs",
"-o", "size=1M,noexec,dev", "-o", "size=1M,noexec,dev",
"tmpfs", dev]) "tmpfs", dev])
# Create pts, shm folders and device nodes # Create pts, shm folders and device nodes
pmb.helpers.run.root(args, ["mkdir", "-p", dev / "pts", dev / "shm"]) pmb.helpers.run.root(["mkdir", "-p", dev / "pts", dev / "shm"])
pmb.helpers.run.root(args, ["mount", "-t", "tmpfs", pmb.helpers.run.root(["mount", "-t", "tmpfs",
"-o", "nodev,nosuid,noexec", "-o", "nodev,nosuid,noexec",
"tmpfs", dev / "shm"]) "tmpfs", dev / "shm"])
create_device_nodes(args, chroot) create_device_nodes(args, chroot)
# Setup /dev/fd as a symlink # Setup /dev/fd as a symlink
pmb.helpers.run.root(args, ["ln", "-sf", "/proc/self/fd", f"{dev}/"]) pmb.helpers.run.root(["ln", "-sf", "/proc/self/fd", f"{dev}/"])
def mount(args: PmbArgs, chroot: Chroot=Chroot.native()): def mount(args: PmbArgs, chroot: Chroot=Chroot.native()):
@ -105,7 +105,7 @@ def mount_native_into_foreign(args: PmbArgs, chroot: Chroot):
musl = next(source.glob("lib/ld-musl-*.so.1")).name musl = next(source.glob("lib/ld-musl-*.so.1")).name
musl_link = (chroot / "lib" / musl) musl_link = (chroot / "lib" / musl)
if not musl_link.is_symlink(): if not musl_link.is_symlink():
pmb.helpers.run.root(args, ["ln", "-s", "/native/lib/" + musl, pmb.helpers.run.root(["ln", "-s", "/native/lib/" + musl,
musl_link]) musl_link])
pmb.helpers.run.root(args, ["ln", "-sf", "/native/usr/bin/pigz", "/usr/local/bin/pigz"]) pmb.helpers.run.root(args, ["ln", "-sf", "/native/usr/bin/pigz", "/usr/local/bin/pigz"])
@ -122,4 +122,4 @@ def remove_mnt_pmbootstrap(args: PmbArgs, chroot: Chroot):
return return
for path in list(mnt_dir.glob("*")) + [mnt_dir]: for path in list(mnt_dir.glob("*")) + [mnt_dir]:
pmb.helpers.run.root(args, ["rmdir", path]) pmb.helpers.run.root(["rmdir", path])

View file

@ -71,6 +71,6 @@ def copy_xauthority(args: PmbArgs):
# Copy to chroot and chown # Copy to chroot and chown
copy = Chroot.native() / "home/pmos/.Xauthority" copy = Chroot.native() / "home/pmos/.Xauthority"
if os.path.exists(copy): if os.path.exists(copy):
pmb.helpers.run.root(args, ["rm", copy]) pmb.helpers.run.root(["rm", copy])
pmb.helpers.run.root(args, ["cp", original, copy]) pmb.helpers.run.root(["cp", original, copy])
pmb.chroot.root(args, ["chown", "pmos:pmos", "/home/pmos/.Xauthority"]) pmb.chroot.root(args, ["chown", "pmos:pmos", "/home/pmos/.Xauthority"])

View file

@ -83,7 +83,7 @@ def root(args: PmbArgs, cmd: Sequence[PathString], chroot: Chroot=Chroot.native(
"env", "-i", executables["sh"], "-c", "env", "-i", executables["sh"], "-c",
pmb.helpers.run_core.flat_cmd(cmd_chroot, env=env_all)] pmb.helpers.run_core.flat_cmd(cmd_chroot, env=env_all)]
) )
return pmb.helpers.run_core.core(args, msg, cmd_sudo, None, output, return pmb.helpers.run_core.core(msg, cmd_sudo, None, output,
output_return, check, True, output_return, check, True,
disable_timeout) disable_timeout)

View file

@ -87,7 +87,7 @@ def shutdown(args: PmbArgs, only_install_related=False):
# contents get copied to a rootfs / installer image, or if creating an # contents get copied to a rootfs / installer image, or if creating an
# android recovery zip from its contents). # android recovery zip from its contents).
for marker in pmb.config.work.glob("chroot_*/in-pmbootstrap"): for marker in pmb.config.work.glob("chroot_*/in-pmbootstrap"):
pmb.helpers.run.root(args, ["rm", marker]) pmb.helpers.run.root(["rm", marker])
if not only_install_related: if not only_install_related:
# Umount all folders inside work dir # Umount all folders inside work dir

View file

@ -73,7 +73,7 @@ def zap(args: PmbArgs, confirm=True, dry=False, pkgs_local=False, http=False,
pmb.helpers.cli.confirm(args, f"Remove {match}?")): pmb.helpers.cli.confirm(args, f"Remove {match}?")):
logging.info(f"% rm -rf {match}") logging.info(f"% rm -rf {match}")
if not dry: if not dry:
pmb.helpers.run.root(args, ["rm", "-rf", match]) pmb.helpers.run.root(["rm", "-rf", match])
# Remove config init dates for deleted chroots # Remove config init dates for deleted chroots
pmb.config.workdir.clean(args) pmb.config.workdir.clean(args)
@ -120,7 +120,7 @@ def zap_pkgs_local_mismatch(args: PmbArgs, confirm=True, dry=False):
logging.info(f"% rm {apk_path_short}" logging.info(f"% rm {apk_path_short}"
f" ({origin} aport not found)") f" ({origin} aport not found)")
if not dry: if not dry:
pmb.helpers.run.root(args, ["rm", apk_path]) pmb.helpers.run.root(["rm", apk_path])
reindex = True reindex = True
continue continue
@ -131,7 +131,7 @@ def zap_pkgs_local_mismatch(args: PmbArgs, confirm=True, dry=False):
logging.info(f"% rm {apk_path_short}" logging.info(f"% rm {apk_path_short}"
f" ({origin} aport: {version_aport})") f" ({origin} aport: {version_aport})")
if not dry: if not dry:
pmb.helpers.run.root(args, ["rm", apk_path]) pmb.helpers.run.root(["rm", apk_path])
reindex = True reindex = True
if reindex: if reindex:

View file

@ -131,7 +131,7 @@ def copy_git_repo_to_chroot(args: PmbArgs, topdir):
handle.write(file) handle.write(file)
handle.write("\n") handle.write("\n")
pmb.helpers.run.user(args, ["tar", "-cf", tarball_path, "-T", pmb.helpers.run.user(["tar", "-cf", tarball_path, "-T",
f"{tarball_path}.files"], topdir) f"{tarball_path}.files"], topdir)
ci_dir = Path("/home/pmos/ci") ci_dir = Path("/home/pmos/ci")
@ -168,7 +168,7 @@ def run_scripts(args: PmbArgs, topdir, scripts):
f" [{where}] ***") f" [{where}] ***")
if "native" in script["options"]: if "native" in script["options"]:
rc = pmb.helpers.run.user(args, [script_path], topdir, rc = pmb.helpers.run.user([script_path], topdir,
output="tui") output="tui")
continue continue
else: else:

View file

@ -452,13 +452,14 @@ def ask_for_device(args: PmbArgs):
def ask_for_additional_options(args: PmbArgs, cfg): def ask_for_additional_options(args: PmbArgs, cfg):
context = pmb.core.get_context()
# Allow to skip additional options # Allow to skip additional options
logging.info("Additional options:" logging.info("Additional options:"
f" extra free space: {args.extra_space} MB," f" extra free space: {args.extra_space} MB,"
f" boot partition size: {args.boot_size} MB," f" boot partition size: {args.boot_size} MB,"
f" parallel jobs: {args.jobs}," f" parallel jobs: {args.jobs},"
f" ccache per arch: {args.ccache_size}," f" ccache per arch: {args.ccache_size},"
f" sudo timer: {args.sudo_timer}," f" sudo timer: {context.sudo_timer},"
f" mirror: {','.join(args.mirrors_postmarketos)}") f" mirror: {','.join(args.mirrors_postmarketos)}")
if not pmb.helpers.cli.confirm(args, "Change them?", if not pmb.helpers.cli.confirm(args, "Change them?",
@ -510,7 +511,7 @@ def ask_for_additional_options(args: PmbArgs, cfg):
" that you'll have to authorize sudo more than once.") " that you'll have to authorize sudo more than once.")
answer = pmb.helpers.cli.confirm(args, "Enable background timer to prevent" answer = pmb.helpers.cli.confirm(args, "Enable background timer to prevent"
" repeated sudo authorization?", " repeated sudo authorization?",
default=args.sudo_timer) default=context.sudo_timer)
cfg["pmbootstrap"]["sudo_timer"] = str(answer) cfg["pmbootstrap"]["sudo_timer"] = str(answer)
# Mirrors # Mirrors

View file

@ -211,7 +211,7 @@ def switch_to_channel_branch(args: PmbArgs, channel_new):
# Attempt to switch branch (git gives a nice error message, mentioning # Attempt to switch branch (git gives a nice error message, mentioning
# which files need to be committed/stashed, so just pass it through) # which files need to be committed/stashed, so just pass it through)
if pmb.helpers.run.user(args, ["git", "checkout", branch_new], if pmb.helpers.run.user(["git", "checkout", branch_new],
args.aports, "interactive", check=False): args.aports, "interactive", check=False):
raise RuntimeError("Failed to switch branch. Go to your pmaports and" raise RuntimeError("Failed to switch branch. Go to your pmaports and"
" fix what git complained about, then try again: " " fix what git complained about, then try again: "
@ -232,5 +232,5 @@ def install_githooks(args: PmbArgs):
# Use git default hooks dir so users can ignore our hooks # Use git default hooks dir so users can ignore our hooks
# if they dislike them by setting "core.hooksPath" git config # if they dislike them by setting "core.hooksPath" git config
dst = os.path.join(args.aports, ".git", "hooks", h) dst = os.path.join(args.aports, ".git", "hooks", h)
if pmb.helpers.run.user(args, ["cp", src, dst], check=False): if pmb.helpers.run.user(["cp", src, dst], check=False):
logging.warning(f"WARNING: Copying git hook failed: {dst}") logging.warning(f"WARNING: Copying git hook failed: {dst}")

View file

@ -13,7 +13,7 @@ def frontend(args: PmbArgs):
# Create the export folder # Create the export folder
target = args.export_folder target = args.export_folder
if not os.path.exists(target): if not os.path.exists(target):
pmb.helpers.run.user(args, ["mkdir", "-p", target]) pmb.helpers.run.user(["mkdir", "-p", target])
# Rootfs image note # Rootfs image note
chroot = Chroot.native() chroot = Chroot.native()

View file

@ -24,11 +24,11 @@ def _prepare_fifo(args: PmbArgs):
path of the fifo as needed by cat to read from it (always path of the fifo as needed by cat to read from it (always
relative to the host) relative to the host)
""" """
pmb.helpers.run.root(args, ["mkdir", "-p", pmb.config.work / "tmp"]) pmb.helpers.run.root(["mkdir", "-p", pmb.config.work / "tmp"])
fifo = fifo_outside = pmb.config.work / "tmp/apk_progress_fifo" fifo = fifo_outside = pmb.config.work / "tmp/apk_progress_fifo"
if os.path.exists(fifo_outside): if os.path.exists(fifo_outside):
pmb.helpers.run.root(args, ["rm", "-f", fifo_outside]) pmb.helpers.run.root(["rm", "-f", fifo_outside])
pmb.helpers.run.root(args, ["mkfifo", fifo_outside]) pmb.helpers.run.root(["mkfifo", fifo_outside])
return (fifo, fifo_outside) return (fifo, fifo_outside)
@ -75,16 +75,16 @@ def apk_with_progress(args: PmbArgs, command: Sequence[PathString]):
_command: List[str] = [os.fspath(c) for c in command] _command: List[str] = [os.fspath(c) for c in command]
command_with_progress = _create_command_with_progress(_command, fifo) command_with_progress = _create_command_with_progress(_command, fifo)
log_msg = " ".join(_command) log_msg = " ".join(_command)
with pmb.helpers.run.root(args, ['cat', fifo], with pmb.helpers.run.root(['cat', fifo],
output="pipe") as p_cat: output="pipe") as p_cat:
with pmb.helpers.run.root(args, command_with_progress, with pmb.helpers.run.root(command_with_progress,
output="background") as p_apk: output="background") as p_apk:
while p_apk.poll() is None: while p_apk.poll() is None:
line = p_cat.stdout.readline().decode('utf-8') line = p_cat.stdout.readline().decode('utf-8')
progress = _compute_progress(line) progress = _compute_progress(line)
pmb.helpers.cli.progress_print(args, progress) pmb.helpers.cli.progress_print(args, progress)
pmb.helpers.cli.progress_flush(args) pmb.helpers.cli.progress_flush(args)
pmb.helpers.run_core.check_return_code(args, p_apk.returncode, pmb.helpers.run_core.check_return_code(p_apk.returncode,
log_msg) log_msg)

View file

@ -101,4 +101,4 @@ def symlink(args: PmbArgs, file: Path, link: Path):
link.unlink() link.unlink()
# Create the symlink # Create the symlink
pmb.helpers.run.user(args, ["ln", "-s", file, link]) pmb.helpers.run.user(["ln", "-s", file, link])

View file

@ -562,11 +562,12 @@ def work_migrate(args: PmbArgs):
def log(args: PmbArgs): def log(args: PmbArgs):
context = pmb.core.get_context()
log_testsuite = pmb.config.work / "log_testsuite.txt" log_testsuite = pmb.config.work / "log_testsuite.txt"
if args.clear_log: if args.clear_log:
pmb.helpers.run.user(args, ["truncate", "-s", "0", args.log]) pmb.helpers.run.user(["truncate", "-s", "0", context.log])
pmb.helpers.run.user(args, ["truncate", "-s", "0", log_testsuite]) pmb.helpers.run.user(["truncate", "-s", "0", log_testsuite])
cmd: List[PathString] = ["tail", "-n", args.lines, "-F"] cmd: List[PathString] = ["tail", "-n", args.lines, "-F"]
@ -578,9 +579,9 @@ def log(args: PmbArgs):
# tail writes the last lines of the files to the terminal. Put the regular # tail writes the last lines of the files to the terminal. Put the regular
# log at the end, so that output is visible at the bottom (where the user # log at the end, so that output is visible at the bottom (where the user
# looks for an error / what's currently going on). # looks for an error / what's currently going on).
cmd += [args.log] cmd += [context.log]
pmb.helpers.run.user(args, cmd, output="tui") pmb.helpers.run.user(cmd, output="tui")
def zap(args: PmbArgs): def zap(args: PmbArgs):

View file

@ -49,7 +49,7 @@ def clone(args: PmbArgs, name_repo):
# Create parent dir and clone # Create parent dir and clone
logging.info("Clone git repository: " + url) logging.info("Clone git repository: " + url)
os.makedirs(pmb.config.work / "cache_git", exist_ok=True) os.makedirs(pmb.config.work / "cache_git", exist_ok=True)
pmb.helpers.run.user(args, command, output="stdout") pmb.helpers.run.user(command, output="stdout")
# FETCH_HEAD does not exist after initial clone. Create it, so # FETCH_HEAD does not exist after initial clone. Create it, so
# is_outdated() can use it. # is_outdated() can use it.
@ -68,13 +68,13 @@ def rev_parse(args: PmbArgs, path, revision="HEAD", extra_args: list = []):
or (with ``--abbrev-ref``): the branch name, e.g. "master" or (with ``--abbrev-ref``): the branch name, e.g. "master"
""" """
command = ["git", "rev-parse"] + extra_args + [revision] command = ["git", "rev-parse"] + extra_args + [revision]
rev = pmb.helpers.run.user_output(args, command, path) rev = pmb.helpers.run.user_output(command, path)
return rev.rstrip() return rev.rstrip()
def can_fast_forward(args: PmbArgs, path, branch_upstream, branch="HEAD"): def can_fast_forward(args: PmbArgs, path, branch_upstream, branch="HEAD"):
command = ["git", "merge-base", "--is-ancestor", branch, branch_upstream] command = ["git", "merge-base", "--is-ancestor", branch, branch_upstream]
ret = pmb.helpers.run.user(args, command, path, check=False) ret = pmb.helpers.run.user(command, path, check=False)
if ret == 0: if ret == 0:
return True return True
elif ret == 1: elif ret == 1:
@ -86,7 +86,7 @@ def can_fast_forward(args: PmbArgs, path, branch_upstream, branch="HEAD"):
def clean_worktree(args: PmbArgs, path): def clean_worktree(args: PmbArgs, path):
"""Check if there are not any modified files in the git dir.""" """Check if there are not any modified files in the git dir."""
command = ["git", "status", "--porcelain"] command = ["git", "status", "--porcelain"]
return pmb.helpers.run.user_output(args, command, path) == "" return pmb.helpers.run.user_output(command, path) == ""
def get_upstream_remote(args: PmbArgs, name_repo): def get_upstream_remote(args: PmbArgs, name_repo):
@ -97,7 +97,7 @@ def get_upstream_remote(args: PmbArgs, name_repo):
urls = pmb.config.git_repos[name_repo] urls = pmb.config.git_repos[name_repo]
path = get_path(args, name_repo) path = get_path(args, name_repo)
command = ["git", "remote", "-v"] command = ["git", "remote", "-v"]
output = pmb.helpers.run.user_output(args, command, path) output = pmb.helpers.run.user_output(command, path)
for line in output.split("\n"): for line in output.split("\n"):
if any(u in line for u in urls): if any(u in line for u in urls):
return line.split("\t", 1)[0] return line.split("\t", 1)[0]
@ -129,7 +129,7 @@ def parse_channels_cfg(args):
else: else:
remote = get_upstream_remote(args, "pmaports") remote = get_upstream_remote(args, "pmaports")
command = ["git", "show", f"{remote}/master:channels.cfg"] command = ["git", "show", f"{remote}/master:channels.cfg"]
stdout = pmb.helpers.run.user_output(args, command, args.aports, stdout = pmb.helpers.run.user_output(command, args.aports,
check=False) check=False)
try: try:
cfg.read_string(stdout) cfg.read_string(stdout)
@ -223,7 +223,7 @@ def pull(args: PmbArgs, name_repo):
# Fetch (exception on failure, meaning connection to server broke) # Fetch (exception on failure, meaning connection to server broke)
logging.info(msg_start + " git pull --ff-only") logging.info(msg_start + " git pull --ff-only")
if not args.offline: if not args.offline:
pmb.helpers.run.user(args, ["git", "fetch"], path) pmb.helpers.run.user(["git", "fetch"], path)
# Skip if already up to date # Skip if already up to date
if rev_parse(args, path, branch) == rev_parse(args, path, branch_upstream): if rev_parse(args, path, branch) == rev_parse(args, path, branch_upstream):
@ -240,7 +240,7 @@ def pull(args: PmbArgs, name_repo):
# Fast-forward now (should not fail due to checks above, so it's fine to # Fast-forward now (should not fail due to checks above, so it's fine to
# throw an exception on error) # throw an exception on error)
command = ["git", "merge", "--ff-only", branch_upstream] command = ["git", "merge", "--ff-only", branch_upstream]
pmb.helpers.run.user(args, command, path, "stdout") pmb.helpers.run.user(command, path, "stdout")
return 0 return 0
@ -250,7 +250,7 @@ def get_topdir(args: PmbArgs, path: Path):
:returns: a string with the top dir of the git repository, :returns: a string with the top dir of the git repository,
or an empty string if it's not a git repository. or an empty string if it's not a git repository.
""" """
return pmb.helpers.run.user(args, ["git", "rev-parse", "--show-toplevel"], return pmb.helpers.run.user(["git", "rev-parse", "--show-toplevel"],
path, output_return=True, check=False).rstrip() path, output_return=True, check=False).rstrip()
@ -264,8 +264,8 @@ def get_files(args: PmbArgs, path):
:returns: all files in a git repository as list, relative to path :returns: all files in a git repository as list, relative to path
""" """
ret = [] ret = []
files = pmb.helpers.run.user_output(args, ["git", "ls-files"], path).split("\n") files = pmb.helpers.run.user_output(["git", "ls-files"], path).split("\n")
files += pmb.helpers.run.user_output(args, ["git", "ls-files", files += pmb.helpers.run.user_output(["git", "ls-files",
"--exclude-standard", "--other"], "--exclude-standard", "--other"],
path).split("\n") path).split("\n")
for file in files: for file in files:

View file

@ -35,14 +35,14 @@ def download(args: PmbArgs, url, prefix, cache=True, loglevel=logging.INFO,
""" """
# Create cache folder # Create cache folder
if not os.path.exists(pmb.config.work / "cache_http"): if not os.path.exists(pmb.config.work / "cache_http"):
pmb.helpers.run.user(args, ["mkdir", "-p", pmb.config.work / "cache_http"]) pmb.helpers.run.user(["mkdir", "-p", pmb.config.work / "cache_http"])
# Check if file exists in cache # Check if file exists in cache
path = pmb.config.work / "cache_http" / cache_file(prefix, url) path = pmb.config.work / "cache_http" / cache_file(prefix, url)
if os.path.exists(path): if os.path.exists(path):
if cache: if cache:
return path return path
pmb.helpers.run.user(args, ["rm", path]) pmb.helpers.run.user(["rm", path])
# Offline and not cached # Offline and not cached
if args.offline: if args.offline:

View file

@ -44,12 +44,12 @@ def bind(args: PmbArgs, source: Path, destination: Path, create_folders=True, um
if os.path.exists(path): if os.path.exists(path):
continue continue
if create_folders: if create_folders:
pmb.helpers.run.root(args, ["mkdir", "-p", path]) pmb.helpers.run.root(["mkdir", "-p", path])
else: else:
raise RuntimeError(f"Mount failed, folder does not exist: {path}") raise RuntimeError(f"Mount failed, folder does not exist: {path}")
# Actually mount the folder # Actually mount the folder
pmb.helpers.run.root(args, ["mount", "--bind", source, destination]) pmb.helpers.run.root(["mount", "--bind", source, destination])
# Verify that it has worked # Verify that it has worked
if not ismount(destination): if not ismount(destination):
@ -67,12 +67,12 @@ def bind_file(args: PmbArgs, source: Path, destination: Path, create_folders=Fal
if create_folders: if create_folders:
dest_dir: Path = destination.parent dest_dir: Path = destination.parent
if not dest_dir.is_dir(): if not dest_dir.is_dir():
pmb.helpers.run.root(args, ["mkdir", "-p", dest_dir]) pmb.helpers.run.root(["mkdir", "-p", dest_dir])
pmb.helpers.run.root(args, ["touch", destination]) pmb.helpers.run.root(["touch", destination])
# Mount # Mount
pmb.helpers.run.root(args, ["mount", "--bind", source, pmb.helpers.run.root(["mount", "--bind", source,
destination]) destination])
@ -101,7 +101,7 @@ def umount_all_list(prefix: Path, source: Path=Path("/proc/mounts")) -> List[Pat
def umount_all(args: PmbArgs, folder: Path): def umount_all(args: PmbArgs, folder: Path):
"""Umount all folders that are mounted inside a given folder.""" """Umount all folders that are mounted inside a given folder."""
for mountpoint in umount_all_list(folder): for mountpoint in umount_all_list(folder):
pmb.helpers.run.root(args, ["umount", mountpoint]) pmb.helpers.run.root(["umount", mountpoint])
if ismount(mountpoint): if ismount(mountpoint):
raise RuntimeError(f"Failed to umount: {mountpoint}") raise RuntimeError(f"Failed to umount: {mountpoint}")

View file

@ -23,7 +23,7 @@ def folder_size(args: PmbArgs, path: Path):
:returns: folder size in kilobytes :returns: folder size in kilobytes
""" """
output = pmb.helpers.run.root(args, ["du", "-ks", output = pmb.helpers.run.root(["du", "-ks",
path], output_return=True) path], output_return=True)
# Only look at last line to filter out sudo garbage (#1766) # Only look at last line to filter out sudo garbage (#1766)
@ -60,10 +60,10 @@ def check_binfmt_misc(args):
return return
# check=False: this might be built-in instead of being a module # check=False: this might be built-in instead of being a module
pmb.helpers.run.root(args, ["modprobe", "binfmt_misc"], check=False) pmb.helpers.run.root(["modprobe", "binfmt_misc"], check=False)
# check=False: we check it below and print a more helpful message on error # check=False: we check it below and print a more helpful message on error
pmb.helpers.run.root(args, ["mount", "-t", "binfmt_misc", "none", pmb.helpers.run.root(["mount", "-t", "binfmt_misc", "none",
"/proc/sys/fs/binfmt_misc"], check=False) "/proc/sys/fs/binfmt_misc"], check=False)
if not os.path.exists(path): if not os.path.exists(path):
@ -108,7 +108,7 @@ def migrate_work_folder(args: PmbArgs):
pmb.chroot.zap(args, False) pmb.chroot.zap(args, False)
conf = pmb.config.work / "config_abuild/abuild.conf" conf = pmb.config.work / "config_abuild/abuild.conf"
if os.path.exists(conf): if os.path.exists(conf):
pmb.helpers.run.root(args, ["sed", "-i", pmb.helpers.run.root(["sed", "-i",
"s./home/user/./home/pmos/.g", conf]) "s./home/user/./home/pmos/.g", conf])
# Update version file # Update version file
migrate_success(args, 1) migrate_success(args, 1)
@ -165,7 +165,7 @@ def migrate_work_folder(args: PmbArgs):
pmb.config.init.require_programs() pmb.config.init.require_programs()
if os.path.exists(path): if os.path.exists(path):
uid_gid = "{}:{}".format(os.getuid(), os.getgid()) uid_gid = "{}:{}".format(os.getuid(), os.getgid())
pmb.helpers.run.root(args, ["chown", "-R", uid_gid, path]) pmb.helpers.run.root(["chown", "-R", uid_gid, path])
else: else:
os.makedirs(path, 0o700, True) os.makedirs(path, 0o700, True)
@ -188,7 +188,7 @@ def migrate_work_folder(args: PmbArgs):
# Move packages to edge subdir # Move packages to edge subdir
edge_path = pmb.config.work / "packages/edge" edge_path = pmb.config.work / "packages/edge"
pmb.helpers.run.root(args, ["mkdir", "-p", edge_path]) pmb.helpers.run.root(["mkdir", "-p", edge_path])
for arch in pmb.config.build_device_architectures: for arch in pmb.config.build_device_architectures:
old_path = pmb.config.work / "packages" / arch old_path = pmb.config.work / "packages" / arch
new_path = edge_path / arch new_path = edge_path / arch
@ -198,8 +198,8 @@ def migrate_work_folder(args: PmbArgs):
f" '{new_path}', destination already" f" '{new_path}', destination already"
" exists! Consider 'pmbootstrap zap -p'" " exists! Consider 'pmbootstrap zap -p'"
f" to delete '{pmb.config.work}/packages'.") f" to delete '{pmb.config.work}/packages'.")
pmb.helpers.run.root(args, ["mv", old_path, new_path]) pmb.helpers.run.root(["mv", old_path, new_path])
pmb.helpers.run.root(args, ["chown", pmb.config.chroot_uid_user, pmb.helpers.run.root(["chown", pmb.config.chroot_uid_user,
edge_path]) edge_path])
# Update version file # Update version file
@ -228,7 +228,7 @@ def migrate_work_folder(args: PmbArgs):
packages_dir = f"{pmb.config.work}/packages" packages_dir = f"{pmb.config.work}/packages"
for old, new in pmb.config.pmaports_channels_legacy.items(): for old, new in pmb.config.pmaports_channels_legacy.items():
if os.path.exists(f"{packages_dir}/{old}"): if os.path.exists(f"{packages_dir}/{old}"):
pmb.helpers.run.root(args, ["mv", old, new], packages_dir) pmb.helpers.run.root(["mv", old, new], packages_dir)
# Update version file # Update version file
migrate_success(args, 6) migrate_success(args, 6)

View file

@ -194,8 +194,8 @@ def update(args: PmbArgs, arch=None, force=False, existing_only=False):
continue continue
target_folder = os.path.dirname(target) target_folder = os.path.dirname(target)
if not os.path.exists(target_folder): if not os.path.exists(target_folder):
pmb.helpers.run.root(args, ["mkdir", "-p", target_folder]) pmb.helpers.run.root(["mkdir", "-p", target_folder])
pmb.helpers.run.root(args, ["cp", temp, target]) pmb.helpers.run.root(["cp", temp, target])
pmb.helpers.cli.progress_flush(args) pmb.helpers.cli.progress_flush(args)
return True return True

View file

@ -8,7 +8,7 @@ from typing import Any, Dict, List, Optional, Sequence
from pmb.core.types import Env, PathString, PmbArgs from pmb.core.types import Env, PathString, PmbArgs
def user(args: PmbArgs, cmd: Sequence[PathString], working_dir: Optional[Path] = None, output: str = "log", output_return: bool = False, def user(cmd: Sequence[PathString], working_dir: Optional[Path] = None, output: str = "log", output_return: bool = False,
check: Optional[bool] = None, env: Env = {}, sudo: bool = False) -> str | int | subprocess.Popen: check: Optional[bool] = None, env: Env = {}, sudo: bool = False) -> str | int | subprocess.Popen:
""" """
Run a command on the host system as user. Run a command on the host system as user.
@ -33,20 +33,20 @@ def user(args: PmbArgs, cmd: Sequence[PathString], working_dir: Optional[Path] =
pmb.helpers.run_core.add_proxy_env_vars(env) pmb.helpers.run_core.add_proxy_env_vars(env)
if env: if env:
cmd_parts = ["sh", "-c", pmb.helpers.run_core.flat_cmd(cmd_parts, env=env)] cmd_parts = ["sh", "-c", pmb.helpers.run_core.flat_cmd(cmd_parts, env=env)]
return pmb.helpers.run_core.core(args, msg, cmd_parts, working_dir, output, return pmb.helpers.run_core.core(msg, cmd_parts, working_dir, output,
output_return, check, sudo) output_return, check, sudo)
# FIXME: should probably use some kind of wrapper class / builder pattern for all these parameters... # FIXME: should probably use some kind of wrapper class / builder pattern for all these parameters...
def user_output(args: PmbArgs, cmd: Sequence[PathString], working_dir: Optional[Path] = None, output: str = "log", def user_output(cmd: Sequence[PathString], working_dir: Optional[Path] = None, output: str = "log",
check: Optional[bool] = None, env: Env = {}, sudo: bool = False) -> str: check: Optional[bool] = None, env: Env = {}, sudo: bool = False) -> str:
ret = user(args, cmd, working_dir, output, output_return=True, check=check, env=env, sudo=sudo) ret = user(cmd, working_dir, output, output_return=True, check=check, env=env, sudo=sudo)
if not isinstance(ret, str): if not isinstance(ret, str):
raise TypeError("Expected str output, got " + str(ret)) raise TypeError("Expected str output, got " + str(ret))
return ret return ret
def root(args: PmbArgs, cmd: Sequence[PathString], working_dir=None, output="log", output_return=False, def root(cmd: Sequence[PathString], working_dir=None, output="log", output_return=False,
check=None, env={}): check=None, env={}):
"""Run a command on the host system as root, with sudo or doas. """Run a command on the host system as root, with sudo or doas.
@ -63,5 +63,5 @@ def root(args: PmbArgs, cmd: Sequence[PathString], working_dir=None, output="log
cmd = ["sh", "-c", pmb.helpers.run_core.flat_cmd(cmd, env=env)] cmd = ["sh", "-c", pmb.helpers.run_core.flat_cmd(cmd, env=env)]
cmd = pmb.config.sudo(cmd) cmd = pmb.config.sudo(cmd)
return user(args, cmd, working_dir, output, output_return, check, env, return user(cmd, working_dir, output, output_return, check, env,
True) True)

View file

@ -15,8 +15,6 @@ import time
from typing import Dict, Optional, Sequence from typing import Dict, Optional, Sequence
import pmb.helpers.run import pmb.helpers.run
from pmb.core.types import Env, PathString, PmbArgs
"""For a detailed description of all output modes, read the description of """For a detailed description of all output modes, read the description of
core() at the bottom. All other functions in this file get (indirectly) core() at the bottom. All other functions in this file get (indirectly)
called by core(). """ called by core(). """
@ -118,7 +116,7 @@ def pipe_read(process, output_to_stdout=False, output_return=False,
return return
def kill_process_tree(args: PmbArgs, pid, ppids, sudo): def kill_process_tree(pid, ppids, sudo):
"""Recursively kill a pid and its child processes. """Recursively kill a pid and its child processes.
:param pid: process id that will be killed :param pid: process id that will be killed
@ -126,18 +124,18 @@ def kill_process_tree(args: PmbArgs, pid, ppids, sudo):
:param sudo: use sudo to kill the process :param sudo: use sudo to kill the process
""" """
if sudo: if sudo:
pmb.helpers.run.root(args, ["kill", "-9", str(pid)], pmb.helpers.run.root(["kill", "-9", str(pid)],
check=False) check=False)
else: else:
pmb.helpers.run.user(args, ["kill", "-9", str(pid)], pmb.helpers.run.user(["kill", "-9", str(pid)],
check=False) check=False)
for (child_pid, child_ppid) in ppids: for (child_pid, child_ppid) in ppids:
if child_ppid == str(pid): if child_ppid == str(pid):
kill_process_tree(args, child_pid, ppids, sudo) kill_process_tree(child_pid, ppids, sudo)
def kill_command(args: PmbArgs, pid, sudo): def kill_command(pid, sudo):
"""Kill a command process and recursively kill its child processes. """Kill a command process and recursively kill its child processes.
:param pid: process id that will be killed :param pid: process id that will be killed
@ -153,10 +151,10 @@ def kill_command(args: PmbArgs, pid, sudo):
raise RuntimeError("Unexpected ps output: " + row) raise RuntimeError("Unexpected ps output: " + row)
ppids.append(items) ppids.append(items)
kill_process_tree(args, pid, ppids, sudo) kill_process_tree(pid, ppids, sudo)
def foreground_pipe(args: PmbArgs, cmd, working_dir=None, output_to_stdout=False, def foreground_pipe(cmd, working_dir=None, output_to_stdout=False,
output_return=False, output_timeout=True, output_return=False, output_timeout=True,
sudo=False, stdin=None): sudo=False, stdin=None):
"""Run a subprocess in foreground with redirected output. """Run a subprocess in foreground with redirected output.
@ -238,7 +236,7 @@ def foreground_tui(cmd, working_dir=None):
return process.wait() return process.wait()
def check_return_code(args: PmbArgs, code, log_message): def check_return_code(code, log_message):
"""Check the return code of a command. """Check the return code of a command.
:param code: exit code to check :param code: exit code to check
@ -249,8 +247,9 @@ def check_return_code(args: PmbArgs, code, log_message):
""" """
if code: if code:
logging.debug("^" * 70) logging.debug("^" * 70)
log_file = get_context().log
logging.info("NOTE: The failed command's output is above the ^^^ line" logging.info("NOTE: The failed command's output is above the ^^^ line"
f" in the log file: {args.log}") f" in the log file: {log_file}")
raise RuntimeError(f"Command failed (exit code {str(code)}): " + raise RuntimeError(f"Command failed (exit code {str(code)}): " +
log_message) log_message)
@ -297,7 +296,7 @@ def add_proxy_env_vars(env):
env[var] = os.environ[var] env[var] = os.environ[var]
def core(args: PmbArgs, log_message, cmd, working_dir=None, output="log", def core(log_message, cmd, working_dir=None, output="log",
output_return=False, check=None, sudo=False, disable_timeout=False): output_return=False, check=None, sudo=False, disable_timeout=False):
"""Run a command and create a log entry. """Run a command and create a log entry.
@ -354,8 +353,9 @@ def core(args: PmbArgs, log_message, cmd, working_dir=None, output="log",
* the program's entire output (output_return is True) * the program's entire output (output_return is True)
""" """
sanity_checks(output, output_return, check) sanity_checks(output, output_return, check)
context = pmb.core.get_context()
if args.sudo_timer and sudo: if context.sudo_timer and sudo:
sudo_timer_start() sudo_timer_start()
# Log simplified and full command (pmbootstrap -v) # Log simplified and full command (pmbootstrap -v)
@ -383,14 +383,14 @@ def core(args: PmbArgs, log_message, cmd, working_dir=None, output="log",
else: else:
# Foreground pipe (always redirects to the error log file) # Foreground pipe (always redirects to the error log file)
output_to_stdout = False output_to_stdout = False
if not args.details_to_stdout and output in ["stdout", "interactive"]: if not context.details_to_stdout and output in ["stdout", "interactive"]:
output_to_stdout = True output_to_stdout = True
output_timeout = output in ["log", "stdout"] and not disable_timeout output_timeout = output in ["log", "stdout"] and not disable_timeout
stdin = subprocess.DEVNULL if output in ["log", "stdout"] else None stdin = subprocess.DEVNULL if output in ["log", "stdout"] else None
(code, output_after_run) = foreground_pipe(args, cmd, working_dir, (code, output_after_run) = foreground_pipe(cmd, working_dir,
output_to_stdout, output_to_stdout,
output_return, output_return,
output_timeout, output_timeout,
@ -398,7 +398,7 @@ def core(args: PmbArgs, log_message, cmd, working_dir=None, output="log",
# Check the return code # Check the return code
if check is not False: if check is not False:
check_return_code(args, code, log_message) check_return_code(code, log_message)
# Return (code or output string) # Return (code or output string)
return output_after_run if output_return else code return output_after_run if output_return else code

View file

@ -118,12 +118,12 @@ def copy_files_from_chroot(args: PmbArgs, chroot: Chroot):
arch_qemu = pmb.parse.arch.alpine_to_qemu(args.deviceinfo["arch"]) arch_qemu = pmb.parse.arch.alpine_to_qemu(args.deviceinfo["arch"])
qemu_binary = mountpoint_outside / ("/usr/bin/qemu-" + arch_qemu + "-static") qemu_binary = mountpoint_outside / ("/usr/bin/qemu-" + arch_qemu + "-static")
if os.path.exists(qemu_binary): if os.path.exists(qemu_binary):
pmb.helpers.run.root(args, ["rm", qemu_binary]) pmb.helpers.run.root(["rm", qemu_binary])
# Remove apk progress fifo # Remove apk progress fifo
fifo = chroot / "tmp/apk_progress_fifo" fifo = chroot / "tmp/apk_progress_fifo"
if os.path.exists(fifo): if os.path.exists(fifo):
pmb.helpers.run.root(args, ["rm", fifo]) pmb.helpers.run.root(["rm", fifo])
# Get all folders inside the device rootfs (except for home) # Get all folders inside the device rootfs (except for home)
folders: List[str] = [] folders: List[str] = []
@ -153,14 +153,14 @@ def create_home_from_skel(args: PmbArgs):
rootfs = (Chroot.native() / "mnt/install") rootfs = (Chroot.native() / "mnt/install")
# In btrfs, home subvol & home dir is created in format.py # In btrfs, home subvol & home dir is created in format.py
if args.filesystem != "btrfs": if args.filesystem != "btrfs":
pmb.helpers.run.root(args, ["mkdir", rootfs / "home"]) pmb.helpers.run.root(["mkdir", rootfs / "home"])
home = (rootfs / "home" / args.user) home = (rootfs / "home" / args.user)
if (rootfs / "etc/skel").exists(): if (rootfs / "etc/skel").exists():
pmb.helpers.run.root(args, ["cp", "-a", (rootfs / "etc/skel"), home]) pmb.helpers.run.root(["cp", "-a", (rootfs / "etc/skel"), home])
else: else:
pmb.helpers.run.root(args, ["mkdir", home]) pmb.helpers.run.root(["mkdir", home])
pmb.helpers.run.root(args, ["chown", "-R", "10000", home]) pmb.helpers.run.root(["chown", "-R", "10000", home])
def configure_apk(args: PmbArgs): def configure_apk(args: PmbArgs):
@ -179,19 +179,19 @@ def configure_apk(args: PmbArgs):
# Copy over keys # Copy over keys
rootfs = (Chroot.native() / "mnt/install") rootfs = (Chroot.native() / "mnt/install")
for key in keys_dir.glob("*.pub"): for key in keys_dir.glob("*.pub"):
pmb.helpers.run.root(args, ["cp", key, rootfs / "etc/apk/keys/"]) pmb.helpers.run.root(["cp", key, rootfs / "etc/apk/keys/"])
# Copy over the corresponding APKINDEX files from cache # Copy over the corresponding APKINDEX files from cache
index_files = pmb.helpers.repo.apkindex_files(args, index_files = pmb.helpers.repo.apkindex_files(args,
arch=args.deviceinfo["arch"], arch=args.deviceinfo["arch"],
user_repository=False) user_repository=False)
for f in index_files: for f in index_files:
pmb.helpers.run.root(args, ["cp", f, rootfs / "var/cache/apk/"]) pmb.helpers.run.root(["cp", f, rootfs / "var/cache/apk/"])
# Disable pmbootstrap repository # Disable pmbootstrap repository
pmb.helpers.run.root(args, ["sed", "-i", r"/\/mnt\/pmbootstrap\/packages/d", pmb.helpers.run.root(["sed", "-i", r"/\/mnt\/pmbootstrap\/packages/d",
rootfs / "etc/apk/repositories"]) rootfs / "etc/apk/repositories"])
pmb.helpers.run.user(args, ["cat", rootfs / "etc/apk/repositories"]) pmb.helpers.run.user(["cat", rootfs / "etc/apk/repositories"])
def set_user(args: PmbArgs): def set_user(args: PmbArgs):
@ -311,11 +311,11 @@ def copy_ssh_keys(args: PmbArgs):
outfile.close() outfile.close()
target = Chroot.native() / "mnt/install/home/" / args.user / ".ssh" target = Chroot.native() / "mnt/install/home/" / args.user / ".ssh"
pmb.helpers.run.root(args, ["mkdir", target]) pmb.helpers.run.root(["mkdir", target])
pmb.helpers.run.root(args, ["chmod", "700", target]) pmb.helpers.run.root(["chmod", "700", target])
pmb.helpers.run.root(args, ["cp", authorized_keys, target / "authorized_keys"]) pmb.helpers.run.root(["cp", authorized_keys, target / "authorized_keys"])
pmb.helpers.run.root(args, ["rm", authorized_keys]) pmb.helpers.run.root(["rm", authorized_keys])
pmb.helpers.run.root(args, ["chown", "-R", "10000:10000", target]) pmb.helpers.run.root(["chown", "-R", "10000:10000", target])
def setup_keymap(args: PmbArgs): def setup_keymap(args: PmbArgs):
@ -854,7 +854,7 @@ def install_system_image(args: PmbArgs, size_reserve, chroot: Chroot, step, step
# Clean up after running mkinitfs in chroot # Clean up after running mkinitfs in chroot
pmb.helpers.mount.umount_all(args, chroot.path) pmb.helpers.mount.umount_all(args, chroot.path)
pmb.helpers.run.root(args, ["rm", chroot / "in-pmbootstrap"]) pmb.helpers.run.root(["rm", chroot / "in-pmbootstrap"])
pmb.chroot.remove_mnt_pmbootstrap(args, chroot) pmb.chroot.remove_mnt_pmbootstrap(args, chroot)
# Just copy all the files # Just copy all the files
@ -1028,7 +1028,7 @@ def install_on_device_installer(args: PmbArgs, step, steps):
img_path_src = Chroot.native() / "home/pmos/rootfs" / img img_path_src = Chroot.native() / "home/pmos/rootfs" / img
logging.info(f"({chroot_installer}) add {img} as /var/lib/rootfs.img") logging.info(f"({chroot_installer}) add {img} as /var/lib/rootfs.img")
pmb.install.losetup.umount(args, img_path_src) pmb.install.losetup.umount(args, img_path_src)
pmb.helpers.run.root(args, ["mv", img_path_src, img_path_dest]) pmb.helpers.run.root(["mv", img_path_src, img_path_dest])
# Run ondev-prepare, so it may generate nice configs from the channel # Run ondev-prepare, so it may generate nice configs from the channel
# properties (e.g. to display the version number), or transform the image # properties (e.g. to display the version number), or transform the image
@ -1053,7 +1053,7 @@ def install_on_device_installer(args: PmbArgs, step, steps):
host_dest = chroot_installer / chroot_dest host_dest = chroot_installer / chroot_dest
logging.info(f"({chroot_installer}) add {host_src} as" logging.info(f"({chroot_installer}) add {host_src} as"
f" {chroot_dest}") f" {chroot_dest}")
pmb.helpers.run.root(args, ["install", "-Dm644", host_src, pmb.helpers.run.root(["install", "-Dm644", host_src,
host_dest]) host_dest])
# Remove $DEVICE-boot.img (we will generate a new one if --split was # Remove $DEVICE-boot.img (we will generate a new one if --split was

View file

@ -36,7 +36,7 @@ def previous_install(args: PmbArgs, path: Path):
logging.info("WARNING: Could not get block device label," logging.info("WARNING: Could not get block device label,"
" assume no previous installation on that partition") " assume no previous installation on that partition")
pmb.helpers.run.root(args, ["umount", Chroot.native() / blockdevice_inside]) pmb.helpers.run.root(["umount", Chroot.native() / blockdevice_inside])
return "pmOS_boot" in label return "pmOS_boot" in label

View file

@ -17,7 +17,7 @@ from pmb.core import Chroot
def init(args: PmbArgs): def init(args: PmbArgs):
if not Path("/sys/module/loop").is_dir(): if not Path("/sys/module/loop").is_dir():
pmb.helpers.run.root(args, ["modprobe", "loop"]) pmb.helpers.run.root(["modprobe", "loop"])
for loopdevice in Path("/dev/").glob("loop*"): for loopdevice in Path("/dev/").glob("loop*"):
if loopdevice.is_dir(): if loopdevice.is_dir():
continue continue

View file

@ -86,8 +86,8 @@ def bootimg(args: PmbArgs, path: Path):
# Copy the boot.img into the chroot temporary folder # Copy the boot.img into the chroot temporary folder
# and make it world readable # and make it world readable
pmb.helpers.run.root(args, ["cp", path, bootimg_path]) pmb.helpers.run.root(["cp", path, bootimg_path])
pmb.helpers.run.root(args, ["chmod", "a+r", bootimg_path]) pmb.helpers.run.root(["chmod", "a+r", bootimg_path])
file_output = pmb.chroot.user(args, ["file", "-b", "boot.img"], file_output = pmb.chroot.user(args, ["file", "-b", "boot.img"],
working_dir=temp_path, working_dir=temp_path,

View file

@ -45,8 +45,8 @@ def create_second_storage(args: PmbArgs):
""" """
path = Chroot.native() / "home/pmos/rootfs" / f"{args.device}-2nd.img" path = Chroot.native() / "home/pmos/rootfs" / f"{args.device}-2nd.img"
pmb.helpers.run.root(args, ["touch", path]) pmb.helpers.run.root(["touch", path])
pmb.helpers.run.root(args, ["chmod", "a+w", path]) pmb.helpers.run.root(["chmod", "a+w", path])
resize_image(args, args.second_storage, path) resize_image(args, args.second_storage, path)
return path return path
@ -272,7 +272,7 @@ def resize_image(args: PmbArgs, img_size_new, img_path):
if (img_size_new_bytes >= img_size): if (img_size_new_bytes >= img_size):
logging.info(f"Resize image to {img_size_new}: {img_path}") logging.info(f"Resize image to {img_size_new}: {img_path}")
pmb.helpers.run.root(args, ["truncate", "-s", img_size_new, img_path]) pmb.helpers.run.root(["truncate", "-s", img_size_new, img_path])
else: else:
# Convert to human-readable format # Convert to human-readable format
# NOTE: We convert to M here, and not G, so that we don't have to # NOTE: We convert to M here, and not G, so that we don't have to
@ -352,7 +352,7 @@ def run(args: PmbArgs):
# Workaround: QEMU runs as local user and needs write permissions in the # Workaround: QEMU runs as local user and needs write permissions in the
# rootfs, which is owned by root # rootfs, which is owned by root
if not os.access(img_path, os.W_OK): if not os.access(img_path, os.W_OK):
pmb.helpers.run.root(args, ["chmod", "666", img_path]) pmb.helpers.run.root(["chmod", "666", img_path])
# Resize the rootfs (or show hint) # Resize the rootfs (or show hint)
if args.image_size: if args.image_size:
@ -380,7 +380,7 @@ def run(args: PmbArgs):
process = None process = None
try: try:
signal.signal(signal.SIGTERM, sigterm_handler) signal.signal(signal.SIGTERM, sigterm_handler)
process = pmb.helpers.run.user(args, qemu, output="tui", env=env) process = pmb.helpers.run.user(qemu, output="tui", env=env)
except KeyboardInterrupt: except KeyboardInterrupt:
# In addition to not showing a trace when pressing ^C, let user know # In addition to not showing a trace when pressing ^C, let user know
# they can override this behavior: # they can override this behavior:

View file

@ -27,7 +27,7 @@ def scp_abuild_key(args: PmbArgs, user: str, host: str, port: str):
logging.info(f"Copying signing key ({key_name}) to {user}@{host}") logging.info(f"Copying signing key ({key_name}) to {user}@{host}")
command: List[PathString] = ['scp', '-P', port, key, f'{user}@{host}:/tmp'] command: List[PathString] = ['scp', '-P', port, key, f'{user}@{host}:/tmp']
pmb.helpers.run.user(args, command, output="interactive") pmb.helpers.run.user(command, output="interactive")
logging.info(f"Installing signing key at {user}@{host}") logging.info(f"Installing signing key at {user}@{host}")
keyname = os.path.join("/tmp", os.path.basename(key)) keyname = os.path.join("/tmp", os.path.basename(key))
@ -35,14 +35,14 @@ def scp_abuild_key(args: PmbArgs, user: str, host: str, port: str):
'-S', 'mv', '-n', keyname, "/etc/apk/keys/"] '-S', 'mv', '-n', keyname, "/etc/apk/keys/"]
remote_cmd = pmb.helpers.run_core.flat_cmd(remote_cmd_l) remote_cmd = pmb.helpers.run_core.flat_cmd(remote_cmd_l)
command = ['ssh', '-t', '-p', port, 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(command, output="tui")
def ssh_find_arch(args: PmbArgs, user: str, host: str, port: str) -> str: def ssh_find_arch(args: PmbArgs, user: str, host: str, port: str) -> str:
"""Connect to a device via ssh and query the architecture.""" """Connect to a device via ssh and query the architecture."""
logging.info(f"Querying architecture of {user}@{host}") logging.info(f"Querying architecture of {user}@{host}")
command = ["ssh", "-p", port, f"{user}@{host}", "uname -m"] command = ["ssh", "-p", port, f"{user}@{host}", "uname -m"]
output = pmb.helpers.run.user_output(args, command) output = pmb.helpers.run.user_output(command)
# Split by newlines so we can pick out any irrelevant output, e.g. the "permanently # Split by newlines so we can pick out any irrelevant output, e.g. the "permanently
# added to list of known hosts" warnings. # added to list of known hosts" warnings.
output_lines = output.strip().splitlines() output_lines = output.strip().splitlines()
@ -66,7 +66,7 @@ def ssh_install_apks(args: PmbArgs, user, host, port, paths):
logging.info(f"Copying packages to {user}@{host}") logging.info(f"Copying packages to {user}@{host}")
command = ['scp', '-P', port] + 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(command, output="interactive")
logging.info(f"Installing packages at {user}@{host}") logging.info(f"Installing packages at {user}@{host}")
add_cmd = ['sudo', '-p', pmb.config.sideload_sudo_prompt, add_cmd = ['sudo', '-p', pmb.config.sideload_sudo_prompt,
@ -77,7 +77,7 @@ def ssh_install_apks(args: PmbArgs, user, host, port, paths):
# Run apk command in a subshell in case the foreign device has a non-POSIX shell. # Run apk command in a subshell in case the foreign device has a non-POSIX shell.
command = ['ssh', '-t', '-p', port, f'{user}@{host}', command = ['ssh', '-t', '-p', port, f'{user}@{host}',
f'sh -c {add_cmd_complete}'] f'sh -c {add_cmd_complete}']
pmb.helpers.run.user(args, command, output="tui") pmb.helpers.run.user(command, output="tui")
def sideload(args: PmbArgs, user: str, host: str, port: str, arch: str, copy_key: bool, pkgnames): def sideload(args: PmbArgs, user: str, host: str, port: str, arch: str, copy_key: bool, pkgnames):