From 7058e0378312b1692ad69b01920bbc7ac1a882aa Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Wed, 24 Jan 2018 17:31:09 -0800 Subject: [PATCH] Add Clear Linux support --- README.md | 2 ++ mkosi | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f536f921d..30d20f710 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,8 @@ following *OS*es. * *CentOS* +* *Clear Linux* + In theory, any distribution may be used on the host for building images containing any other distribution, as long as the necessary tools are available. Specifically, any distro that packages diff --git a/mkosi b/mkosi index 75d5b145f..62a1f512a 100755 --- a/mkosi +++ b/mkosi @@ -65,6 +65,7 @@ class Distribution(Enum): opensuse = 5 mageia = 6 centos = 7 + clear = 8 GPT_ROOT_X86 = uuid.UUID("44479540f29741b29af7d131d5f0458a") GPT_ROOT_X86_64 = uuid.UUID("4f68bce3e8cd4db196e7fbcaf984b709") @@ -982,6 +983,57 @@ def invoke_dnf(args, workspace, repositories, base_packages, boot_packages, conf with mount_api_vfs(args, workspace): run(cmdline, check=True) +@complete_step('Installing Clear Linux') +def install_clear(args, workspace, run_build_script): + if args.release == "latest": + release = "clear" + else: + release = "clear/"+args.release + + root = os.path.join(workspace, "root") + + packages = ['os-core'] + args.packages + if run_build_script: + packages.extend(args.build_packages) + if args.bootable: + packages += ['kernel-native'] + + swupd_extract = shutil.which("swupd-extract") + + if swupd_extract is None: + print(""" +Couldn't find swupd-extract program, download (or update it) it using: + + go get -u github.com/clearlinux/mixer-tools/swupd-extract + +and it will be installed by default in ~/go/bin/swupd-extract. Also +ensure that you have openssl program in your system. +""") + raise FileNotFoundError("Couldn't find swupd-extract") + + print("Using {}".format(swupd_extract)) + + run([swupd_extract, + '-output', root, + '-state', args.cache_path, + release, + *packages], + check=True) + + os.symlink("../run/systemd/resolve/resolv.conf", os.path.join(root, "etc/resolv.conf")) + + # Clear Linux doesn't have a /etc/shadow at install time, it gets + # created when the root first login. To set the password via + # mkosi, create one. + if not run_build_script and args.password is not None: + shadow_file = os.path.join(root, "etc/shadow") + with open(shadow_file, "w") as f: + f.write('root::::::::') + os.chmod(shadow_file, 0o400) + # Password is already empty for root, so no need to reset it later. + if args.password == "": + args.password = None + @complete_step('Installing Fedora') def install_fedora(args, workspace, run_build_script): if args.release == 'rawhide': @@ -1462,6 +1514,7 @@ def install_distribution(args, workspace, run_build_script, cached): Distribution.ubuntu : install_ubuntu, Distribution.arch : install_arch, Distribution.opensuse : install_opensuse, + Distribution.clear : install_clear, } install[args.distribution](args, workspace, run_build_script) @@ -1569,6 +1622,21 @@ def install_boot_loader_debian(args, workspace): def install_boot_loader_opensuse(args, workspace): install_boot_loader_debian(args, workspace) +def install_boot_loader_clear(args, workspace, loopdev): + nspawn_params = [ + # clr-boot-manager uses blkid in the device backing "/" to + # figure out uuid and related parameters. + "--bind-ro=/dev", + "--property=DeviceAllow=" + loopdev, + "--property=DeviceAllow=" + partition(loopdev, args.esp_partno), + "--property=DeviceAllow=" + partition(loopdev, args.root_partno), + + # clr-boot-manager compiled in Clear Linux will assume EFI + # partition is mounted in "/boot". + "--bind=" + os.path.join(workspace, "root/efi") + ":/boot", + ] + run_workspace_command(args, workspace, "/usr/bin/clr-boot-manager", "update", "-i", nspawn_params=nspawn_params) + def install_boot_loader(args, workspace, loopdev, cached): if not args.bootable: return @@ -1592,6 +1660,9 @@ def install_boot_loader(args, workspace, loopdev, cached): if args.distribution == Distribution.opensuse: install_boot_loader_opensuse(args, workspace) + if args.distribution == Distribution.clear: + install_boot_loader_clear(args, workspace, loopdev) + def install_extra_trees(args, workspace, for_cache): if not args.extra_trees: return @@ -2326,6 +2397,9 @@ def detect_distribution(): if ln.startswith("VERSION_ID="): version_id = ln[11:].strip() + if id == "clear-linux-os": + id = "clear" + d = Distribution.__members__.get(id, None) return d, version_id @@ -2652,7 +2726,9 @@ def find_cache(args): if os.path.exists("mkosi.cache/"): args.cache_path = "mkosi.cache/" + args.distribution.name - if args.release is not None: + # Clear has a release number that can be used, however the + # cache is valid (and more efficient) across releases. + if args.distribution != Distribution.clear and args.release is not None: args.cache_path += "~" + args.release def find_build_script(args): @@ -2801,7 +2877,7 @@ def load_args(): if args.distribution is None: args.distribution = d - if args.distribution == d and args.release is None: + if args.distribution == d and d != Distribution.clear and args.release is None: args.release = r if args.distribution is None: @@ -2820,6 +2896,8 @@ def load_args(): args.release = "artful" elif args.distribution == Distribution.opensuse: args.release = "tumbleweed" + elif args.distribution == Distribution.clear: + args.release = "latest" find_cache(args) -- 2.47.2