source: calamares/trunk/fuentes/src/modules/networkcfg/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.8 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, Philip Müller <philm@manjaro.org>
7#   Copyright 2014, Teo Mrnjavac <teo@kde.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 os
24import shutil
25
26import libcalamares
27
28
29def run():
30    """
31    Setup network configuration
32    """
33
34    root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
35    source_nm = "/etc/NetworkManager/system-connections/"
36    target_nm = os.path.join(
37        root_mount_point, "etc/NetworkManager/system-connections/"
38        )
39
40    # Sanity checks.  We don't want to do anything if a network
41    # configuration already exists on the target
42    if os.path.exists(source_nm) and os.path.exists(target_nm):
43        for network in os.listdir(source_nm):
44            # Skip LTSP live
45            if network == "LTSP":
46                continue
47
48            source_network = os.path.join(source_nm, network)
49            target_network = os.path.join(target_nm, network)
50
51            if os.path.exists(target_network):
52                continue
53
54            try:
55                shutil.copy(source_network, target_network)
56            except FileNotFoundError:
57                libcalamares.utils.debug(
58                    "Can't copy network configuration files in "
59                    + "{}".format(source_network)
60                    )
61            except FileExistsError:
62                pass
63
64    # We need to overwrite the default resolv.conf in the chroot.
65    source_resolv = "/etc/resolv.conf"
66    target_resolv = os.path.join(root_mount_point, "etc/resolv.conf")
67    if source_resolv != target_resolv and os.path.exists(source_resolv):
68        try:
69            os.remove(target_resolv)
70        except Exception as err:
71            libcalamares.utils.debug(
72                "Couldn't remove {}: {}".format(target_resolv, err)
73                )
74
75        try:
76            shutil.copy(source_resolv, target_resolv)
77        except Exception as err:
78            libcalamares.utils.debug(
79                "Can't copy resolv.conf from {}: {}".format(source_resolv, err)
80                )
81
82    return None
Note: See TracBrowser for help on using the repository browser.