mirror of
https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
synced 2025-07-13 11:29:46 +03:00
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:
parent
02f04ba3a8
commit
05c86be11c
42 changed files with 161 additions and 160 deletions
|
@ -70,10 +70,10 @@ def generate(args: PmbArgs, pkgname):
|
|||
aportgen = pmb.config.work / "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:
|
||||
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])
|
||||
pmb.aportgen.core.rewrite(args, pkgname, replace_simple={
|
||||
"# Contributor:*": None, "# Maintainer:*": None})
|
||||
|
@ -83,7 +83,7 @@ def generate(args: PmbArgs, pkgname):
|
|||
|
||||
# Move to the aports folder
|
||||
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(
|
||||
args, ["mv", aportgen, path_target])
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ def generate(args: PmbArgs, pkgname):
|
|||
tempdir = Path("/tmp/aportgen")
|
||||
aportgen = pmb.config.work / "aportgen"
|
||||
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])
|
||||
|
||||
# Write the APKBUILD
|
||||
|
@ -74,4 +74,4 @@ def generate(args: PmbArgs, pkgname):
|
|||
pmb.build.init_abuild_minimal(args)
|
||||
pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", 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])
|
||||
|
|
|
@ -175,7 +175,7 @@ def get_upstream_aport(args: PmbArgs, pkgname, arch=None):
|
|||
channel_cfg = pmb.config.pmaports.read_config_channel(args)
|
||||
branch = channel_cfg["branch_aports"]
|
||||
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):
|
||||
logging.info("NOTE: run 'pmbootstrap pull' and try again")
|
||||
logging.info("NOTE: if it still fails, your aports.git was cloned with"
|
||||
|
|
|
@ -237,7 +237,7 @@ def generate_deviceinfo(args: PmbArgs, pkgname, name, manufacturer, year, arch,
|
|||
content += content_uuu
|
||||
|
||||
# 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"
|
||||
with open(path, "w", encoding="utf-8") as handle:
|
||||
for line in content.rstrip().split("\n"):
|
||||
|
@ -258,7 +258,7 @@ def generate_modules_initfs(args: PmbArgs):
|
|||
"""
|
||||
|
||||
# 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"
|
||||
with open(path, "w", encoding="utf-8") as handle:
|
||||
for line in content.rstrip().split("\n"):
|
||||
|
@ -308,7 +308,7 @@ def generate_apkbuild(args: PmbArgs, pkgname, name, arch, flash_method):
|
|||
"""
|
||||
|
||||
# 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"
|
||||
with open(path, "w", encoding="utf-8") as handle:
|
||||
for line in content.rstrip().split("\n"):
|
||||
|
|
|
@ -22,7 +22,7 @@ def generate(args: PmbArgs, pkgname):
|
|||
else:
|
||||
raise ValueError(f"Invalid prefix '{prefix}', expected gcc, gcc4 or"
|
||||
" 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
|
||||
fields = {
|
||||
|
|
|
@ -24,7 +24,7 @@ def generate(args: PmbArgs, pkgname):
|
|||
tempdir = Path("/tmp/aportgen")
|
||||
aportgen = pmb.config.work / "aportgen"
|
||||
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])
|
||||
|
||||
# Write the APKBUILD
|
||||
|
@ -64,4 +64,4 @@ def generate(args: PmbArgs, pkgname):
|
|||
pmb.build.init_abuild_minimal(args)
|
||||
pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", 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])
|
||||
|
|
|
@ -115,7 +115,7 @@ def generate(args: PmbArgs, pkgname):
|
|||
deviceinfo = pmb.parse.deviceinfo(args, device)
|
||||
|
||||
# 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 = [
|
||||
"gcc7-give-up-on-ilog2-const-optimizations.patch",
|
||||
"gcc8-fix-put-user.patch",
|
||||
|
@ -123,7 +123,7 @@ def generate(args: PmbArgs, pkgname):
|
|||
"kernel-use-the-gnu89-standard-explicitly.patch",
|
||||
]
|
||||
for patch in patches:
|
||||
pmb.helpers.run.user(args, ["ln", "-s",
|
||||
pmb.helpers.run.user(["ln", "-s",
|
||||
"../../.shared-patches/linux/" + patch,
|
||||
(pmb.config.work / "aportgen" / patch)])
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ def generate(args: PmbArgs, pkgname):
|
|||
tempdir = Path("/tmp/aportgen")
|
||||
aportgen = pmb.config.work / "aportgen"
|
||||
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])
|
||||
|
||||
# Write the APKBUILD
|
||||
|
@ -100,4 +100,4 @@ def generate(args: PmbArgs, pkgname):
|
|||
pmb.build.init_abuild_minimal(args)
|
||||
pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", 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])
|
||||
|
|
|
@ -23,7 +23,7 @@ def update(args: PmbArgs, pkgname):
|
|||
# Copy modified APKBUILD back
|
||||
source = Chroot.native() / "home/pmos/build/APKBUILD"
|
||||
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):
|
||||
|
|
|
@ -95,10 +95,10 @@ def modify_apkbuild(args: PmbArgs, pkgname: str, aport: Path):
|
|||
apkbuild_path = aport + "/APKBUILD"
|
||||
apkbuild = pmb.parse.apkbuild(apkbuild_path)
|
||||
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(args, ["cp", "-r", apkbuild_path,
|
||||
pmb.helpers.run.user(["mkdir", pmb.config.work / "aportgen"])
|
||||
pmb.helpers.run.user(["cp", "-r", apkbuild_path,
|
||||
pmb.config.work / "aportgen"])
|
||||
|
||||
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])
|
||||
|
||||
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
|
||||
env = {"CARCH": arch,
|
||||
|
|
|
@ -162,7 +162,7 @@ def menuconfig(args: PmbArgs, pkgname: str, use_oldconfig):
|
|||
logging.info("Copy kernel config back to aport-folder")
|
||||
config = "config-" + apkbuild["_flavor"] + "." + arch
|
||||
target = aport / config
|
||||
pmb.helpers.run.user(args, ["cp", source, target])
|
||||
pmb.helpers.run.user(["cp", source, target])
|
||||
pmb.build.checksum.update(args, pkgname)
|
||||
|
||||
# Check config
|
||||
|
|
|
@ -44,11 +44,11 @@ def newapkbuild(args: PmbArgs, folder, args_passed, force=False):
|
|||
question = "Continue and delete its contents?"
|
||||
if not force and not pmb.helpers.cli.confirm(args, question):
|
||||
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)
|
||||
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("/*"):
|
||||
if not path.is_dir():
|
||||
pmb.helpers.run.user(args, ["cp", path, target])
|
||||
pmb.helpers.run.user(["cp", path, target])
|
||||
|
|
|
@ -28,10 +28,10 @@ def copy_to_buildpath(args: PmbArgs, package, chroot: Chroot=Chroot.native()):
|
|||
# Clean up folder
|
||||
build = chroot / "home/pmos/build"
|
||||
if build.exists():
|
||||
pmb.helpers.run.root(args, ["rm", "-rf", build])
|
||||
pmb.helpers.run.root(["rm", "-rf", build])
|
||||
|
||||
# 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():
|
||||
file = entry.name
|
||||
# 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"]:
|
||||
logging.warning(f"WARNING: Not copying {file}, looks like a leftover from abuild")
|
||||
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",
|
||||
"/home/pmos/build"], chroot)
|
||||
|
|
|
@ -49,7 +49,7 @@ def update_repository_list(args: PmbArgs, suffix: Chroot, postmarketos_mirror=Tr
|
|||
for line in handle:
|
||||
lines_old.append(line[:-1])
|
||||
else:
|
||||
pmb.helpers.run.root(args, ["mkdir", "-p", path.parent])
|
||||
pmb.helpers.run.root(["mkdir", "-p", path.parent])
|
||||
|
||||
# Up to date: Save cache, return
|
||||
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
|
||||
logging.debug(f"({suffix}) update /etc/apk/repositories")
|
||||
if path.exists():
|
||||
pmb.helpers.run.root(args, ["rm", path])
|
||||
pmb.helpers.run.root(["rm", path])
|
||||
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}"])
|
||||
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
|
||||
# packages, but only mark the right ones as explicitly installed.
|
||||
# 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):
|
||||
|
|
|
@ -86,7 +86,7 @@ def verify_signature(args: PmbArgs, files, sigkey_path):
|
|||
"""
|
||||
logging.debug(f"Verify apk.static signature with {sigkey_path}")
|
||||
try:
|
||||
pmb.helpers.run.user(args, ["openssl", "dgst", "-sha1", "-verify",
|
||||
pmb.helpers.run.user(["openssl", "dgst", "-sha1", "-verify",
|
||||
sigkey_path, "-signature", files[
|
||||
"sig"]["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"
|
||||
f" (must match the package version {version})")
|
||||
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]
|
||||
if not version.startswith(f"{version_bin}-r"):
|
||||
os.unlink(temp_path)
|
||||
|
|
|
@ -53,8 +53,7 @@ def register(args: PmbArgs, arch):
|
|||
# Register in binfmt_misc
|
||||
logging.info("Register qemu binfmt (" + arch_qemu + ")")
|
||||
register = "/proc/sys/fs/binfmt_misc/register"
|
||||
pmb.helpers.run.root(
|
||||
args, ["sh", "-c", 'echo "' + code + '" > ' + register])
|
||||
pmb.helpers.run.root(["sh", "-c", 'echo "' + code + '" > ' + register])
|
||||
|
||||
|
||||
def unregister(args: PmbArgs, arch):
|
||||
|
@ -63,4 +62,4 @@ def unregister(args: PmbArgs, arch):
|
|||
if not os.path.exists(binfmt_file):
|
||||
return
|
||||
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])
|
||||
|
|
|
@ -40,9 +40,9 @@ def copy_resolv_conf(args: PmbArgs, chroot: Chroot):
|
|||
resolv_path = chroot / host
|
||||
if os.path.exists(host):
|
||||
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:
|
||||
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()):
|
||||
|
@ -53,7 +53,7 @@ def mark_in_chroot(args: PmbArgs, chroot: Chroot=Chroot.native()):
|
|||
"""
|
||||
in_chroot_file = chroot / "in-pmbootstrap"
|
||||
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):
|
||||
|
@ -84,13 +84,13 @@ def init_keys(args: PmbArgs):
|
|||
target = pmb.config.work / "config_apk_keys" / key.name
|
||||
if not target.exists():
|
||||
# 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):
|
||||
logging.info(f"({chroot}) merge /usr")
|
||||
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])
|
||||
|
||||
|
||||
|
@ -148,7 +148,7 @@ def init(args: PmbArgs, chroot: Chroot=Chroot.native(), usr_merge=UsrMerge.AUTO,
|
|||
|
||||
# Initialize cache
|
||||
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"])
|
||||
|
||||
# Initialize /etc/apk/keys/, resolv.conf, repositories
|
||||
|
|
|
@ -20,7 +20,7 @@ def create_device_nodes(args: PmbArgs, chroot: Chroot):
|
|||
for dev in pmb.config.chroot_device_nodes:
|
||||
path = chroot / "dev" / str(dev[4])
|
||||
if not path.exists():
|
||||
pmb.helpers.run.root(args, ["mknod",
|
||||
pmb.helpers.run.root(["mknod",
|
||||
"-m", str(dev[0]), # permissions
|
||||
path, # name
|
||||
str(dev[1]), # type
|
||||
|
@ -60,20 +60,20 @@ def mount_dev_tmpfs(args: PmbArgs, chroot: Chroot=Chroot.native()):
|
|||
return
|
||||
|
||||
# Create the $chroot/dev folder and mount tmpfs there
|
||||
pmb.helpers.run.root(args, ["mkdir", "-p", dev])
|
||||
pmb.helpers.run.root(args, ["mount", "-t", "tmpfs",
|
||||
pmb.helpers.run.root(["mkdir", "-p", dev])
|
||||
pmb.helpers.run.root(["mount", "-t", "tmpfs",
|
||||
"-o", "size=1M,noexec,dev",
|
||||
"tmpfs", dev])
|
||||
|
||||
# Create pts, shm folders and device nodes
|
||||
pmb.helpers.run.root(args, ["mkdir", "-p", dev / "pts", dev / "shm"])
|
||||
pmb.helpers.run.root(args, ["mount", "-t", "tmpfs",
|
||||
pmb.helpers.run.root(["mkdir", "-p", dev / "pts", dev / "shm"])
|
||||
pmb.helpers.run.root(["mount", "-t", "tmpfs",
|
||||
"-o", "nodev,nosuid,noexec",
|
||||
"tmpfs", dev / "shm"])
|
||||
create_device_nodes(args, chroot)
|
||||
|
||||
# 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()):
|
||||
|
@ -105,7 +105,7 @@ def mount_native_into_foreign(args: PmbArgs, chroot: Chroot):
|
|||
musl = next(source.glob("lib/ld-musl-*.so.1")).name
|
||||
musl_link = (chroot / "lib" / musl)
|
||||
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])
|
||||
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
|
||||
|
||||
for path in list(mnt_dir.glob("*")) + [mnt_dir]:
|
||||
pmb.helpers.run.root(args, ["rmdir", path])
|
||||
pmb.helpers.run.root(["rmdir", path])
|
||||
|
|
|
@ -71,6 +71,6 @@ def copy_xauthority(args: PmbArgs):
|
|||
# Copy to chroot and chown
|
||||
copy = Chroot.native() / "home/pmos/.Xauthority"
|
||||
if os.path.exists(copy):
|
||||
pmb.helpers.run.root(args, ["rm", copy])
|
||||
pmb.helpers.run.root(args, ["cp", original, copy])
|
||||
pmb.helpers.run.root(["rm", copy])
|
||||
pmb.helpers.run.root(["cp", original, copy])
|
||||
pmb.chroot.root(args, ["chown", "pmos:pmos", "/home/pmos/.Xauthority"])
|
||||
|
|
|
@ -83,7 +83,7 @@ def root(args: PmbArgs, cmd: Sequence[PathString], chroot: Chroot=Chroot.native(
|
|||
"env", "-i", executables["sh"], "-c",
|
||||
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,
|
||||
disable_timeout)
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ def shutdown(args: PmbArgs, only_install_related=False):
|
|||
# contents get copied to a rootfs / installer image, or if creating an
|
||||
# android recovery zip from its contents).
|
||||
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:
|
||||
# Umount all folders inside work dir
|
||||
|
|
|
@ -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}?")):
|
||||
logging.info(f"% rm -rf {match}")
|
||||
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
|
||||
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}"
|
||||
f" ({origin} aport not found)")
|
||||
if not dry:
|
||||
pmb.helpers.run.root(args, ["rm", apk_path])
|
||||
pmb.helpers.run.root(["rm", apk_path])
|
||||
reindex = True
|
||||
continue
|
||||
|
||||
|
@ -131,7 +131,7 @@ def zap_pkgs_local_mismatch(args: PmbArgs, confirm=True, dry=False):
|
|||
logging.info(f"% rm {apk_path_short}"
|
||||
f" ({origin} aport: {version_aport})")
|
||||
if not dry:
|
||||
pmb.helpers.run.root(args, ["rm", apk_path])
|
||||
pmb.helpers.run.root(["rm", apk_path])
|
||||
reindex = True
|
||||
|
||||
if reindex:
|
||||
|
|
|
@ -131,7 +131,7 @@ def copy_git_repo_to_chroot(args: PmbArgs, topdir):
|
|||
handle.write(file)
|
||||
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)
|
||||
|
||||
ci_dir = Path("/home/pmos/ci")
|
||||
|
@ -168,7 +168,7 @@ def run_scripts(args: PmbArgs, topdir, scripts):
|
|||
f" [{where}] ***")
|
||||
|
||||
if "native" in script["options"]:
|
||||
rc = pmb.helpers.run.user(args, [script_path], topdir,
|
||||
rc = pmb.helpers.run.user([script_path], topdir,
|
||||
output="tui")
|
||||
continue
|
||||
else:
|
||||
|
|
|
@ -452,13 +452,14 @@ def ask_for_device(args: PmbArgs):
|
|||
|
||||
|
||||
def ask_for_additional_options(args: PmbArgs, cfg):
|
||||
context = pmb.core.get_context()
|
||||
# Allow to skip additional options
|
||||
logging.info("Additional options:"
|
||||
f" extra free space: {args.extra_space} MB,"
|
||||
f" boot partition size: {args.boot_size} MB,"
|
||||
f" parallel jobs: {args.jobs},"
|
||||
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)}")
|
||||
|
||||
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.")
|
||||
answer = pmb.helpers.cli.confirm(args, "Enable background timer to prevent"
|
||||
" repeated sudo authorization?",
|
||||
default=args.sudo_timer)
|
||||
default=context.sudo_timer)
|
||||
cfg["pmbootstrap"]["sudo_timer"] = str(answer)
|
||||
|
||||
# Mirrors
|
||||
|
|
|
@ -211,7 +211,7 @@ def switch_to_channel_branch(args: PmbArgs, channel_new):
|
|||
|
||||
# Attempt to switch branch (git gives a nice error message, mentioning
|
||||
# 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):
|
||||
raise RuntimeError("Failed to switch branch. Go to your pmaports and"
|
||||
" 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
|
||||
# if they dislike them by setting "core.hooksPath" git config
|
||||
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}")
|
||||
|
|
|
@ -13,7 +13,7 @@ def frontend(args: PmbArgs):
|
|||
# Create the export folder
|
||||
target = args.export_folder
|
||||
if not os.path.exists(target):
|
||||
pmb.helpers.run.user(args, ["mkdir", "-p", target])
|
||||
pmb.helpers.run.user(["mkdir", "-p", target])
|
||||
|
||||
# Rootfs image note
|
||||
chroot = Chroot.native()
|
||||
|
|
|
@ -24,11 +24,11 @@ def _prepare_fifo(args: PmbArgs):
|
|||
path of the fifo as needed by cat to read from it (always
|
||||
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"
|
||||
if os.path.exists(fifo_outside):
|
||||
pmb.helpers.run.root(args, ["rm", "-f", fifo_outside])
|
||||
pmb.helpers.run.root(args, ["mkfifo", fifo_outside])
|
||||
pmb.helpers.run.root(["rm", "-f", fifo_outside])
|
||||
pmb.helpers.run.root(["mkfifo", 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_with_progress = _create_command_with_progress(_command, fifo)
|
||||
log_msg = " ".join(_command)
|
||||
with pmb.helpers.run.root(args, ['cat', fifo],
|
||||
with pmb.helpers.run.root(['cat', fifo],
|
||||
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:
|
||||
while p_apk.poll() is None:
|
||||
line = p_cat.stdout.readline().decode('utf-8')
|
||||
progress = _compute_progress(line)
|
||||
pmb.helpers.cli.progress_print(args, progress)
|
||||
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)
|
||||
|
||||
|
||||
|
|
|
@ -101,4 +101,4 @@ def symlink(args: PmbArgs, file: Path, link: Path):
|
|||
link.unlink()
|
||||
|
||||
# Create the symlink
|
||||
pmb.helpers.run.user(args, ["ln", "-s", file, link])
|
||||
pmb.helpers.run.user(["ln", "-s", file, link])
|
||||
|
|
|
@ -562,11 +562,12 @@ def work_migrate(args: PmbArgs):
|
|||
|
||||
|
||||
def log(args: PmbArgs):
|
||||
context = pmb.core.get_context()
|
||||
log_testsuite = pmb.config.work / "log_testsuite.txt"
|
||||
|
||||
if args.clear_log:
|
||||
pmb.helpers.run.user(args, ["truncate", "-s", "0", args.log])
|
||||
pmb.helpers.run.user(args, ["truncate", "-s", "0", log_testsuite])
|
||||
pmb.helpers.run.user(["truncate", "-s", "0", context.log])
|
||||
pmb.helpers.run.user(["truncate", "-s", "0", log_testsuite])
|
||||
|
||||
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
|
||||
# log at the end, so that output is visible at the bottom (where the user
|
||||
# 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):
|
||||
|
|
|
@ -49,7 +49,7 @@ def clone(args: PmbArgs, name_repo):
|
|||
# Create parent dir and clone
|
||||
logging.info("Clone git repository: " + url)
|
||||
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
|
||||
# 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"
|
||||
"""
|
||||
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()
|
||||
|
||||
|
||||
def can_fast_forward(args: PmbArgs, path, branch_upstream, branch="HEAD"):
|
||||
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:
|
||||
return True
|
||||
elif ret == 1:
|
||||
|
@ -86,7 +86,7 @@ def can_fast_forward(args: PmbArgs, path, branch_upstream, branch="HEAD"):
|
|||
def clean_worktree(args: PmbArgs, path):
|
||||
"""Check if there are not any modified files in the git dir."""
|
||||
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):
|
||||
|
@ -97,7 +97,7 @@ def get_upstream_remote(args: PmbArgs, name_repo):
|
|||
urls = pmb.config.git_repos[name_repo]
|
||||
path = get_path(args, name_repo)
|
||||
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"):
|
||||
if any(u in line for u in urls):
|
||||
return line.split("\t", 1)[0]
|
||||
|
@ -129,7 +129,7 @@ def parse_channels_cfg(args):
|
|||
else:
|
||||
remote = get_upstream_remote(args, "pmaports")
|
||||
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)
|
||||
try:
|
||||
cfg.read_string(stdout)
|
||||
|
@ -223,7 +223,7 @@ def pull(args: PmbArgs, name_repo):
|
|||
# Fetch (exception on failure, meaning connection to server broke)
|
||||
logging.info(msg_start + " git pull --ff-only")
|
||||
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
|
||||
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
|
||||
# throw an exception on error)
|
||||
command = ["git", "merge", "--ff-only", branch_upstream]
|
||||
pmb.helpers.run.user(args, command, path, "stdout")
|
||||
pmb.helpers.run.user(command, path, "stdout")
|
||||
return 0
|
||||
|
||||
|
||||
|
@ -250,7 +250,7 @@ def get_topdir(args: PmbArgs, path: Path):
|
|||
:returns: a string with the top dir of the 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()
|
||||
|
||||
|
||||
|
@ -264,8 +264,8 @@ def get_files(args: PmbArgs, path):
|
|||
:returns: all files in a git repository as list, relative to path
|
||||
"""
|
||||
ret = []
|
||||
files = pmb.helpers.run.user_output(args, ["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"], path).split("\n")
|
||||
files += pmb.helpers.run.user_output(["git", "ls-files",
|
||||
"--exclude-standard", "--other"],
|
||||
path).split("\n")
|
||||
for file in files:
|
||||
|
|
|
@ -35,14 +35,14 @@ def download(args: PmbArgs, url, prefix, cache=True, loglevel=logging.INFO,
|
|||
"""
|
||||
# Create cache folder
|
||||
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
|
||||
path = pmb.config.work / "cache_http" / cache_file(prefix, url)
|
||||
if os.path.exists(path):
|
||||
if cache:
|
||||
return path
|
||||
pmb.helpers.run.user(args, ["rm", path])
|
||||
pmb.helpers.run.user(["rm", path])
|
||||
|
||||
# Offline and not cached
|
||||
if args.offline:
|
||||
|
|
|
@ -44,12 +44,12 @@ def bind(args: PmbArgs, source: Path, destination: Path, create_folders=True, um
|
|||
if os.path.exists(path):
|
||||
continue
|
||||
if create_folders:
|
||||
pmb.helpers.run.root(args, ["mkdir", "-p", path])
|
||||
pmb.helpers.run.root(["mkdir", "-p", path])
|
||||
else:
|
||||
raise RuntimeError(f"Mount failed, folder does not exist: {path}")
|
||||
|
||||
# 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
|
||||
if not ismount(destination):
|
||||
|
@ -67,12 +67,12 @@ def bind_file(args: PmbArgs, source: Path, destination: Path, create_folders=Fal
|
|||
if create_folders:
|
||||
dest_dir: Path = destination.parent
|
||||
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
|
||||
pmb.helpers.run.root(args, ["mount", "--bind", source,
|
||||
pmb.helpers.run.root(["mount", "--bind", source,
|
||||
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):
|
||||
"""Umount all folders that are mounted inside a given folder."""
|
||||
for mountpoint in umount_all_list(folder):
|
||||
pmb.helpers.run.root(args, ["umount", mountpoint])
|
||||
pmb.helpers.run.root(["umount", mountpoint])
|
||||
if ismount(mountpoint):
|
||||
raise RuntimeError(f"Failed to umount: {mountpoint}")
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ def folder_size(args: PmbArgs, path: Path):
|
|||
|
||||
:returns: folder size in kilobytes
|
||||
"""
|
||||
output = pmb.helpers.run.root(args, ["du", "-ks",
|
||||
output = pmb.helpers.run.root(["du", "-ks",
|
||||
path], output_return=True)
|
||||
|
||||
# Only look at last line to filter out sudo garbage (#1766)
|
||||
|
@ -60,10 +60,10 @@ def check_binfmt_misc(args):
|
|||
return
|
||||
|
||||
# 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
|
||||
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)
|
||||
|
||||
if not os.path.exists(path):
|
||||
|
@ -108,7 +108,7 @@ def migrate_work_folder(args: PmbArgs):
|
|||
pmb.chroot.zap(args, False)
|
||||
conf = pmb.config.work / "config_abuild/abuild.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])
|
||||
# Update version file
|
||||
migrate_success(args, 1)
|
||||
|
@ -165,7 +165,7 @@ def migrate_work_folder(args: PmbArgs):
|
|||
pmb.config.init.require_programs()
|
||||
if os.path.exists(path):
|
||||
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:
|
||||
os.makedirs(path, 0o700, True)
|
||||
|
||||
|
@ -188,7 +188,7 @@ def migrate_work_folder(args: PmbArgs):
|
|||
|
||||
# Move packages to edge subdir
|
||||
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:
|
||||
old_path = pmb.config.work / "packages" / arch
|
||||
new_path = edge_path / arch
|
||||
|
@ -198,8 +198,8 @@ def migrate_work_folder(args: PmbArgs):
|
|||
f" '{new_path}', destination already"
|
||||
" exists! Consider 'pmbootstrap zap -p'"
|
||||
f" to delete '{pmb.config.work}/packages'.")
|
||||
pmb.helpers.run.root(args, ["mv", old_path, new_path])
|
||||
pmb.helpers.run.root(args, ["chown", pmb.config.chroot_uid_user,
|
||||
pmb.helpers.run.root(["mv", old_path, new_path])
|
||||
pmb.helpers.run.root(["chown", pmb.config.chroot_uid_user,
|
||||
edge_path])
|
||||
|
||||
# Update version file
|
||||
|
@ -228,7 +228,7 @@ def migrate_work_folder(args: PmbArgs):
|
|||
packages_dir = f"{pmb.config.work}/packages"
|
||||
for old, new in pmb.config.pmaports_channels_legacy.items():
|
||||
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
|
||||
migrate_success(args, 6)
|
||||
|
|
|
@ -194,8 +194,8 @@ def update(args: PmbArgs, arch=None, force=False, existing_only=False):
|
|||
continue
|
||||
target_folder = os.path.dirname(target)
|
||||
if not os.path.exists(target_folder):
|
||||
pmb.helpers.run.root(args, ["mkdir", "-p", target_folder])
|
||||
pmb.helpers.run.root(args, ["cp", temp, target])
|
||||
pmb.helpers.run.root(["mkdir", "-p", target_folder])
|
||||
pmb.helpers.run.root(["cp", temp, target])
|
||||
pmb.helpers.cli.progress_flush(args)
|
||||
|
||||
return True
|
||||
|
|
|
@ -8,7 +8,7 @@ from typing import Any, Dict, List, Optional, Sequence
|
|||
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:
|
||||
"""
|
||||
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)
|
||||
if 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)
|
||||
|
||||
# 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:
|
||||
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):
|
||||
raise TypeError("Expected str output, got " + str(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={}):
|
||||
"""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 = 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)
|
||||
|
|
|
@ -15,8 +15,6 @@ import time
|
|||
from typing import Dict, Optional, Sequence
|
||||
import pmb.helpers.run
|
||||
|
||||
from pmb.core.types import Env, PathString, PmbArgs
|
||||
|
||||
"""For a detailed description of all output modes, read the description of
|
||||
core() at the bottom. All other functions in this file get (indirectly)
|
||||
called by core(). """
|
||||
|
@ -118,7 +116,7 @@ def pipe_read(process, output_to_stdout=False, output_return=False,
|
|||
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.
|
||||
|
||||
: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
|
||||
"""
|
||||
if sudo:
|
||||
pmb.helpers.run.root(args, ["kill", "-9", str(pid)],
|
||||
pmb.helpers.run.root(["kill", "-9", str(pid)],
|
||||
check=False)
|
||||
else:
|
||||
pmb.helpers.run.user(args, ["kill", "-9", str(pid)],
|
||||
pmb.helpers.run.user(["kill", "-9", str(pid)],
|
||||
check=False)
|
||||
|
||||
for (child_pid, child_ppid) in ppids:
|
||||
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.
|
||||
|
||||
: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)
|
||||
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,
|
||||
sudo=False, stdin=None):
|
||||
"""Run a subprocess in foreground with redirected output.
|
||||
|
@ -238,7 +236,7 @@ def foreground_tui(cmd, working_dir=None):
|
|||
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.
|
||||
|
||||
:param code: exit code to check
|
||||
|
@ -249,8 +247,9 @@ def check_return_code(args: PmbArgs, code, log_message):
|
|||
"""
|
||||
if code:
|
||||
logging.debug("^" * 70)
|
||||
log_file = get_context().log
|
||||
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)}): " +
|
||||
log_message)
|
||||
|
||||
|
@ -297,7 +296,7 @@ def add_proxy_env_vars(env):
|
|||
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):
|
||||
"""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)
|
||||
"""
|
||||
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()
|
||||
|
||||
# Log simplified and full command (pmbootstrap -v)
|
||||
|
@ -383,14 +383,14 @@ def core(args: PmbArgs, log_message, cmd, working_dir=None, output="log",
|
|||
else:
|
||||
# Foreground pipe (always redirects to the error log file)
|
||||
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_timeout = output in ["log", "stdout"] and not disable_timeout
|
||||
|
||||
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_return,
|
||||
output_timeout,
|
||||
|
@ -398,7 +398,7 @@ def core(args: PmbArgs, log_message, cmd, working_dir=None, output="log",
|
|||
|
||||
# Check the return code
|
||||
if check is not False:
|
||||
check_return_code(args, code, log_message)
|
||||
check_return_code(code, log_message)
|
||||
|
||||
# Return (code or output string)
|
||||
return output_after_run if output_return else code
|
||||
|
|
|
@ -118,12 +118,12 @@ def copy_files_from_chroot(args: PmbArgs, chroot: Chroot):
|
|||
arch_qemu = pmb.parse.arch.alpine_to_qemu(args.deviceinfo["arch"])
|
||||
qemu_binary = mountpoint_outside / ("/usr/bin/qemu-" + arch_qemu + "-static")
|
||||
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
|
||||
fifo = chroot / "tmp/apk_progress_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)
|
||||
folders: List[str] = []
|
||||
|
@ -153,14 +153,14 @@ def create_home_from_skel(args: PmbArgs):
|
|||
rootfs = (Chroot.native() / "mnt/install")
|
||||
# In btrfs, home subvol & home dir is created in format.py
|
||||
if args.filesystem != "btrfs":
|
||||
pmb.helpers.run.root(args, ["mkdir", rootfs / "home"])
|
||||
pmb.helpers.run.root(["mkdir", rootfs / "home"])
|
||||
|
||||
home = (rootfs / "home" / args.user)
|
||||
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:
|
||||
pmb.helpers.run.root(args, ["mkdir", home])
|
||||
pmb.helpers.run.root(args, ["chown", "-R", "10000", home])
|
||||
pmb.helpers.run.root(["mkdir", home])
|
||||
pmb.helpers.run.root(["chown", "-R", "10000", home])
|
||||
|
||||
|
||||
def configure_apk(args: PmbArgs):
|
||||
|
@ -179,19 +179,19 @@ def configure_apk(args: PmbArgs):
|
|||
# Copy over keys
|
||||
rootfs = (Chroot.native() / "mnt/install")
|
||||
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
|
||||
index_files = pmb.helpers.repo.apkindex_files(args,
|
||||
arch=args.deviceinfo["arch"],
|
||||
user_repository=False)
|
||||
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
|
||||
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"])
|
||||
pmb.helpers.run.user(args, ["cat", rootfs / "etc/apk/repositories"])
|
||||
pmb.helpers.run.user(["cat", rootfs / "etc/apk/repositories"])
|
||||
|
||||
|
||||
def set_user(args: PmbArgs):
|
||||
|
@ -311,11 +311,11 @@ def copy_ssh_keys(args: PmbArgs):
|
|||
outfile.close()
|
||||
|
||||
target = Chroot.native() / "mnt/install/home/" / args.user / ".ssh"
|
||||
pmb.helpers.run.root(args, ["mkdir", target])
|
||||
pmb.helpers.run.root(args, ["chmod", "700", target])
|
||||
pmb.helpers.run.root(args, ["cp", authorized_keys, target / "authorized_keys"])
|
||||
pmb.helpers.run.root(args, ["rm", authorized_keys])
|
||||
pmb.helpers.run.root(args, ["chown", "-R", "10000:10000", target])
|
||||
pmb.helpers.run.root(["mkdir", target])
|
||||
pmb.helpers.run.root(["chmod", "700", target])
|
||||
pmb.helpers.run.root(["cp", authorized_keys, target / "authorized_keys"])
|
||||
pmb.helpers.run.root(["rm", authorized_keys])
|
||||
pmb.helpers.run.root(["chown", "-R", "10000:10000", target])
|
||||
|
||||
|
||||
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
|
||||
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)
|
||||
|
||||
# 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
|
||||
logging.info(f"({chroot_installer}) add {img} as /var/lib/rootfs.img")
|
||||
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
|
||||
# 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
|
||||
logging.info(f"({chroot_installer}) add {host_src} as"
|
||||
f" {chroot_dest}")
|
||||
pmb.helpers.run.root(args, ["install", "-Dm644", host_src,
|
||||
pmb.helpers.run.root(["install", "-Dm644", host_src,
|
||||
host_dest])
|
||||
|
||||
# Remove $DEVICE-boot.img (we will generate a new one if --split was
|
||||
|
|
|
@ -36,7 +36,7 @@ def previous_install(args: PmbArgs, path: Path):
|
|||
logging.info("WARNING: Could not get block device label,"
|
||||
" 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
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ from pmb.core import Chroot
|
|||
|
||||
def init(args: PmbArgs):
|
||||
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*"):
|
||||
if loopdevice.is_dir():
|
||||
continue
|
||||
|
|
|
@ -86,8 +86,8 @@ def bootimg(args: PmbArgs, path: Path):
|
|||
|
||||
# Copy the boot.img into the chroot temporary folder
|
||||
# and make it world readable
|
||||
pmb.helpers.run.root(args, ["cp", path, bootimg_path])
|
||||
pmb.helpers.run.root(args, ["chmod", "a+r", bootimg_path])
|
||||
pmb.helpers.run.root(["cp", path, bootimg_path])
|
||||
pmb.helpers.run.root(["chmod", "a+r", bootimg_path])
|
||||
|
||||
file_output = pmb.chroot.user(args, ["file", "-b", "boot.img"],
|
||||
working_dir=temp_path,
|
||||
|
|
|
@ -45,8 +45,8 @@ def create_second_storage(args: PmbArgs):
|
|||
|
||||
"""
|
||||
path = Chroot.native() / "home/pmos/rootfs" / f"{args.device}-2nd.img"
|
||||
pmb.helpers.run.root(args, ["touch", path])
|
||||
pmb.helpers.run.root(args, ["chmod", "a+w", path])
|
||||
pmb.helpers.run.root(["touch", path])
|
||||
pmb.helpers.run.root(["chmod", "a+w", path])
|
||||
resize_image(args, args.second_storage, path)
|
||||
return path
|
||||
|
||||
|
@ -272,7 +272,7 @@ def resize_image(args: PmbArgs, img_size_new, img_path):
|
|||
|
||||
if (img_size_new_bytes >= img_size):
|
||||
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:
|
||||
# Convert to human-readable format
|
||||
# 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
|
||||
# rootfs, which is owned by root
|
||||
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)
|
||||
if args.image_size:
|
||||
|
@ -380,7 +380,7 @@ def run(args: PmbArgs):
|
|||
process = None
|
||||
try:
|
||||
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:
|
||||
# In addition to not showing a trace when pressing ^C, let user know
|
||||
# they can override this behavior:
|
||||
|
|
|
@ -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}")
|
||||
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}")
|
||||
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/"]
|
||||
remote_cmd = pmb.helpers.run_core.flat_cmd(remote_cmd_l)
|
||||
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:
|
||||
"""Connect to a device via ssh and query the architecture."""
|
||||
logging.info(f"Querying architecture of {user}@{host}")
|
||||
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
|
||||
# added to list of known hosts" warnings.
|
||||
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}")
|
||||
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}")
|
||||
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.
|
||||
command = ['ssh', '-t', '-p', port, f'{user}@{host}',
|
||||
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue