mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 13:45:45 -05:00
74 lines
1.7 KiB
Python
74 lines
1.7 KiB
Python
import os
|
|
from typing import Optional, TypedDict
|
|
|
|
from config.state import config
|
|
from constants import Arch
|
|
|
|
BIND_BUILD_DIRS = 'BINDBUILDDIRS'
|
|
BASE_CHROOT_PREFIX = 'base_'
|
|
BUILD_CHROOT_PREFIX = 'build_'
|
|
|
|
|
|
class MountEntry(TypedDict):
|
|
src: str
|
|
type: Optional[str]
|
|
options: list[str]
|
|
|
|
|
|
# inspired by arch-chroot
|
|
# order of these matters!
|
|
BASIC_MOUNTS: dict[str, MountEntry] = {
|
|
'/proc': {
|
|
'src': 'proc',
|
|
'type': 'proc',
|
|
'options': ['nosuid,noexec,nodev']
|
|
},
|
|
'/sys': {
|
|
'src': 'sys',
|
|
'type': 'sysfs',
|
|
'options': ['nosuid,noexec,nodev,ro'],
|
|
},
|
|
'/dev': {
|
|
'src': 'udev',
|
|
'type': 'devtmpfs',
|
|
'options': ['mode=0755,nosuid'],
|
|
},
|
|
'/dev/pts': {
|
|
'src': 'devpts',
|
|
'type': 'devpts',
|
|
'options': ['mode=0620,gid=5,nosuid,noexec'],
|
|
},
|
|
'/dev/shm': {
|
|
'src': 'shm',
|
|
'type': 'tmpfs',
|
|
'options': ['mode=1777,nosuid,nodev'],
|
|
},
|
|
'/run': {
|
|
'src': '/run',
|
|
'type': 'tmpfs',
|
|
'options': ['bind'],
|
|
},
|
|
'/etc/resolv.conf': {
|
|
'src': os.path.realpath('/etc/resolv.conf'),
|
|
'type': None,
|
|
'options': ['bind'],
|
|
},
|
|
}
|
|
|
|
|
|
def make_abs_path(path: str) -> str:
|
|
"""Simply ensures the path string starts with a '/'. Does no disk modifications!"""
|
|
return '/' + path.lstrip('/')
|
|
|
|
|
|
def get_chroot_path(chroot_name, override_basepath: Optional[str] = None) -> str:
|
|
base_path = config.get_path('chroots') if not override_basepath else override_basepath
|
|
return os.path.join(base_path, chroot_name)
|
|
|
|
|
|
def base_chroot_name(arch: Arch):
|
|
return BASE_CHROOT_PREFIX + arch
|
|
|
|
|
|
def build_chroot_name(arch: Arch):
|
|
return BUILD_CHROOT_PREFIX + arch
|