From 10ce42f35cec706cba9cd800350428d6d1655754 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 6 Aug 2015 12:13:21 +0200 Subject: [PATCH] Use target_env calls in Python modules. --- src/modules/bootloader/main.py | 14 +++---- src/modules/displaymanager/main.py | 64 +++++++++++++++--------------- src/modules/dracut/main.py | 4 +- src/modules/grubcfg/main.py | 2 +- src/modules/initcpio/main.py | 4 +- src/modules/initcpiocfg/main.py | 2 +- src/modules/initramfs/main.py | 4 +- src/modules/localecfg/main.py | 2 +- src/modules/machineid/main.py | 8 ++-- src/modules/packages/main.py | 40 +++++++++---------- src/modules/removeuser/main.py | 2 +- src/modules/services/main.py | 4 +- 12 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/modules/bootloader/main.py b/src/modules/bootloader/main.py index fa3a3c251..d32c7b44d 100644 --- a/src/modules/bootloader/main.py +++ b/src/modules/bootloader/main.py @@ -28,7 +28,7 @@ import libcalamares import os import subprocess -from libcalamares.utils import check_chroot_call +from libcalamares.utils import check_target_env_call def get_uuid(): @@ -167,7 +167,7 @@ def install_grub(efi_directory, fw_type): if fw_type == "efi": print("Bootloader: grub (efi)") efi_directory_firmware = efi_directory + "/EFI" - check_chroot_call(["mkdir", "-p", "{!s}".format(efi_directory)]) + check_target_env_call(["mkdir", "-p", "{!s}".format(efi_directory)]) if "efiBootloaderId" in libcalamares.job.configuration: efi_bootloader_id = libcalamares.job.configuration["efiBootloaderId"] @@ -176,21 +176,21 @@ def install_grub(efi_directory, fw_type): distribution = branding["bootloaderEntryName"] file_name_sanitizer = str.maketrans(" /", "_-") efi_bootloader_id = distribution.translate(file_name_sanitizer) - check_chroot_call([libcalamares.job.configuration["grubInstall"], "--target=x86_64-efi", + check_target_env_call([libcalamares.job.configuration["grubInstall"], "--target=x86_64-efi", "--efi-directory={!s}".format(efi_directory), "--bootloader-id={!s}".format(efi_bootloader_id), "--force"]) # Workaround for some UEFI firmwares - check_chroot_call(["mkdir", "-p", "{!s}/boot".format(efi_directory_firmware)]) - check_chroot_call(["cp", "{!s}/{!s}/grubx64.efi".format(efi_directory_firmware, efi_bootloader_id), + check_target_env_call(["mkdir", "-p", "{!s}/boot".format(efi_directory_firmware)]) + check_target_env_call(["cp", "{!s}/{!s}/grubx64.efi".format(efi_directory_firmware, efi_bootloader_id), "{!s}/boot/bootx64.efi".format(efi_directory_firmware)]) else: print("Bootloader: grub (bios)") boot_loader = libcalamares.globalstorage.value("bootLoader") - check_chroot_call([libcalamares.job.configuration["grubInstall"], "--target=i386-pc", + check_target_env_call([libcalamares.job.configuration["grubInstall"], "--target=i386-pc", "--recheck", "--force", boot_loader["installPath"]]) - check_chroot_call([libcalamares.job.configuration["grubMkconfig"], "-o", + check_target_env_call([libcalamares.job.configuration["grubMkconfig"], "-o", libcalamares.job.configuration["grubCfg"]]) diff --git a/src/modules/displaymanager/main.py b/src/modules/displaymanager/main.py index b5a9dbb02..b8e04259b 100644 --- a/src/modules/displaymanager/main.py +++ b/src/modules/displaymanager/main.py @@ -254,7 +254,7 @@ def set_autologin(username, displaymanagers, default_desktop_environment, root_m if os.path.isfile(sddm_conf_path): libcalamares.utils.debug('SDDM config file exists') else: - libcalamares.utils.check_chroot_call(["sh", "-c", "sddm --example-config > /etc/sddm.conf"]) + libcalamares.utils.check_target_env_call(["sh", "-c", "sddm --example-config > /etc/sddm.conf"]) text = [] @@ -332,19 +332,19 @@ def run(): if "lightdm" in displaymanagers: if have_dm("lightdm", root_mount_point): if enable_basic_setup: - libcalamares.utils.chroot_call(['mkdir', '-p', '/run/lightdm']) + libcalamares.utils.target_env_call(['mkdir', '-p', '/run/lightdm']) - if libcalamares.utils.chroot_call(['getent', 'group', 'lightdm']) != 0: - libcalamares.utils.chroot_call(['groupadd', '-g', '620', 'lightdm']) + if libcalamares.utils.target_env_call(['getent', 'group', 'lightdm']) != 0: + libcalamares.utils.target_env_call(['groupadd', '-g', '620', 'lightdm']) - if libcalamares.utils.chroot_call(['getent', 'passwd', 'lightdm']) != 0: - libcalamares.utils.chroot_call(['useradd', '-c', '"LightDM Display Manager"', + if libcalamares.utils.target_env_call(['getent', 'passwd', 'lightdm']) != 0: + libcalamares.utils.target_env_call(['useradd', '-c', '"LightDM Display Manager"', '-u', '620', '-g', 'lightdm', '-d', '/var/run/lightdm', '-s', '/usr/bin/nologin', 'lightdm']) - libcalamares.utils.chroot_call(['passwd', '-l', 'lightdm']) - libcalamares.utils.chroot_call(['chown', '-R', 'lightdm:lightdm', '/run/lightdm']) - libcalamares.utils.chroot_call(['chmod', '+r' '/etc/lightdm/lightdm.conf']) + libcalamares.utils.target_env_call(['passwd', '-l', 'lightdm']) + libcalamares.utils.target_env_call(['chown', '-R', 'lightdm:lightdm', '/run/lightdm']) + libcalamares.utils.target_env_call(['chmod', '+r' '/etc/lightdm/lightdm.conf']) if default_desktop_environment is not None: os.system("sed -i -e \"s/^.*user-session=.*/user-session={!s}/\" {!s}/etc/lightdm/lightdm.conf".format( @@ -357,16 +357,16 @@ def run(): if "gdm" in displaymanagers: if have_dm("gdm", root_mount_point): if enable_basic_setup: - if libcalamares.utils.chroot_call(['getent', 'group', 'gdm']) != 0: - libcalamares.utils.chroot_call(['groupadd', '-g', '120', 'gdm']) + if libcalamares.utils.target_env_call(['getent', 'group', 'gdm']) != 0: + libcalamares.utils.target_env_call(['groupadd', '-g', '120', 'gdm']) - if libcalamares.utils.chroot_call(['getent', 'passwd', 'gdm']) != 0: - libcalamares.utils.chroot_call(['useradd', '-c', '"Gnome Display Manager"', + if libcalamares.utils.target_env_call(['getent', 'passwd', 'gdm']) != 0: + libcalamares.utils.target_env_call(['useradd', '-c', '"Gnome Display Manager"', '-u', '120', '-g', 'gdm', '-d', '/var/lib/gdm', '-s', '/usr/bin/nologin', 'gdm']) - libcalamares.utils.chroot_call(['passwd', '-l', 'gdm']) - libcalamares.utils.chroot_call(['chown', '-R', 'gdm:gdm', '/var/lib/gdm']) + libcalamares.utils.target_env_call(['passwd', '-l', 'gdm']) + libcalamares.utils.target_env_call(['chown', '-R', 'gdm:gdm', '/var/lib/gdm']) else: libcalamares.utils.debug("gdm selected but not installed") displaymanagers.remove("gdm") @@ -375,17 +375,17 @@ def run(): if "mdm" in displaymanagers: if have_dm("mdm", root_mount_point): if enable_basic_setup: - if libcalamares.utils.chroot_call(['getent', 'group', 'mdm']) != 0: - libcalamares.utils.chroot_call(['groupadd', '-g', '128', 'mdm']) + if libcalamares.utils.target_env_call(['getent', 'group', 'mdm']) != 0: + libcalamares.utils.target_env_call(['groupadd', '-g', '128', 'mdm']) - if libcalamares.utils.chroot_call(['getent', 'passwd', 'mdm']) != 0: - libcalamares.utils.chroot_call(['useradd', '-c', '"Linux Mint Display Manager"', + if libcalamares.utils.target_env_call(['getent', 'passwd', 'mdm']) != 0: + libcalamares.utils.target_env_call(['useradd', '-c', '"Linux Mint Display Manager"', '-u', '128', '-g', 'mdm', '-d', '/var/lib/mdm', '-s', '/usr/bin/nologin', 'mdm']) - libcalamares.utils.chroot_call(['passwd', '-l', 'mdm']) - libcalamares.utils.chroot_call(['chown', 'root:mdm', '/var/lib/mdm']) - libcalamares.utils.chroot_call(['chmod', '1770', '/var/lib/mdm']) + libcalamares.utils.target_env_call(['passwd', '-l', 'mdm']) + libcalamares.utils.target_env_call(['chown', 'root:mdm', '/var/lib/mdm']) + libcalamares.utils.target_env_call(['chmod', '1770', '/var/lib/mdm']) if default_desktop_environment is not None: os.system("sed -i \"s|default.desktop|{!s}.desktop|g\" {!s}/etc/mdm/custom.conf".format( @@ -398,12 +398,12 @@ def run(): if "lxdm" in displaymanagers: if have_dm("lxdm", root_mount_point): if enable_basic_setup: - if libcalamares.utils.chroot_call(['getent', 'group', 'lxdm']) != 0: - libcalamares.utils.chroot_call(['groupadd', '--system', 'lxdm']) + if libcalamares.utils.target_env_call(['getent', 'group', 'lxdm']) != 0: + libcalamares.utils.target_env_call(['groupadd', '--system', 'lxdm']) - libcalamares.utils.chroot_call(['chgrp', '-R', 'lxdm', '/var/lib/lxdm']) - libcalamares.utils.chroot_call(['chgrp', 'lxdm', '/etc/lxdm/lxdm.conf']) - libcalamares.utils.chroot_call(['chmod', '+r', '/etc/lxdm/lxdm.conf']) + libcalamares.utils.target_env_call(['chgrp', '-R', 'lxdm', '/var/lib/lxdm']) + libcalamares.utils.target_env_call(['chgrp', 'lxdm', '/etc/lxdm/lxdm.conf']) + libcalamares.utils.target_env_call(['chmod', '+r', '/etc/lxdm/lxdm.conf']) if default_desktop_environment is not None: os.system("sed -i -e \"s|^.*session=.*|session={!s}|\" {!s}/etc/lxdm/lxdm.conf".format( @@ -416,14 +416,14 @@ def run(): if "kdm" in displaymanagers: if have_dm("kdm", root_mount_point): if enable_basic_setup: - if libcalamares.utils.chroot_call(['getent', 'group', 'kdm']) != 0: - libcalamares.utils.chroot_call(['groupadd', '-g', '135', 'kdm']) + if libcalamares.utils.target_env_call(['getent', 'group', 'kdm']) != 0: + libcalamares.utils.target_env_call(['groupadd', '-g', '135', 'kdm']) - if libcalamares.utils.chroot_call(['getent', 'passwd', 'kdm']) != 0: - libcalamares.utils.chroot_call(['useradd', '-u', '135', '-g', 'kdm', '-d', + if libcalamares.utils.target_env_call(['getent', 'passwd', 'kdm']) != 0: + libcalamares.utils.target_env_call(['useradd', '-u', '135', '-g', 'kdm', '-d', '/var/lib/kdm', '-s', '/bin/false', '-r', '-M', 'kdm']) - libcalamares.utils.chroot_call(['chown', '-R', '135:135', 'var/lib/kdm']) + libcalamares.utils.target_env_call(['chown', '-R', '135:135', 'var/lib/kdm']) else: libcalamares.utils.debug("kdm selected but not installed") displaymanagers.remove("kdm") diff --git a/src/modules/dracut/main.py b/src/modules/dracut/main.py index ef97899ee..46902fb07 100644 --- a/src/modules/dracut/main.py +++ b/src/modules/dracut/main.py @@ -20,7 +20,7 @@ # along with Calamares. If not, see . import libcalamares -from libcalamares.utils import chroot_call +from libcalamares.utils import target_env_call def run_dracut(): @@ -28,7 +28,7 @@ def run_dracut(): :return: """ - return chroot_call(['dracut', '-f']) + return target_env_call(['dracut', '-f']) def run(): diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index 5ab041170..5f4e7dcaa 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -35,7 +35,7 @@ def modify_grub_default(partitions, root_mount_point, distributor): default_dir = os.path.join(root_mount_point, "etc/default") default_grub = os.path.join(default_dir, "grub") distributor_replace = distributor.replace("'", "'\\''") - plymouth_bin = libcalamares.utils.chroot_call(["sh", "-c", "which plymouth"]) + plymouth_bin = libcalamares.utils.target_env_call(["sh", "-c", "which plymouth"]) use_splash = "" swap_uuid = "" diff --git a/src/modules/initcpio/main.py b/src/modules/initcpio/main.py index f7c1cd336..24366f9ad 100644 --- a/src/modules/initcpio/main.py +++ b/src/modules/initcpio/main.py @@ -19,13 +19,13 @@ # along with Calamares. If not, see . import libcalamares -from libcalamares.utils import check_chroot_call +from libcalamares.utils import check_target_env_call def run_mkinitcpio(): """ Runs mkinitcpio with given kernel profile """ kernel = libcalamares.job.configuration['kernel'] - check_chroot_call(['mkinitcpio', '-p', kernel]) + check_target_env_call(['mkinitcpio', '-p', kernel]) def run(): diff --git a/src/modules/initcpiocfg/main.py b/src/modules/initcpiocfg/main.py index f811e8edb..5d4c704f0 100644 --- a/src/modules/initcpiocfg/main.py +++ b/src/modules/initcpiocfg/main.py @@ -22,7 +22,7 @@ import libcalamares import os from collections import OrderedDict -from libcalamares.utils import check_chroot_call +from libcalamares.utils import check_target_env_call def cpuinfo(): diff --git a/src/modules/initramfs/main.py b/src/modules/initramfs/main.py index 37279c4d3..58fb296b9 100644 --- a/src/modules/initramfs/main.py +++ b/src/modules/initramfs/main.py @@ -18,7 +18,7 @@ # You should have received a copy of the GNU General Public License # along with Calamares. If not, see . -from libcalamares.utils import chroot_call +from libcalamares.utils import target_env_call def run(): @@ -26,7 +26,7 @@ def run(): :return: """ - return_code = chroot_call(["update-initramfs", "-k", "all", "-u"]) + return_code = target_env_call(["update-initramfs", "-k", "all", "-u"]) if return_code != 0: return "Failed to run update-initramfs on the target", "The exit code was {}".format(return_code) diff --git a/src/modules/localecfg/main.py b/src/modules/localecfg/main.py index 8f6330fe3..eaa5e0344 100644 --- a/src/modules/localecfg/main.py +++ b/src/modules/localecfg/main.py @@ -60,7 +60,7 @@ def run(): gen.write(line) - libcalamares.utils.chroot_call(['locale-gen']) + libcalamares.utils.target_env_call(['locale-gen']) print('locale.gen done') locale_conf_path = os.path.join(install_path, "etc/locale.conf") diff --git a/src/modules/machineid/main.py b/src/modules/machineid/main.py index ddf134f5a..36b4833fc 100644 --- a/src/modules/machineid/main.py +++ b/src/modules/machineid/main.py @@ -20,7 +20,7 @@ import libcalamares import os -from libcalamares.utils import check_chroot_call +from libcalamares.utils import check_target_env_call def run(): @@ -38,7 +38,7 @@ def run(): if os.path.exists(target_systemd_machineid_file): os.remove(target_systemd_machineid_file) - check_chroot_call("systemd-machine-id-setup") + check_target_env_call("systemd-machine-id-setup") if enable_dbus: target_dbus_machineid_file = "{}/var/lib/dbus/machine-id".format(root_mount_point) @@ -47,8 +47,8 @@ def run(): os.remove(target_dbus_machineid_file) if enable_symlink and os.path.exists(target_systemd_machineid_file): - check_chroot_call(["ln", "-s", "/etc/machine-id", "/var/lib/dbus/machine-id"]) + check_target_env_call(["ln", "-s", "/etc/machine-id", "/var/lib/dbus/machine-id"]) else: - check_chroot_call(["dbus-uuidgen", "--ensure"]) + check_target_env_call(["dbus-uuidgen", "--ensure"]) return None diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index 8149d1eb9..216e1c046 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -19,7 +19,7 @@ # along with Calamares. If not, see . import libcalamares -from libcalamares.utils import check_chroot_call, chroot_call +from libcalamares.utils import check_target_env_call, target_env_call class PackageManager: @@ -38,30 +38,30 @@ class PackageManager: """ if self.backend == "packagekit": for pkg in pkgs: - check_chroot_call(["pkcon", "-py", "install", pkg]) + check_target_env_call(["pkcon", "-py", "install", pkg]) elif self.backend == "zypp": - check_chroot_call(["zypper", "--non-interactive", "--quiet-install", "install", + check_target_env_call(["zypper", "--non-interactive", "--quiet-install", "install", "--auto-agree-with-licenses", "install"] + pkgs) elif self.backend == "yum": - check_chroot_call(["yum", "install", "-y"] + pkgs) + check_target_env_call(["yum", "install", "-y"] + pkgs) elif self.backend == "dnf": - check_chroot_call(["dnf", "install", "-y"] + pkgs) + check_target_env_call(["dnf", "install", "-y"] + pkgs) elif self.backend == "urpmi": - check_chroot_call(["urpmi", "--download-all", "--no-suggests", "--no-verify-rpm", + check_target_env_call(["urpmi", "--download-all", "--no-suggests", "--no-verify-rpm", "--fastunsafe", "--ignoresize", "--nolock", "--auto"] + pkgs) elif self.backend == "apt": - check_chroot_call(["apt-get", "-q", "-y", "install"] + pkgs) + check_target_env_call(["apt-get", "-q", "-y", "install"] + pkgs) elif self.backend == "pacman": if from_local: pacman_flags = "-U" else: pacman_flags = "-Sy" - check_chroot_call(["pacman", pacman_flags, "--noconfirm"] + pkgs) + check_target_env_call(["pacman", pacman_flags, "--noconfirm"] + pkgs) elif self.backend == "portage": - check_chroot_call(["emerge", "-v"] + pkgs) + check_target_env_call(["emerge", "-v"] + pkgs) elif self.backend == "entropy": - check_chroot_call(["equo", "i"] + pkgs) + check_target_env_call(["equo", "i"] + pkgs) def remove(self, pkgs): """ Removes packages. @@ -70,25 +70,25 @@ class PackageManager: """ if self.backend == "packagekit": for pkg in pkgs: - check_chroot_call(["pkcon", "-py", "remove", pkg]) + check_target_env_call(["pkcon", "-py", "remove", pkg]) elif self.backend == "zypp": - check_chroot_call(["zypper", "--non-interactive", "remove"] + pkgs) + check_target_env_call(["zypper", "--non-interactive", "remove"] + pkgs) elif self.backend == "yum": - check_chroot_call(["yum", "--disablerepo=*", "-C", "-y", "remove"] + pkgs) + check_target_env_call(["yum", "--disablerepo=*", "-C", "-y", "remove"] + pkgs) elif self.backend == "dnf": # ignore the error code for now because dnf thinks removing a nonexistent package is an error - chroot_call(["dnf", "--disablerepo=*", "-C", "-y", "remove"] + pkgs) + target_env_call(["dnf", "--disablerepo=*", "-C", "-y", "remove"] + pkgs) elif self.backend == "urpmi": - check_chroot_call(["urpme", "--auto"] + pkgs) + check_target_env_call(["urpme", "--auto"] + pkgs) elif self.backend == "apt": - check_chroot_call(["apt-get", "--purge", "-q", "-y", "remove"] + pkgs) - check_chroot_call(["apt-get", "--purge", "-q", "-y", "autoremove"]) + check_target_env_call(["apt-get", "--purge", "-q", "-y", "remove"] + pkgs) + check_target_env_call(["apt-get", "--purge", "-q", "-y", "autoremove"]) elif self.backend == "pacman": - check_chroot_call(["pacman", "-Rs", "--noconfirm"] + pkgs) + check_target_env_call(["pacman", "-Rs", "--noconfirm"] + pkgs) elif self.backend == "portage": - check_chroot_call(["emerge", "-C"] + pkgs) + check_target_env_call(["emerge", "-C"] + pkgs) elif self.backend == "entropy": - check_chroot_call(["equo", "rm"] + pkgs) + check_target_env_call(["equo", "rm"] + pkgs) def run_operations(pkgman, entry): diff --git a/src/modules/removeuser/main.py b/src/modules/removeuser/main.py index 05366caf0..f31e1dc9d 100644 --- a/src/modules/removeuser/main.py +++ b/src/modules/removeuser/main.py @@ -27,7 +27,7 @@ def run(): username = libcalamares.job.configuration["username"] try: - libcalamares.utils.check_chroot_call(["userdel", "-f", "-r", username]) + libcalamares.utils.check_target_env_call(["userdel", "-f", "-r", username]) except subprocess.CalledProcessError as e: libcalamares.utils.debug("Cannot remove user.", "'userdel' terminated with exit code {}.".format(e.returncode)) diff --git a/src/modules/services/main.py b/src/modules/services/main.py index dbaebaa2e..a7c23b677 100644 --- a/src/modules/services/main.py +++ b/src/modules/services/main.py @@ -30,7 +30,7 @@ def run(): # enable services for svc in services: - ec = libcalamares.utils.chroot_call(['systemctl', 'enable', '{}.service'.format(svc['name'])]) + ec = libcalamares.utils.target_env_call(['systemctl', 'enable', '{}.service'.format(svc['name'])]) if ec != 0: if svc['mandatory']: @@ -42,7 +42,7 @@ def run(): # enable targets for tgt in targets: - ec = libcalamares.utils.chroot_call(['systemctl', 'enable', '{}.target'.format(tgt['name'])]) + ec = libcalamares.utils.target_env_call(['systemctl', 'enable', '{}.target'.format(tgt['name'])]) if ec != 0: if tgt['mandatory']: