From 422d19e932df119c7578e5b07f0dae9ebc8dc5e1 Mon Sep 17 00:00:00 2001 From: alexander stefanov Date: Sat, 16 Nov 2024 13:56:34 +0300 Subject: [PATCH] few minor improvements --- utils/bootstrap_setup.py | 13 +++++++++++++ utils/kernel.py | 2 ++ utils/rpmbuild.py | 3 +++ 3 files changed, 18 insertions(+) diff --git a/utils/bootstrap_setup.py b/utils/bootstrap_setup.py index 98e46ca..bd33a95 100644 --- a/utils/bootstrap_setup.py +++ b/utils/bootstrap_setup.py @@ -71,12 +71,24 @@ def run_dnf_install(config, dnf_conf_path, rootfs_dir, arch, extra_pkgs=""): subprocess.run(dnf_command, check=True) +def set_root_password_with_systemd(rootfs_dir, password_root): + """Set root password using systemd-firstboot in chroot environment.""" + subprocess.run( + ["sudo", "systemd-firstboot", "--root-password=", password_root, "--root=", rootfs_dir], + check=True + ) + print(f"root password set to '{password_root}' in chroot at {rootfs_dir}") + + def setup_bootstrap(bootstrap_dir, tmp_dir, vendor, device, distro, arch): # load distro config # bootstrap/DISTRO_NAME distro_config_path = os.path.join(bootstrap_dir, distro) + if not os.path.exists(distro_config_path): print(f"Bootstrap configuration for distro '{distro}' not found.") + current_directory = os.getcwd() + print(f"Текущая рабочая директория: {current_directory}") sys.exit(1) config = load_config(distro_config_path) @@ -91,5 +103,6 @@ def setup_bootstrap(bootstrap_dir, tmp_dir, vendor, device, distro, arch): generate_dnf_conf(dnf_conf_path, config["ABF_DOWNLOADS"], config["RELEASE"]) run_dnf_install(config, dnf_conf_path, rootfs_dir, arch, extra_pkgs) + set_root_password_with_systemd(rootfs_dir, config["PASSWD_ROOT"]) #setup_user(rootfs_dir, config["DEFAULT_USER"], config["DEFAULT_USER_PASSWORD"], config["PASSWD_ROOT"]) diff --git a/utils/kernel.py b/utils/kernel.py index ab8fa30..6f4f46e 100644 --- a/utils/kernel.py +++ b/utils/kernel.py @@ -15,7 +15,9 @@ def clone_kernel(TMP_DIR, BASE_DIR, config, vendor, device, kernel_dir): def make_kernel_tar(kernel_dir, kernel_rpm_dir): + base_dir = os.getcwd() os.chdir(kernel_dir) subprocess.run(["git", "archive", "--format=tar", "--prefix=kernel/", f"--output={kernel_rpm_dir}/kernel.tar", "HEAD"]) + os.chdir(base_dir) diff --git a/utils/rpmbuild.py b/utils/rpmbuild.py index b496a01..c7bf22b 100644 --- a/utils/rpmbuild.py +++ b/utils/rpmbuild.py @@ -13,6 +13,7 @@ def run_rpmbuild(kernel_build_dir, target_arch): print(f"Error: Kernel build directory '{kernel_build_dir}' does not exist.") sys.exit(1) + base_dir = os.getcwd() # Change to the kernel-build directory os.chdir(kernel_build_dir) @@ -58,6 +59,8 @@ def run_rpmbuild(kernel_build_dir, target_arch): except subprocess.CalledProcessError as e: print(f"Error: rpmbuild failed with error code {e.returncode}") sys.exit(1) + # go back to script dir + os.chdir(base_dir) if __name__ == "__main__":