source: calamares/trunk/fuentes/src/modules/machineid/main.py @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 2.4 KB
Line 
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# === This file is part of Calamares - <https://github.com/calamares> ===
5#
6#   Copyright 2014, Kevin Kofler <kevin.kofler@chello.at>
7#   Copyright 2016, Philip Müller <philm@manjaro.org>
8#   Copyright 2017, Alf Gaida <agaida@siduction.org>
9#
10#   Calamares is free software: you can redistribute it and/or modify
11#   it under the terms of the GNU General Public License as published by
12#   the Free Software Foundation, either version 3 of the License, or
13#   (at your option) any later version.
14#
15#   Calamares is distributed in the hope that it will be useful,
16#   but WITHOUT ANY WARRANTY; without even the implied warranty of
17#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18#   GNU General Public License for more details.
19#
20#   You should have received a copy of the GNU General Public License
21#   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
22
23import libcalamares
24import os
25from libcalamares.utils import check_target_env_call, debug
26
27import gettext
28_ = gettext.translation("calamares-python",
29                        localedir=libcalamares.utils.gettext_path(),
30                        languages=libcalamares.utils.gettext_languages(),
31                        fallback=True).gettext
32
33
34def pretty_name():
35    return _("Generate machine-id.")
36
37
38def run():
39    """
40    Generate machine-id using dbus and systemd.
41
42    :return:
43    """
44    root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
45    enable_systemd = libcalamares.job.configuration["systemd"]
46    enable_dbus = libcalamares.job.configuration["dbus"]
47    enable_symlink = libcalamares.job.configuration["symlink"]
48    target_systemd_machineid_file = root_mount_point + "/etc/machine-id"
49    target_dbus_machineid_file = root_mount_point + "/var/lib/dbus/machine-id"
50
51    if os.path.exists(target_dbus_machineid_file):
52        os.remove(target_dbus_machineid_file)
53
54    if enable_systemd:
55        if os.path.exists(target_systemd_machineid_file):
56            os.remove(target_systemd_machineid_file)
57        check_target_env_call("systemd-machine-id-setup")
58
59    if enable_dbus:
60        if enable_symlink and os.path.exists(target_systemd_machineid_file):
61            check_target_env_call(["ln", "-s", "/etc/machine-id",
62                                   "/var/lib/dbus/machine-id"])
63        else:
64            check_target_env_call(["dbus-uuidgen", "--ensure"])
65
66    return None
Note: See TracBrowser for help on using the repository browser.