calamares/src/modules/servicescfg/main.py

104 lines
3.4 KiB
Python
Raw Normal View History

2016-09-10 14:18:58 +02:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# === This file is part of Calamares - <http://github.com/calamares> ===
#
# Copyright 2016, Artoo <artoo@manjaro.org>
2017-06-23 11:51:47 +02:00
# Copyright 2017, Philip Müller <philm@manjaro.org>
2016-09-10 14:18:58 +02:00
#
# 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 libcalamares.utils import target_env_call
2016-09-10 14:18:58 +02:00
from os.path import exists, join
2017-06-23 11:51:47 +02:00
2016-09-10 14:18:58 +02:00
class ServicesController:
def __init__(self):
self.__root = libcalamares.globalstorage.value('rootMountPoint')
self.__services = libcalamares.job.configuration.get('services', [])
@property
def root(self):
return self.__root
@property
def services(self):
return self.__services
def setExpression(self, pattern, file):
target_env_call(["sed", "-e", pattern, "-i", file])
2016-09-10 14:18:58 +02:00
def configure(self):
2017-06-23 11:51:47 +02:00
self.setExpression(
's|^.*rc_shell=.*|rc_shell="/usr/bin/sulogin"|',
"/etc/rc.conf"
)
self.setExpression(
's|^.*rc_controller_cgroups=.*|rc_controller_cgroups="YES"|',
"/etc/rc.conf"
)
exp = 's|^.*keymap=.*|keymap="' \
+ libcalamares.globalstorage.value("keyboardLayout") \
+ '"|'
2016-09-10 14:18:58 +02:00
self.setExpression(exp, "/etc/conf.d/keymaps")
2017-06-23 11:51:47 +02:00
self.setExpression(
's|pam_systemd.so|pam_ck_connector.so nox11|',
"/etc/pam.d/system-login"
)
2016-09-10 14:18:58 +02:00
for dm in libcalamares.globalstorage.value("displayManagers"):
exp = 's|^.*DISPLAYMANAGER=.*|DISPLAYMANAGER="' + dm + '"|'
self.setExpression(exp, "/etc/conf.d/xdm")
if dm == "lightdm":
2017-06-23 11:51:47 +02:00
self.setExpression(
's|^.*minimum-vt=.*|minimum-vt=7|',
"/etc/lightdm/lightdm.conf"
)
self.setExpression(
's|pam_systemd.so|pam_ck_connector.so nox11|',
"/etc/pam.d/lightdm-greeter"
)
2016-09-23 22:37:23 +02:00
if exists(join(self.root, "etc/pulse/client.conf")):
2017-06-23 11:51:47 +02:00
self.setExpression(
's|autospawn = no|autospawn = yes|',
"/etc/pulse/client.conf"
)
2016-09-10 14:18:58 +02:00
def update(self, action, state):
for svc in self.services[state]:
if exists(self.root + "/etc/init.d/" + svc["name"]):
2017-06-23 12:29:44 +02:00
target_env_call([
"rc-update",
action,
svc["name"],
svc["runlevel"]
])
2016-09-10 14:18:58 +02:00
def run(self):
self.configure()
for state in self.services.keys():
if state == "enabled":
self.update("add", "enabled")
elif state == "disabled":
self.update("del", "disabled")
return None
2017-06-23 11:51:47 +02:00
2016-09-10 14:18:58 +02:00
def run():
""" Setup openrc services """
sc = ServicesController()
return sc.run()