mirror of
https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
synced 2025-07-13 11:29:46 +03:00
ruffify
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
This commit is contained in:
parent
257a89bc18
commit
633d655952
6 changed files with 43 additions and 16 deletions
|
@ -1,7 +1,6 @@
|
||||||
# Copyright 2023 Johannes Marbach, Oliver Smith
|
# Copyright 2023 Johannes Marbach, Oliver Smith
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
import os
|
import os
|
||||||
import shlex
|
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
|
@ -102,7 +102,13 @@ libc.syscall.restype = ctypes.c_long
|
||||||
libc.unshare.argtypes = (ctypes.c_int,)
|
libc.unshare.argtypes = (ctypes.c_int,)
|
||||||
libc.statfs.argtypes = (ctypes.c_char_p, ctypes.c_void_p)
|
libc.statfs.argtypes = (ctypes.c_char_p, ctypes.c_void_p)
|
||||||
libc.eventfd.argtypes = (ctypes.c_int, ctypes.c_int)
|
libc.eventfd.argtypes = (ctypes.c_int, ctypes.c_int)
|
||||||
libc.mount.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_char_p)
|
libc.mount.argtypes = (
|
||||||
|
ctypes.c_char_p,
|
||||||
|
ctypes.c_char_p,
|
||||||
|
ctypes.c_char_p,
|
||||||
|
ctypes.c_ulong,
|
||||||
|
ctypes.c_char_p,
|
||||||
|
)
|
||||||
libc.pivot_root.argtypes = (ctypes.c_char_p, ctypes.c_char_p)
|
libc.pivot_root.argtypes = (ctypes.c_char_p, ctypes.c_char_p)
|
||||||
libc.umount2.argtypes = (ctypes.c_char_p, ctypes.c_int)
|
libc.umount2.argtypes = (ctypes.c_char_p, ctypes.c_int)
|
||||||
libc.capget.argtypes = (ctypes.c_void_p, ctypes.c_void_p)
|
libc.capget.argtypes = (ctypes.c_void_p, ctypes.c_void_p)
|
||||||
|
@ -195,13 +201,22 @@ def cap_permitted_to_ambient() -> None:
|
||||||
with open("/proc/sys/kernel/cap_last_cap", "rb") as f:
|
with open("/proc/sys/kernel/cap_last_cap", "rb") as f:
|
||||||
last_cap = int(f.read())
|
last_cap = int(f.read())
|
||||||
|
|
||||||
libc.prctl.argtypes = (ctypes.c_int, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong)
|
libc.prctl.argtypes = (
|
||||||
|
ctypes.c_int,
|
||||||
|
ctypes.c_ulong,
|
||||||
|
ctypes.c_ulong,
|
||||||
|
ctypes.c_ulong,
|
||||||
|
ctypes.c_ulong,
|
||||||
|
)
|
||||||
|
|
||||||
for cap in range(ctypes.sizeof(ctypes.c_uint64) * 8):
|
for cap in range(ctypes.sizeof(ctypes.c_uint64) * 8):
|
||||||
if cap > last_cap:
|
if cap > last_cap:
|
||||||
break
|
break
|
||||||
|
|
||||||
if effective & (1 << cap) and libc.prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, cap, 0, 0) < 0:
|
if (
|
||||||
|
effective & (1 << cap)
|
||||||
|
and libc.prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, cap, 0, 0) < 0
|
||||||
|
):
|
||||||
oserror("prctl")
|
oserror("prctl")
|
||||||
|
|
||||||
|
|
||||||
|
@ -365,7 +380,9 @@ def mount_rbind(src: str, dst: str, attrs: int = 0) -> None:
|
||||||
ctypes.c_void_p,
|
ctypes.c_void_p,
|
||||||
ctypes.c_size_t,
|
ctypes.c_size_t,
|
||||||
)
|
)
|
||||||
r = libc.syscall(NR_mount_setattr, fd, b"", flags, ctypes.addressof(attr), MOUNT_ATTR_SIZE_VER0)
|
r = libc.syscall(
|
||||||
|
NR_mount_setattr, fd, b"", flags, ctypes.addressof(attr), MOUNT_ATTR_SIZE_VER0
|
||||||
|
)
|
||||||
|
|
||||||
if r < 0:
|
if r < 0:
|
||||||
oserror("mount_setattr", src)
|
oserror("mount_setattr", src)
|
||||||
|
@ -388,7 +405,9 @@ def mount_rbind(src: str, dst: str, attrs: int = 0) -> None:
|
||||||
ctypes.c_char_p,
|
ctypes.c_char_p,
|
||||||
ctypes.c_uint,
|
ctypes.c_uint,
|
||||||
)
|
)
|
||||||
r = libc.syscall(NR_move_mount, fd, b"", AT_FDCWD, dst.encode(), MOVE_MOUNT_F_EMPTY_PATH)
|
r = libc.syscall(
|
||||||
|
NR_move_mount, fd, b"", AT_FDCWD, dst.encode(), MOVE_MOUNT_F_EMPTY_PATH
|
||||||
|
)
|
||||||
|
|
||||||
if r < 0:
|
if r < 0:
|
||||||
oserror("move_mount", dst)
|
oserror("move_mount", dst)
|
||||||
|
@ -649,7 +668,9 @@ class FSOperation:
|
||||||
|
|
||||||
|
|
||||||
class BindOperation(FSOperation):
|
class BindOperation(FSOperation):
|
||||||
def __init__(self, src: str, dst: str, *, readonly: bool, required: bool, relative: bool) -> None:
|
def __init__(
|
||||||
|
self, src: str, dst: str, *, readonly: bool, required: bool, relative: bool
|
||||||
|
) -> None:
|
||||||
self.src = src
|
self.src = src
|
||||||
self.readonly = readonly
|
self.readonly = readonly
|
||||||
self.required = required
|
self.required = required
|
||||||
|
@ -759,7 +780,9 @@ class TmpfsOperation(FSOperation):
|
||||||
with umask(~0o755):
|
with umask(~0o755):
|
||||||
os.makedirs(dst, exist_ok=True)
|
os.makedirs(dst, exist_ok=True)
|
||||||
|
|
||||||
options = "" if any(dst.endswith(suffix) for suffix in ("/tmp", "/var/tmp")) else "mode=0755"
|
options = (
|
||||||
|
"" if any(dst.endswith(suffix) for suffix in ("/tmp", "/var/tmp")) else "mode=0755"
|
||||||
|
)
|
||||||
mount("tmpfs", dst, "tmpfs", 0, options)
|
mount("tmpfs", dst, "tmpfs", 0, options)
|
||||||
|
|
||||||
|
|
||||||
|
@ -829,7 +852,9 @@ class OverlayOperation(FSOperation):
|
||||||
def execute(self, oldroot: str, newroot: str) -> None:
|
def execute(self, oldroot: str, newroot: str) -> None:
|
||||||
lowerdirs = tuple(chase(oldroot, p) for p in self.lowerdirs)
|
lowerdirs = tuple(chase(oldroot, p) for p in self.lowerdirs)
|
||||||
upperdir = (
|
upperdir = (
|
||||||
chase(oldroot, self.upperdir) if self.upperdir and self.upperdir != "tmpfs" else self.upperdir
|
chase(oldroot, self.upperdir)
|
||||||
|
if self.upperdir and self.upperdir != "tmpfs"
|
||||||
|
else self.upperdir
|
||||||
)
|
)
|
||||||
workdir = chase(oldroot, self.workdir) if self.workdir else None
|
workdir = chase(oldroot, self.workdir) if self.workdir else None
|
||||||
dst = chase(newroot, self.dst)
|
dst = chase(newroot, self.dst)
|
||||||
|
@ -991,7 +1016,9 @@ def main() -> None:
|
||||||
upperdir = ""
|
upperdir = ""
|
||||||
workdir = ""
|
workdir = ""
|
||||||
chdir = None
|
chdir = None
|
||||||
become_root = suppress_chown = suppress_sync = unshare_net = unshare_ipc = suspend = pack_fds = False
|
become_root = suppress_chown = suppress_sync = unshare_net = unshare_ipc = suspend = (
|
||||||
|
pack_fds
|
||||||
|
) = False
|
||||||
|
|
||||||
ttyname = os.ttyname(2) if os.isatty(2) else ""
|
ttyname = os.ttyname(2) if os.isatty(2) else ""
|
||||||
|
|
||||||
|
@ -1039,7 +1066,9 @@ def main() -> None:
|
||||||
elif arg == "--overlay-workdir":
|
elif arg == "--overlay-workdir":
|
||||||
workdir = argv.pop()
|
workdir = argv.pop()
|
||||||
elif arg == "--overlay":
|
elif arg == "--overlay":
|
||||||
fsops.append(OverlayOperation(tuple(reversed(lowerdirs)), upperdir, workdir, argv.pop()))
|
fsops.append(
|
||||||
|
OverlayOperation(tuple(reversed(lowerdirs)), upperdir, workdir, argv.pop())
|
||||||
|
)
|
||||||
upperdir = ""
|
upperdir = ""
|
||||||
workdir = ""
|
workdir = ""
|
||||||
lowerdirs = []
|
lowerdirs = []
|
||||||
|
|
|
@ -21,7 +21,7 @@ import pmb.config.pmaports
|
||||||
from pmb.helpers.locale import get_xkb_layout
|
from pmb.helpers.locale import get_xkb_layout
|
||||||
from pmb.parse.deviceinfo import Deviceinfo
|
from pmb.parse.deviceinfo import Deviceinfo
|
||||||
from pmb.core import Config
|
from pmb.core import Config
|
||||||
from pmb.types import Env, PartitionLayout, PmbArgs
|
from pmb.types import PartitionLayout, PmbArgs
|
||||||
import pmb.helpers.devices
|
import pmb.helpers.devices
|
||||||
from pmb.helpers.mount import mount_device_rootfs
|
from pmb.helpers.mount import mount_device_rootfs
|
||||||
import pmb.helpers.run
|
import pmb.helpers.run
|
||||||
|
|
|
@ -86,7 +86,9 @@ def format_and_mount_boot(layout: PartitionLayout) -> None:
|
||||||
)
|
)
|
||||||
elif filesystem == "btrfs":
|
elif filesystem == "btrfs":
|
||||||
raise ValueError("BTRFS not yet supported with new sandbox")
|
raise ValueError("BTRFS not yet supported with new sandbox")
|
||||||
pmb.chroot.root(["mkfs.btrfs", "-f", "-q", "-L", layout.boot.partition_label, layout.boot.path])
|
pmb.chroot.root(
|
||||||
|
["mkfs.btrfs", "-f", "-q", "-L", layout.boot.partition_label, layout.boot.path]
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Filesystem " + filesystem + " is not supported!")
|
raise RuntimeError("Filesystem " + filesystem + " is not supported!")
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
# Copyright 2023 Oliver Smith
|
# Copyright 2023 Oliver Smith
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
from pathlib import Path
|
|
||||||
from pmb.helpers import logging
|
from pmb.helpers import logging
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
import pmb.chroot
|
import pmb.chroot
|
||||||
import pmb.chroot.apk
|
import pmb.chroot.apk
|
||||||
import pmb.config
|
import pmb.config
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
import argparse
|
import argparse
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue