2 # -*- coding: utf-8 -*-
4 # === This file is part of Calamares - <http://github.com/calamares> ===
6 # Copyright 2014 - 2019, Philip Müller <philm@manjaro.org>
7 # Copyright 2016, Artoo <artoo@manjaro.org>
9 # Calamares is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # Calamares is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Calamares. If not, see <http://www.gnu.org/licenses/>.
25 from shutil import copy2
26 from distutils.dir_util import copy_tree
27 from os.path import join, exists
28 from libcalamares.utils import target_env_call
31 class ConfigController:
33 self.__root = libcalamares.globalstorage.value("rootMountPoint")
34 self.__keyrings = libcalamares.job.configuration.get('keyrings', [])
42 return self.__keyrings
44 def init_keyring(self):
45 target_env_call(["pacman-key", "--init"])
47 def populate_keyring(self):
48 target_env_call(["pacman-key", "--populate"] + self.keyrings)
50 def terminate(self, proc):
51 target_env_call(['killall', '-9', proc])
53 def copy_file(self, file):
54 if exists("/" + file):
55 copy2("/" + file, join(self.root, file))
57 def copy_folder(self, source, target):
58 if exists("/" + source):
59 copy_tree("/" + source, join(self.root, target))
61 def remove_pkg(self, pkg, path):
62 if exists(join(self.root, path)):
63 target_env_call(['pacman', '-R', '--noconfirm', pkg])
66 subprocess.call(["umount", "-l", join(self.root, mp)])
69 subprocess.call(["mount", "-B", "/" + mp, join(self.root, mp)])
72 subprocess.call(["rm", "-Rf", join(self.root, dir)])
75 subprocess.call(["mkdir", "-p", join(self.root, dir)])
79 self.populate_keyring()
81 # Generate mirror list
82 if exists(join(self.root, "usr/bin/pacman-mirrors")):
83 if libcalamares.globalstorage.value("hasInternet"):
84 target_env_call(["pacman-mirrors", "-f3"])
86 self.copy_file('etc/pacman.d/mirrorlist')
88 # Initialize package manager databases
89 if libcalamares.globalstorage.value("hasInternet"):
90 target_env_call(["pacman", "-Syy"])
92 # Remove unneeded ucode
93 cpu_ucode = subprocess.getoutput("hwinfo --cpu | grep Vendor: -m1 | cut -d\'\"\' -f2")
94 if cpu_ucode == "AuthenticAMD":
95 self.remove_pkg("intel-ucode", "boot/intel-ucode.img")
96 elif cpu_ucode == "GenuineIntel":
97 self.remove_pkg("amd-ucode", "boot/amd-ucode.img")
100 self.remove_pkg("calamares", "usr/bin/calamares")
103 self.copy_folder('etc/skel', 'root')
105 # Workaround for pacman-key bug
106 # FS#45351 https://bugs.archlinux.org/task/45351
107 # We have to kill gpg-agent because if it stays
108 # around we can't reliably unmount
109 # the target partition.
110 self.terminate('gpg-agent')
113 if exists(join(self.root, "usr/bin/update-grub")):
114 target_env_call(["update-grub"])
116 # Enable 'menu_auto_hide' when supported in grubenv
117 if exists(join(self.root, "usr/bin/grub-set-bootflag")):
118 target_env_call(["grub-editenv", "-", "set", "menu_auto_hide=1", "boot_success=1"])
120 # Install Office Suite if selected (WIP)
121 office_package = libcalamares.globalstorage.value("packagechooser_packagechooser")
122 if not office_package:
123 libcalamares.utils.warning("no office suite selected, {!s}".format(office_package))
125 # For PoC we added the Office Packages to mhwd-live overlay in 18.1.0
126 cmd = ["pacman", "-S", office_package, "--noconfirm", "--config", "/opt/mhwd/pacman-mhwd.conf" ]
127 self.mkdir("opt/mhwd")
128 self.mount("opt/mhwd")
129 self.mount("etc/resolv.conf")
131 self.umount("opt/mhwd")
132 self.rmdir("opt/mhwd")
133 self.umount("etc/resolv.conf")
139 """ Misc postinstall configurations """
141 config = ConfigController()