calamares/src/modules/machineid/main.py

55 lines
2.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2015-02-18 15:06:10 +01:00
# -*- coding: utf-8 -*-
#
# === This file is part of Calamares - <http://github.com/calamares> ===
#
2015-02-18 16:03:57 +01:00
# Copyright 2014, Kevin Kofler <kevin.kofler@chello.at>
#
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.
#
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.
#
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/>.
import libcalamares
import os
2014-11-27 21:11:56 +01:00
from libcalamares.utils import check_chroot_call
def run():
2015-02-21 10:35:05 +01:00
""" Generate machine-id using dbus and systemd.
2015-02-20 20:54:25 +01:00
:return:
"""
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
enable_systemd = libcalamares.job.configuration["systemd"]
enable_dbus = libcalamares.job.configuration["dbus"]
enable_symlink = libcalamares.job.configuration["symlink"]
target_systemd_machineid_file = "{}/etc/machine-id".format(root_mount_point)
2015-06-14 13:04:52 +02:00
if enable_systemd:
if os.path.exists(target_systemd_machineid_file):
os.remove(target_systemd_machineid_file)
2015-06-14 13:04:52 +02:00
check_chroot_call("systemd-machine-id-setup")
2015-06-14 13:04:52 +02:00
if enable_dbus:
target_dbus_machineid_file = "{}/var/lib/dbus/machine-id".format(root_mount_point)
2015-06-14 13:04:52 +02:00
if os.path.exists(target_dbus_machineid_file):
os.remove(target_dbus_machineid_file)
2015-06-14 13:04:52 +02:00
if enable_symlink and os.path.exists(target_systemd_machineid_file):
check_chroot_call(["ln", "-s", "/etc/machine-id", "/var/lib/dbus/machine-id"])
else:
check_chroot_call(["dbus-uuidgen", "--ensure"])
2015-06-14 13:04:52 +02:00
return None