Compare commits
1 Commits
services-d
...
postcfg
Author | SHA1 | Date | |
---|---|---|---|
041dcd2983 |
80
src/modules/postcfg/main.py
Normal file
80
src/modules/postcfg/main.py
Normal file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
#
|
||||
# Copyright 2014 - 2016, Philip Müller <philm@manjaro.org>
|
||||
# Copyright 2016, Artoo <artoo@manjaro.org>
|
||||
# Copyright 2018, Artoo <artoo@artixlinux.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/>.
|
||||
|
||||
|
||||
from os.path import join, exists
|
||||
|
||||
import libcalamares
|
||||
from libcalamares.utils import target_env_call
|
||||
|
||||
|
||||
class ConfigController:
|
||||
"""Configuration controller
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.root = libcalamares.globalstorage.value("rootMountPoint")
|
||||
|
||||
def terminate(self, proc):
|
||||
"""Send SIGKILL to the given proccess
|
||||
"""
|
||||
target_env_call(['killall', '-9', proc])
|
||||
|
||||
def sedFile(self, pattern, file):
|
||||
"""Sed the given file with the given pattern
|
||||
"""
|
||||
target_env_call(["sed", "-e", pattern, "-i", file])
|
||||
|
||||
def configure(self):
|
||||
"""Configure the services
|
||||
"""
|
||||
if exists(join(self.root, "/etc/conf.d/keymaps")):
|
||||
exp = 's|^.*keymap=.*|keymap="{}"|'.format(
|
||||
libcalamares.globalstorage.value("keyboardLayout")
|
||||
)
|
||||
self.sedFile(exp, "/etc/conf.d/keymaps")
|
||||
|
||||
if exists(join(self.root, "/etc/conf.d/xdm")):
|
||||
for dm in libcalamares.globalstorage.value("displayManagers"):
|
||||
exp = 's|^.*DISPLAYMANAGER=.*|DISPLAYMANAGER="{}"|'.format(dm)
|
||||
self.sedFile(exp, "/etc/conf.d/xdm")
|
||||
|
||||
|
||||
def run(self):
|
||||
"""Run the controller
|
||||
|
||||
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.configure()
|
||||
self.terminate('gpg-agent')
|
||||
|
||||
|
||||
def run():
|
||||
""" Misc postinstall configurations """
|
||||
|
||||
config = ConfigController()
|
||||
|
||||
return config.run()
|
7
src/modules/postcfg/module.desc
Normal file
7
src/modules/postcfg/module.desc
Normal file
@@ -0,0 +1,7 @@
|
||||
# Syntax is YAML 1.2
|
||||
---
|
||||
type: "job"
|
||||
name: "postcfg"
|
||||
interface: "python"
|
||||
script: "main.py" #assumed relative to the current directory
|
||||
noconfig: true
|
@@ -1,133 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
#
|
||||
# Copyright 2018-2019, Adriaan de Groot <groot@kde.org>
|
||||
# Copyright 2021, Artoo <artoo@artixlinux.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 libcalamares.utils import target_env_call, warning
|
||||
from os.path import exists, join
|
||||
|
||||
|
||||
import gettext
|
||||
_ = gettext.translation("calamares-python",
|
||||
localedir=libcalamares.utils.gettext_path(),
|
||||
languages=libcalamares.utils.gettext_languages(),
|
||||
fallback=True).gettext
|
||||
|
||||
|
||||
def pretty_name():
|
||||
return _("Configure Dinit services")
|
||||
|
||||
|
||||
class DinitController:
|
||||
"""
|
||||
This is the dinit service controller.
|
||||
All of its state comes from global storage and the job
|
||||
configuration at initialization time.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.root = libcalamares.globalstorage.value('rootMountPoint')
|
||||
|
||||
# Translate the entries in the config to the actions passed to sv-helper
|
||||
self.services = dict()
|
||||
self.services["enable"] = libcalamares.job.configuration.get('services', [])
|
||||
self.services["disable"] = libcalamares.job.configuration.get('disable', [])
|
||||
|
||||
self.initdDir = libcalamares.job.configuration['initdDir']
|
||||
self.runsvDir = libcalamares.job.configuration['runsvDir']
|
||||
|
||||
|
||||
def make_failure_description(self, state, name):
|
||||
"""
|
||||
Returns a generic "could not <foo>" failure message, specialized
|
||||
for the action @p state and the specific service @p name.
|
||||
"""
|
||||
if state == "enable":
|
||||
description = _("Cannot enable service {name!s}.")
|
||||
elif state == "disable":
|
||||
description = _("Cannot disable service {name!s}.")
|
||||
else:
|
||||
description = _("Unknown service-action <code>{arg!s}</code> for service {name!s}.")
|
||||
|
||||
return description.format(arg=state, name=name)
|
||||
|
||||
|
||||
def update(self, state):
|
||||
"""
|
||||
Process each service listed
|
||||
in services for the given @p state.
|
||||
"""
|
||||
|
||||
for svc in self.services.get(state, []):
|
||||
if isinstance(svc, str):
|
||||
name = svc
|
||||
mandatory = False
|
||||
else:
|
||||
name = svc["name"]
|
||||
mandatory = svc.get("mandatory", False)
|
||||
|
||||
service_path = self.root + self.initdDir + "/" + name
|
||||
runlevel_path = self.root + self.runsvDir
|
||||
src = self.initdDir + "/" + name
|
||||
dest = self.runsvDir + "/"
|
||||
|
||||
if state == 'enable':
|
||||
cmd = ["ln", "-sv", src, dest]
|
||||
elif state == 'disable':
|
||||
cmd = ["rm", "-rv", dest]
|
||||
|
||||
if exists(service_path):
|
||||
if exists(runlevel_path):
|
||||
ec = target_env_call(cmd)
|
||||
if ec != 0:
|
||||
warning("Cannot {} service {}".format(state, name))
|
||||
warning("{} returned error code {!s}".format(cmd, ec))
|
||||
if mandatory:
|
||||
title = _("Cannot modify service")
|
||||
diagnostic = _("<code>cmd {arg!s}</code> call in chroot returned error code {num!s}.").format(arg=state, num=ec)
|
||||
return (title,
|
||||
self.make_failure_description(state, name) + " " + 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) + " " + diagnostic
|
||||
)
|
||||
|
||||
|
||||
def run(self):
|
||||
"""Run the controller
|
||||
"""
|
||||
|
||||
for state in ("enable", "disable"):
|
||||
r = self.update(state)
|
||||
if r is not None:
|
||||
return r
|
||||
|
||||
def run():
|
||||
"""
|
||||
Setup services
|
||||
"""
|
||||
|
||||
return DinitController().run()
|
@@ -1,5 +0,0 @@
|
||||
---
|
||||
type: "job"
|
||||
name: "services-dinit"
|
||||
interface: "python"
|
||||
script: "main.py"
|
@@ -1,41 +0,0 @@
|
||||
# runit services module to modify service runlevels via symlinks in the chroot
|
||||
#
|
||||
# Services can be added (to any runlevel, or multiple runlevels) or deleted.
|
||||
# Handle disable with care and only use it if absolutely necessary.
|
||||
#
|
||||
# if a service is listed in the conf but is not present/detected on the target system,
|
||||
# it will be ignored and skipped; a warning is logged.
|
||||
#
|
||||
---
|
||||
# initdDir: holds the runit service directory location
|
||||
initdDir: /etc/dinit.d
|
||||
|
||||
# runsvDir: holds the runlevels directory location
|
||||
runsvDir: /etc/dinit.d/boot.d
|
||||
|
||||
# services: a list of entries to **enable**
|
||||
# disable: a list of entries to **disable**
|
||||
#
|
||||
# Each entry has three fields:
|
||||
# - name: the service name
|
||||
# - (optional) mandatory: if set to true, a failure to modify
|
||||
# the service will result in installation failure, rather than just
|
||||
# a warning. The default is false.
|
||||
#
|
||||
# an entry may also be a single string, which is interpreted
|
||||
# as the name field.
|
||||
#
|
||||
# # Example services and disable settings:
|
||||
# # - add foo1, but it must succeed
|
||||
# # - add foo2
|
||||
# # - remove foo3
|
||||
# # - remove foo4
|
||||
# services:
|
||||
# - name: foo1
|
||||
# mandatory: true
|
||||
# - name: foo2
|
||||
# disable:
|
||||
# - name: foo3
|
||||
# - foo4
|
||||
services: []
|
||||
disable: []
|
Reference in New Issue
Block a user