2014-08-11 15:13:28 +02:00
|
|
|
#!/usr/bin/env python3
|
2015-02-18 15:06:10 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2017-12-20 14:39:09 +01:00
|
|
|
# === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-08-11 15:13:28 +02:00
|
|
|
#
|
|
|
|
# Copyright 2014, Philip Müller <philm@manjaro.org>
|
|
|
|
# Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
2017-03-29 21:47:15 +02:00
|
|
|
# Copyright 2017, Alf Gaida <agaida@siduction.org>
|
2014-08-11 15:13:28 +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
|
|
|
|
|
|
|
|
|
|
|
|
def run():
|
2017-03-29 21:47:15 +02:00
|
|
|
"""
|
|
|
|
Setup systemd services
|
|
|
|
"""
|
2014-08-11 15:13:28 +02:00
|
|
|
services = libcalamares.job.configuration['services']
|
|
|
|
targets = libcalamares.job.configuration['targets']
|
2015-08-31 14:28:51 +02:00
|
|
|
disable = libcalamares.job.configuration['disable']
|
2014-08-11 15:13:28 +02:00
|
|
|
|
2016-01-15 02:28:57 +01:00
|
|
|
# note that the "systemctl enable" and "systemctl disable" commands used
|
|
|
|
# here will work in a chroot; in fact, they are the only systemctl commands
|
|
|
|
# that support that, see:
|
|
|
|
# http://0pointer.de/blog/projects/changing-roots.html
|
|
|
|
|
2014-08-11 15:13:28 +02:00
|
|
|
# enable services
|
|
|
|
for svc in services:
|
2017-03-29 21:47:15 +02:00
|
|
|
ec = libcalamares.utils.target_env_call(
|
|
|
|
['systemctl', 'enable', '{}.service'.format(svc['name'])]
|
|
|
|
)
|
2015-06-14 13:25:37 +02:00
|
|
|
|
2014-08-11 15:13:28 +02:00
|
|
|
if ec != 0:
|
|
|
|
if svc['mandatory']:
|
2017-03-29 21:47:15 +02:00
|
|
|
return ("Cannot enable systemd service {}".format(svc['name']),
|
|
|
|
"systemctl enable call in chroot returned error code "
|
|
|
|
"{}".format(ec)
|
|
|
|
)
|
2014-08-11 15:13:28 +02:00
|
|
|
else:
|
2017-03-29 21:47:15 +02:00
|
|
|
libcalamares.utils.debug(
|
|
|
|
"Cannot enable systemd service {}".format(svc['name'])
|
|
|
|
)
|
|
|
|
libcalamares.utils.debug(
|
|
|
|
"systemctl enable call in chroot returned error code "
|
|
|
|
"{}".format(ec)
|
|
|
|
)
|
2014-08-11 15:13:28 +02:00
|
|
|
|
|
|
|
# enable targets
|
|
|
|
for tgt in targets:
|
2017-03-29 21:47:15 +02:00
|
|
|
ec = libcalamares.utils.target_env_call(
|
|
|
|
['systemctl', 'enable', '{}.target'.format(tgt['name'])]
|
|
|
|
)
|
2015-06-14 13:25:37 +02:00
|
|
|
|
2014-08-11 15:13:28 +02:00
|
|
|
if ec != 0:
|
|
|
|
if tgt['mandatory']:
|
2017-03-29 21:47:15 +02:00
|
|
|
return ("Cannot enable systemd target {}".format(tgt['name']),
|
|
|
|
"systemctl enable call in chroot returned error code"
|
|
|
|
"{}".format(ec)
|
|
|
|
)
|
2014-08-11 15:13:28 +02:00
|
|
|
else:
|
2017-03-29 21:47:15 +02:00
|
|
|
libcalamares.utils.debug(
|
|
|
|
"Cannot enable systemd target {}".format(tgt['name'])
|
|
|
|
)
|
|
|
|
libcalamares.utils.debug(
|
|
|
|
"systemctl enable call in chroot returned error code "
|
|
|
|
"{}".format(ec)
|
|
|
|
)
|
2014-08-11 15:13:28 +02:00
|
|
|
|
2015-08-31 14:28:51 +02:00
|
|
|
for dbl in disable:
|
2017-03-29 21:47:15 +02:00
|
|
|
ec = libcalamares.utils.target_env_call(
|
|
|
|
['systemctl', 'disable', '{}.service'.format(dbl['name'])]
|
|
|
|
)
|
2015-08-31 14:28:51 +02:00
|
|
|
|
|
|
|
if ec != 0:
|
|
|
|
if dbl['mandatory']:
|
2017-03-29 21:47:15 +02:00
|
|
|
return ("Cannot disable systemd service"
|
|
|
|
"{}".format(dbl['name']),
|
|
|
|
"systemctl disable call in chroot returned error code"
|
|
|
|
"{}".format(ec))
|
2015-08-31 14:28:51 +02:00
|
|
|
else:
|
2017-03-29 21:47:15 +02:00
|
|
|
libcalamares.utils.debug(
|
|
|
|
"Cannot disable systemd service {}".format(dbl['name'])
|
|
|
|
)
|
|
|
|
libcalamares.utils.debug(
|
|
|
|
"systemctl disable call in chroot returned error code "
|
|
|
|
"{}".format(ec)
|
|
|
|
)
|
2015-08-31 14:28:51 +02:00
|
|
|
|
2014-08-11 15:13:28 +02:00
|
|
|
return None
|