calamares/src/modules/postcfg/main.py

117 lines
3.8 KiB
Python
Raw Normal View History

2016-09-10 13:56:05 +02:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# === This file is part of Calamares - <http://github.com/calamares> ===
#
# Copyright 2014 - 2018, Philip Müller <philm@manjaro.org>
2016-09-10 13:56:05 +02:00
# Copyright 2016, Artoo <artoo@manjaro.org>
#
# Calamares is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Calamares is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
import libcalamares
from shutil import copy2
from distutils.dir_util import copy_tree
2016-09-10 13:56:05 +02:00
from os.path import join, exists
from libcalamares.utils import target_env_call
2016-09-10 13:56:05 +02:00
2017-06-23 11:24:17 +02:00
2016-09-10 13:56:05 +02:00
class ConfigController:
def __init__(self):
self.__root = libcalamares.globalstorage.value("rootMountPoint")
2016-09-10 13:56:05 +02:00
self.__keyrings = libcalamares.job.configuration.get('keyrings', [])
2016-09-10 13:56:05 +02:00
@property
def root(self):
return self.__root
2016-09-10 13:56:05 +02:00
@property
def keyrings(self):
return self.__keyrings
2016-09-10 13:56:05 +02:00
def init_keyring(self):
target_env_call(["pacman-key", "--init"])
2016-09-10 13:56:05 +02:00
def populate_keyring(self):
target_env_call(["pacman-key", "--populate"] + self.keyrings)
2016-09-10 13:56:05 +02:00
def terminate(self, proc):
target_env_call(['killall', '-9', proc])
2016-09-10 13:56:05 +02:00
def copy_file(self, file):
if exists("/" + file):
copy2("/" + file, join(self.root, file))
2016-09-10 13:56:05 +02:00
def copy_folder(self, source, target):
if exists("/" + source):
copy_tree("/" + source, join(self.root, target))
2016-09-10 13:56:05 +02:00
def remove_pkg(self, pkg, path):
if exists(join(self.root, path)):
target_env_call(['pacman', '-R', '--noconfirm', pkg])
2016-09-10 13:56:05 +02:00
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"):
2018-01-02 09:35:43 +01:00
target_env_call(["pacman-mirrors", "-f3"])
2016-09-10 13:56:05 +02:00
else:
self.copy_file('etc/pacman.d/mirrorlist')
# Initialize package manager databases
if libcalamares.globalstorage.value("hasInternet"):
target_env_call(["pacman", "-Syy"])
2018-08-26 05:06:25 +02:00
# Remove unneeded ucode
cpu_ucode = target_env_call(["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")
2016-09-10 13:56:05 +02:00
# Copy skel to root
self.copy_folder('etc/skel', 'root')
2017-06-23 11:24:17 +02:00
# 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
2016-09-10 13:56:05 +02:00
# the target partition.
self.terminate('gpg-agent')
2016-09-10 13:56:05 +02:00
# Update grub.cfg
2017-06-23 11:59:45 +02:00
if exists(join(self.root, "usr/bin/update-grub")) \
and libcalamares.globalstorage.value("bootLoader") is not None:
2016-09-10 13:56:05 +02:00
target_env_call(["update-grub"])
2018-09-25 20:15:40 +02:00
# Enable 'menu_auto_hide' when supported in grubenv
2018-09-25 20:16:20 +02:00
if exists(join(self.root, "usr/bin/grub-set-bootflag")):
2018-09-25 20:15:40 +02:00
target_env_call(["grub-editenv - set menu_auto_hide=1"])
2016-09-10 13:56:05 +02:00
return None
2017-06-23 11:24:17 +02:00
2016-09-10 13:56:05 +02:00
def run():
""" Misc postinstall configurations """
config = ConfigController()
2016-09-10 13:56:05 +02:00
return config.run()