コード例 #1
0
ファイル: part.py プロジェクト: f-koehler/archlinux-installer
    def append(self, end: str = "100%", type_: Optional[str] = None):
        if self.partitions:
            start = self.partitions[-1].end
        else:
            start = "0%"

        partition = Partition(self.path,
                              len(self.partitions) + 1, start, end, type_)

        command = [
            "parted",
            "-s",
            "-a",
            "optimal",
            str(self.path),
            "mkpart",
            "primary",
        ]

        if partition.type_ is not None:
            command.append(partition.type_)

        command += [
            partition.start,
            partition.end,
        ]

        run(command)

        self.partitions.append(partition)
        return partition
コード例 #2
0
ファイル: git.py プロジェクト: f-koehler/archlinux-installer
def clone(url: str, dest: Union[Path, str]):
    Path(dest).mkdir(parents=True, exist_ok=True)
    run(
        ["git", "clone", url, str(dest)],
        {
            "GIT_SSH_COMMAND":
            "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
        },
    )
コード例 #3
0
def unmount_filesystem(filesystem: FileSystem):
    cmd: List[str] = []

    if filesystem.type_ == "swap":
        cmd = ["swapoff", filesystem.block_device.path]
    else:
        cmd = ["umount", filesystem.mount_point]

    run(cmd)
    filesystem.mounted = False
コード例 #4
0
def run_reflector(country: str = "Germany", prefix: Union[Path, str] = "/mnt"):
    mirrorlist = Path(prefix) / "etc" / "pacman.d" / "mirrorlist"
    mirrorlist.parent.mkdir(parents=True, exist_ok=True)
    run([
        "reflector",
        "--age",
        "12",
        "--country",
        country,
        "--protocol",
        "https",
        "--sort",
        "rate",
        "--save",
        str(mirrorlist),
    ])
コード例 #5
0
ファイル: fs.py プロジェクト: f-koehler/archlinux-installer
def create_btrfs(
    block_device: BlockDevice,
    label: Optional[str] = None,
    mount_point: Optional[Union[str, Path]] = None,
    mount_options: Optional[List[str]] = None,
) -> BtrfsFileSystem:
    cmd = ["mkfs.btrfs", "-f"]
    if label:
        cmd += ["-L", label]
    cmd.append(block_device.path)
    run(cmd)

    return BtrfsFileSystem(
        block_device,
        label=label,
        mount_point=mount_point,
        mount_options=mount_options,
    )
コード例 #6
0
ファイル: fs.py プロジェクト: f-koehler/archlinux-installer
def create_swap(
    block_device: BlockDevice,
    label: Optional[str] = None,
    mount_options: Optional[List[str]] = None,
) -> FileSystem:
    cmd = ["mkswap", "-f"]
    if label:
        cmd += ["-L", label]
    cmd.append(block_device.path)
    run(cmd)

    return FileSystem(
        block_device,
        "swap",
        label=label,
        mount_point="[SWAP]",
        mount_options=mount_options,
    )
コード例 #7
0
def mount_filesystem(filesystem: FileSystem):
    if filesystem.mount_point is None:
        return

    cmd: List[str] = []

    if filesystem.type_ == "swap":
        cmd = ["swapon"]
        if filesystem.mount_options:
            cmd += ["-o", ",".join(filesystem.mount_options)]
        cmd.append(filesystem.block_device.path)
    else:
        Path(filesystem.mount_point).mkdir(parents=True, exist_ok=True)
        cmd = ["mount", "-t", filesystem.type_]
        if filesystem.mount_options:
            cmd += ["-o", ",".join(filesystem.mount_options)]
        cmd += [filesystem.block_device.path, filesystem.mount_point]

    run(cmd)
    filesystem.mounted = True
コード例 #8
0
ファイル: fs.py プロジェクト: f-koehler/archlinux-installer
def create_vfat32(
    block_device: BlockDevice,
    label: Optional[str] = None,
    mount_point: Optional[Union[str, Path]] = None,
    mount_options: Optional[List[str]] = None,
) -> FileSystem:
    cmd = ["mkfs.vfat", "-F", "32"]
    if label:
        cmd.append("-n")
        cmd.append(label[:11].upper())
    cmd.append(block_device.path)
    run(cmd)

    return FileSystem(
        block_device,
        "vfat",
        label=label,
        mount_point=mount_point,
        mount_options=mount_options,
    )
コード例 #9
0
ファイル: fs.py プロジェクト: f-koehler/archlinux-installer
    def create_subvolume(self, name: str) -> FileSystem:
        if self.mount_point is None:
            raise RuntimeError("btrfs filesystem does not have mountpoint")

        if not self.mounted:
            raise RuntimeError("base filesystem is not mounted")

        subvolume_path = Path(self.mount_point) / name
        subvolume_path.parent.mkdir(parents=True, exist_ok=True)

        cmd = ["btrfs", "subvolume", "create", name]
        run(cmd, cwd=self.mount_point)

        mount_options = [] if self.mount_options is None else self.mount_options
        mount_options.append("subvol=" + name)

        return FileSystem(
            self.block_device,
            self.type_,
            mount_point=Path(self.mount_point) / name,
            mount_options=mount_options,
        )
コード例 #10
0
def luks_container(block_device: BlockDevice, mapper_name: str, password: str):
    try:
        command = [
            "cryptsetup",
            "-v",
            "luksFormat",
            block_device.path,
            "--type",
            "luks",
            "--key-file",
            "-",
        ]
        subprocess.Popen(
            command, stderr=sys.stderr, stdout=sys.stdout, stdin=subprocess.PIPE
        ).communicate(input=password.encode())

        subprocess.Popen(
            [
                "cryptsetup",
                "-v",
                "open",
                "--key-file",
                "-",
                block_device.path,
                mapper_name,
            ],
            stderr=sys.stderr,
            stdout=sys.stdout,
            stdin=subprocess.PIPE,
        ).communicate(input=password.encode())
        yield BlockDevice(Path("/") / "dev" / "mapper" / mapper_name)
    finally:
        try:
            run(["cryptsetup", "-v", "close", mapper_name])
        except:
            pass
コード例 #11
0
ファイル: part.py プロジェクト: f-koehler/archlinux-installer
def clear_disk(disk: Union[str, Path], label: str = "gpt"):
    run(["parted", "-s", str(disk), "mklabel", label])
コード例 #12
0
def pacstrap(packages: Union[str, List[str]],
             prefix: Optional[Union[str, Path]] = "/mnt"):
    if isinstance(packages, str):
        run(["pacstrap", str(prefix), packages])
    else:
        run(["pacstrap", str(prefix)] + packages)