2014-11-27 21:08:50 +01: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-11-27 21:08:50 +01:00
|
|
|
#
|
2015-02-18 16:03:57 +01:00
|
|
|
# Copyright 2014, Kevin Kofler <kevin.kofler@chello.at>
|
2016-07-28 01:28:53 +02:00
|
|
|
# Copyright 2016, Philip Müller <philm@manjaro.org>
|
2017-03-20 23:03:41 +01:00
|
|
|
# Copyright 2017, Alf Gaida <agaida@siduction.org>
|
2019-02-14 12:36:17 +01:00
|
|
|
# Copyright 2019, Adriaan de Groot <groot@kde.org>
|
2014-11-27 21:08:50 +01:00
|
|
|
#
|
2015-02-18 16:03:57 +01: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.
|
2014-11-27 21:08:50 +01:00
|
|
|
#
|
2015-02-18 16:03:57 +01:00
|
|
|
# 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.
|
2014-11-27 21:08:50 +01:00
|
|
|
#
|
2015-02-18 16:03:57 +01:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
2014-11-27 21:08:50 +01:00
|
|
|
|
|
|
|
import libcalamares
|
|
|
|
import os
|
2017-08-09 11:08:35 +02:00
|
|
|
from libcalamares.utils import check_target_env_call, debug
|
2014-11-27 21:08:50 +01:00
|
|
|
|
2017-08-09 11:08:35 +02:00
|
|
|
import gettext
|
2017-08-15 14:10:56 +02:00
|
|
|
_ = gettext.translation("calamares-python",
|
2017-08-18 20:19:50 +02:00
|
|
|
localedir=libcalamares.utils.gettext_path(),
|
2017-08-15 14:10:56 +02:00
|
|
|
languages=libcalamares.utils.gettext_languages(),
|
|
|
|
fallback=True).gettext
|
2017-08-09 11:08:35 +02:00
|
|
|
|
2017-08-15 11:39:58 +02:00
|
|
|
|
2017-08-09 11:08:35 +02:00
|
|
|
def pretty_name():
|
|
|
|
return _("Generate machine-id.")
|
2014-11-27 21:08:50 +01:00
|
|
|
|
2017-08-15 11:39:58 +02:00
|
|
|
|
2014-11-27 21:08:50 +01:00
|
|
|
def run():
|
2017-03-20 23:03:41 +01:00
|
|
|
"""
|
|
|
|
Generate machine-id using dbus and systemd.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:return:
|
|
|
|
"""
|
2014-11-27 21:08:50 +01:00
|
|
|
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
|
2019-04-28 15:33:20 +02:00
|
|
|
|
|
|
|
if root_mount_point is None:
|
|
|
|
libcalamares.utils.warning("rootMountPoint is empty, {!s}".format(root_mount_point))
|
|
|
|
return (_("Configuration Error"),
|
|
|
|
_("No root mount point is given for <pre>{!s}</pre> to use." ).format("machineid"))
|
|
|
|
|
2014-11-27 21:08:50 +01:00
|
|
|
enable_systemd = libcalamares.job.configuration["systemd"]
|
|
|
|
enable_dbus = libcalamares.job.configuration["dbus"]
|
|
|
|
enable_symlink = libcalamares.job.configuration["symlink"]
|
2017-03-20 23:03:41 +01:00
|
|
|
target_systemd_machineid_file = root_mount_point + "/etc/machine-id"
|
|
|
|
target_dbus_machineid_file = root_mount_point + "/var/lib/dbus/machine-id"
|
2015-06-14 13:04:52 +02:00
|
|
|
|
2016-07-28 02:37:51 +02:00
|
|
|
if os.path.exists(target_dbus_machineid_file):
|
|
|
|
os.remove(target_dbus_machineid_file)
|
2015-06-14 13:04:52 +02:00
|
|
|
|
2016-07-28 01:27:41 +02:00
|
|
|
if enable_systemd:
|
2016-07-28 02:00:47 +02:00
|
|
|
if os.path.exists(target_systemd_machineid_file):
|
|
|
|
os.remove(target_systemd_machineid_file)
|
2015-08-06 12:13:21 +02:00
|
|
|
check_target_env_call("systemd-machine-id-setup")
|
2015-06-14 13:04:52 +02:00
|
|
|
|
2014-11-27 21:08:50 +01:00
|
|
|
if enable_dbus:
|
|
|
|
if enable_symlink and os.path.exists(target_systemd_machineid_file):
|
2017-03-20 23:03:41 +01:00
|
|
|
check_target_env_call(["ln", "-s", "/etc/machine-id",
|
|
|
|
"/var/lib/dbus/machine-id"])
|
2014-11-27 21:08:50 +01:00
|
|
|
else:
|
2015-08-06 12:13:21 +02:00
|
|
|
check_target_env_call(["dbus-uuidgen", "--ensure"])
|
2015-06-14 13:04:52 +02:00
|
|
|
|
2014-11-27 21:08:50 +01:00
|
|
|
return None
|