def run(self): self.init_keyring() self.populate_keyring() # Remove calamares self.remove_pkg("calamares", "usr/bin/calamares") # Generate mirror list if exists(join(self.root, "usr/bin/pacman-mirrors")): target_env_call(["pacman-mirrors", "-g"]) else: self.copy_file('etc/pacman.d/mirrorlist') # Copy skel to root self.copy_folder('etc/skel', 'root') # Workaround for pacman-key bug FS#45351 https://bugs.archlinux.org/task/45351 # We have to kill gpg-agent because if it stays around we can't reliably unmount # the target partition. self.terminate('gpg-agent') # Update grub.cfg if exists( join(self.root, "usr/bin/update-grub") ) and libcalamares.globalstorage.value("bootLoader") is not None: target_env_call(["update-grub"]) return None
def run(): root = Path(libcalamares.globalstorage.value("rootMountPoint")) live_list_path = root.joinpath('etc', 'apt', 'sources.list.d', 'live.list') opensshserver_path = root.joinpath('lib', 'systemd', 'system', 'ssh.service') if live_list_path.exists(): live_list_path.unlink() if opensshserver_path.exists(): target_env_call(['dpkg-reconfigure', 'openssh-server']) locale = root.joinpath("etc", "default", "locale") with locale.open("r") as fd: content = fd.readlines() for x in range(0, len(content)): if content[x].startswith("LANG"): continue if content[x].find("@valencia") >= 0: z = content[x].split("=") content[x] = z[0] + "=ca_ES.UTF-8\n" with locale.open("w") as fd: fd.writelines(content) return None
def remove(self, pkgs): """ Removes packages. :param pkgs: """ if self.backend == "packagekit": for pkg in pkgs: check_target_env_call(["pkcon", "-py", "remove", pkg]) elif self.backend == "zypp": check_target_env_call(["zypper", "--non-interactive", "remove"] + pkgs) elif self.backend == "yum": 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 target_env_call(["dnf", "--disablerepo=*", "-C", "-y", "remove"] + pkgs) elif self.backend == "urpmi": check_target_env_call(["urpme", "--auto"] + pkgs) elif self.backend == "apt": 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_target_env_call(["pacman", "-Rs", "--noconfirm"] + pkgs) elif self.backend == "portage": check_target_env_call(["emerge", "-C"] + pkgs) check_target_env_call(["emerge", "--depclean", "-q"]) elif self.backend == "entropy": check_target_env_call(["equo", "rm"] + pkgs)
def run(self): if exists('/etc/sudoers.d/g_oem'): target_env_call(['rm', '/etc/sudoers.d/g_oem']) self.remove_pkg("calamares-oem-modules", "/etc/calamares/modules/welcome.conf") self.remove_pkg("calamares-oem-sx-settings", "/etc/oemskel") if exists('/usr/share/calamares'): target_env_call(['rm', '-R', '/usr/share/calamares']) return None
def run(): """ Create kernel initramfs image """ root_mount_point = libcalamares.globalstorage.value("rootMountPoint") subprocess.check_call([ "cp", "/run/archiso/bootmnt/arch/boot/x86_64/vmlinuz", root_mount_point + "/boot/vmlinuz-linux" ]) run_mkinitcpio() target_env_call(["/usr/bin/cleanup.sh"]) return None
def run(): """ Calls routine to create kernel initramfs image. :return: """ root_mount_point = libcalamares.globalstorage.value("rootMountPoint") subprocess.check_call(["cp", "/run/archiso/bootmnt/arch/boot/x86_64/vmlinuz", root_mount_point + "/boot/vmlinuz-linux"]) run_mkinitcpio() target_env_call(["/etc/apricity-assets/postinstall.sh"]) return None
def run(): """ Starts procedure and passes 'fw_type' to other routine. :return: """ if libcalamares.globalstorage.value("bootLoader") is None: return None target_env_call(["os-prober"]) fw_type = libcalamares.globalstorage.value("firmwareType") prepare_bootloader(fw_type) target_env_call(["/etc/apricity-assets/postinstall.sh"]) return None
def configure(self, name, id): cmd = ["mhwd", "-a", str(name), str(self.driver), str(id).zfill(4)] if self.local: self.mount("opt") cmd.extend(["--pmconfig", self.repo]) self.mount("etc/resolv.conf") target_env_call(cmd) if self.local: self.umount("opt") self.umount("etc/resolv.conf")
def run(self): # self.init_keyring() # self.populate_keyring() # ucode cpu_ucode = subprocess.getoutput( "hwinfo --cpu | grep Vendor: -m1 | cut -d\'\"\' -f2") if cpu_ucode == "AuthenticAMD": #target_env_call(["pacman", "-S", "amd-ucode", "--noconfirm"]) target_env_call(["pacman", "-R", "intel-ucode", "--noconfirm"]) elif cpu_ucode == "GenuineIntel": #target_env_call(["pacman", "-S", "intel-ucode", "--noconfirm"]) target_env_call(["pacman", "-R", "amd-ucode", "--noconfirm"])
def run(): """ Starts procedure and passes 'fw_type' to other routine. :return: """ if libcalamares.globalstorage.value("bootLoader") is None: return None fw_type = libcalamares.globalstorage.value("firmwareType") prepare_bootloader(fw_type) target_env_call(["/etc/apricity-assets/postuseradd.sh"]) return None
def run(): """ Calls routine to create kernel initramfs image. :return: """ root_mount_point = libcalamares.globalstorage.value("rootMountPoint") subprocess.check_call([ "cp", "/run/archiso/bootmnt/arch/boot/x86_64/vmlinuz", root_mount_point + "/boot/vmlinuz-linux" ]) run_mkinitcpio() target_env_call(["/etc/brinkOS-assets/postinstall.sh"]) return None
def run(self): self.init_keyring() self.populate_keyring() # Generate mirror list if exists(join(self.root, "usr/bin/pacman-mirrors")): if libcalamares.globalstorage.value("hasInternet"): target_env_call(["pacman-mirrors", "-f3"]) else: self.copy_file('etc/pacman.d/mirrorlist') # Initialize package manager databases if libcalamares.globalstorage.value("hasInternet"): target_env_call(["pacman", "-Syy"]) # Remove unneeded ucode cpu_ucode = subprocess.getoutput("hwinfo --cpu | grep Vendor: -m1 | cut -d\'\"\' -f2") if cpu_ucode == "AuthenticAMD": self.remove_pkg("intel-ucode", "boot/intel-ucode.img") elif cpu_ucode == "GenuineIntel": self.remove_pkg("amd-ucode", "boot/amd-ucode.img") # Remove calamares self.remove_pkg("calamares", "usr/bin/calamares") # Copy skel to root self.copy_folder('etc/skel', 'root') # Workaround for pacman-key bug # FS#45351 https://bugs.archlinux.org/task/45351 # We have to kill gpg-agent because if it stays # around we can't reliably unmount # the target partition. self.terminate('gpg-agent') # Update grub.cfg if exists(join(self.root, "usr/bin/update-grub")): target_env_call(["update-grub"]) # Enable 'menu_auto_hide' when supported in grubenv if exists(join(self.root, "usr/bin/grub-set-bootflag")): target_env_call(["grub-editenv", "-", "set", "menu_auto_hide=1", "boot_success=1"]) # Install Office Suite if selected (WIP) #office_package = libcalamares.globalstorage.value("packagechooser_packagechooser") #if not office_package: # libcalamares.utils.warning("no office suite selected, {!s}".format(office_package)) #else: # # For PoC we added the Office Packages to mhwd-live overlay in 18.1.0 # cmd = ["pacman", "-S", office_package, "--noconfirm", "--config", "/opt/mhwd/pacman-mhwd.conf" ] # self.mkdir("opt/mhwd") # self.mount("opt/mhwd") # self.mount("etc/resolv.conf") # target_env_call(cmd) # self.umount("opt/mhwd") # self.rmdir("opt/mhwd") # self.umount("etc/resolv.conf") return None
def change_user_password(user, new_password): """ Changes the user's password """ try: shadow_password = crypt.crypt(new_password, crypt.mksalt(crypt.METHOD_SHA512)) except: logging.warning(_("Error creating password hash for user {0}".format(user))) return False try: target_env_call(['usermod', '-p', shadow_password, user]) except: logging.warning(_("Error changing password for user {0}".format(user))) return False return True
def run_dracut(): """ Creates initramfs, even when initramfs already exists. :return: """ return target_env_call(['dracut', '-f'])
def run(): return_code = target_env_call( ['zigzag-write-configuration', '--force', 'post_install']) if return_code != 0: return ("Failed to run zigzag-write-configuration on the target", "The exit code was {}".format(return_code))
def run_mkinitfs(): """ Creates initramfs, even when initramfs already exists. :return: """ return target_env_call(['mkinitfs'])
def detect_plymouth(): """ Checks existence (runnability) of plymouth in the target system. @return True if plymouth exists in the target, False otherwise """ # Used to only check existence of path /usr/bin/plymouth in target return target_env_call(["sh", "-c", "which plymouth"]) == 0
def run(): """ Generate an initramfs image. :return: """ 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)
def detect(self): isPlymouth = target_env_call(["which", "plymouth"]) debug("which plymouth exit code: {!s}".format(isPlymouth)) if isPlymouth == 0: libcalamares.globalstorage.insert("hasPlymouth", True) else: libcalamares.globalstorage.insert("hasPlymouth", False) return isPlymouth
def run(): """ Generate an initramfs image. We can happily assume that there is no initrd on the live system - the old fll behaviour - and we build it only for the running kernel :return: """ return_code = target_env_call( ["update-initramfs", "-k", platform.release(), "-c"]) if return_code != 0: return "Failed to run update-initramfs on the target", "The exit code was {}".format( return_code) return_code = target_env_call(["update-grub"]) if return_code != 0: return "Failed to run update-grub on the target", "The exit code was {}".format( return_code)
def run(): """ Generate an initramfs image. :return: """ 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))
def detect_plymouth(): """ Checks existence (runnability) of plymouth in the target system. @return True if plymouth exists in the target, False otherwise """ # Used to only check existence of path /usr/bin/plymouth in target isPlymouth = target_env_call(["sh", "-c", "which plymouth"]) debug("which plymouth exit code: {!s}".format(isPlymouth)) return isPlymouth == 0
def run(): """ Generate an initramfs image. :return: """ return_code = target_env_call(["update-initramfs", "-k", "all", "-c", "-t"]) if return_code != 0: libcalamares.utils.debug("update-initramfs returned {}".format(return_code)) return ( _("Failed to run update-initramfs on the target"), _("The exit code was {}").format(return_code) )
def update(self, state): """ Call rc-update for each service listed in services for the given @p state. rc-update is called with @p state as the command as well. """ for svc in self.services.get(state, []): if isinstance(svc, str): name = svc runlevel = "default" mandatory = False else: name = svc["name"] runlevel = svc.get("runlevel", "default") mandatory = svc.get("mandatory", False) service_path = self.root + self.initdDir + "/" + name runlevel_path = self.root + self.runlevelsDir + "/" + runlevel if exists(service_path): if exists(runlevel_path): ec = target_env_call(["rc-update", state, name, runlevel]) if ec != 0: if mandatory: return ("Cannot {} service {} to {}".format( state, name, runlevel ), "rc-update {} call in chroot returned error code {}" .format(state, ec)) else: warning( "Could not {} service {} in {}, error {!s}". format(state, name, runlevel, ec)) else: if mandatory: return ( "Target runlevel {} does not exist for {}.".format( runlevel, name), "No {} found.".format(runlevel_path)) else: warning( "Target runlevel {} does not exist for {}.".format( runlevel, name)) else: if mandatory: return ("Target service {} does not exist.".format(name), "No {} found.".format(service_path)) else: warning("Target service {} does not exist in {}.".format( name, self.initdDir))
def update(self, state): """ Call rc-update for each service listed in services for the given @p state. rc-update is called with @p state as the command as well. """ for svc in self.services.get(state, []): if isinstance(svc, str): name = svc runlevel = "default" mandatory = False else: name = svc["name"] runlevel = svc.get("runlevel", "default") mandatory = svc.get("mandatory", False) service_path = self.root + self.initdDir + "/" + name runlevel_path = self.root + self.runlevelsDir + "/" + runlevel if exists(service_path): if exists(runlevel_path): ec = target_env_call(["rc-update", state, name, runlevel]) if ec != 0: warning("Cannot {} service {} to {}".format(state, name, runlevel)) warning("rc-update returned error code {!s}".format(ec)) if mandatory: title = _("Cannot modify service") diagnostic = _("<code>rc-update {arg!s}</code> call in chroot returned error code {num!s}.").format(arg=state, num=ec) return (title, self.make_failure_description(state, name, runlevel) + " " + diagnostic ) else: warning("Target runlevel {} does not exist for {}.".format(runlevel, name)) if mandatory: title = _("Target runlevel does not exist") diagnostic = _("The path for runlevel {level!s} is <code>{path!s}</code>, which does not exist.").format(level=runlevel, path=runlevel_path) return (title, self.make_failure_description(state, name, runlevel) + " " + diagnostic ) else: warning("Target service {} does not exist in {}.".format(name, self.initdDir)) if mandatory: title = _("Target service does not exist") diagnostic = _("The path for service {name!s} is <code>{path!s}</code>, which does not exist.").format(name=name, path=service_path) return (title, self.make_failure_description(state, name, runlevel) + " " + diagnostic )
def run(self): # self.init_keyring() # self.populate_keyring() # ucode cpu_ucode = subprocess.getoutput("hwinfo --cpu | grep Vendor: -m1 | cut -d\'\"\' -f2") if cpu_ucode == "AuthenticAMD": #target_env_call(["pacman", "-S", "amd-ucode", "--noconfirm"]) target_env_call(["pacman", "-R", "intel-ucode", "--noconfirm"]) elif cpu_ucode == "GenuineIntel": #target_env_call(["pacman", "-S", "intel-ucode", "--noconfirm"]) target_env_call(["pacman", "-R", "amd-ucode", "--noconfirm"]) # Vimix grub target_env_call(["grub-mkconfig", "-o", "/boot/grub/grub.cfg"]) # Initialize package manager databases if libcalamares.globalstorage.value("hasInternet"): target_env_call(["reflector", "--threads", "50", "-l", "101", "-f", "101", "--number", "20", "--sort", "rate", "--save", "/etc/pacman.d/mirrorlist"])
def update(self, state): """ Call rc-update for each service listed in services for the given @p state. rc-update is called with @p state as the command as well. """ for svc in self.services.get(state, []): if isinstance(svc, str): name = svc runlevel = "default" mandatory = False else: name = svc["name"] runlevel = svc.get("runlevel", "default") mandatory = svc.get("mandatory", False) service_path = self.root + self.initdDir + "/" + name runlevel_path = self.root + self.runlevelsDir + "/" + runlevel if exists(service_path): if exists(runlevel_path): ec = target_env_call(["rc-update", state, name, runlevel]) if ec != 0: if mandatory: return ("Cannot {} service {} to {}".format(state, name, runlevel), "rc-update {} call in chroot returned error code {}".format(state, ec) ) else: warning("Could not {} service {} in {}, error {!s}".format(state, name, runlevel, ec)) else: if mandatory: return ("Target runlevel {} does not exist for {}.".format(runlevel, name), "No {} found.".format(runlevel_path)) else: warning("Target runlevel {} does not exist for {}.".format(runlevel, name)) else: if mandatory: return ("Target service {} does not exist.".format(name), "No {} found.".format(service_path)) else: warning("Target service {} does not exist in {}.".format(name, self.initdDir))
def run(self): self.init_keyring() self.populate_keyring() # ucode cpu_ucode = subprocess.getoutput( "hwinfo --cpu | grep Vendor: -m1 | cut -d\'\"\' -f2") if cpu_ucode == "AuthenticAMD": #target_env_call(["pacman", "-S", "amd-ucode", "--noconfirm"]) target_env_call(["pacman", "-R", "intel-ucode", "--noconfirm"]) elif cpu_ucode == "GenuineIntel": #target_env_call(["pacman", "-S", "intel-ucode", "--noconfirm"]) target_env_call(["pacman", "-R", "amd-ucode", "--noconfirm"]) # seems to break the multiboot - initramfs missing #target_env_call(["grub-mkconfig", "-o", "/boot/grub/grub.cfg"]) # Initialize package manager databases if libcalamares.globalstorage.value("hasInternet"): target_env_call(["pacman", "-Syy"])
def remove(self, pkgs): # ignore the error code for now because dnf thinks removing a # nonexistent package is an error target_env_call(["dnf", "--disablerepo=*", "-C", "-y", "remove"] + pkgs)
def remove_pkg(self, pkg, path): if exists(join(self.root, path)): target_env_call(['pacman', '-R', '--noconfirm', pkg])
def terminate(self, proc): target_env_call(['killall', '-9', proc])
def detect(self): isPlymouth = target_env_call(["sh", "-c", "which plymouth"]) debug("which plymouth exit code: {!s}".format(isPlymouth)) return isPlymouth
def setTheme(self): plymouth_theme = libcalamares.job.configuration["plymouth_theme"] target_env_call(["sed", "-e", 's|^.*Theme=.*|Theme=' + plymouth_theme + '|', "-i", "/etc/plymouth/plymouthd.conf"])
def populate_keyring(self): target_env_call(["pacman-key", "--populate"] + self.keyrings)
def init_keyring(self): target_env_call(["pacman-key", "--init"])
def remove_pkg(self, pkg, path): if exists(path): target_env_call(['pacman', '-Rsn', '--noconfirm', pkg])