From 1b54ec1039aba479bbb66cc5afd0cc436b663332 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 11 Aug 2014 16:30:01 +0200 Subject: [PATCH] New networkcfg module, based on Thus. --- src/modules/networkcfg/main.py | 57 ++++++++++++++++++++++++++++++ src/modules/networkcfg/module.desc | 6 ++++ 2 files changed, 63 insertions(+) create mode 100644 src/modules/networkcfg/main.py create mode 100644 src/modules/networkcfg/module.desc diff --git a/src/modules/networkcfg/main.py b/src/modules/networkcfg/main.py new file mode 100644 index 000000000..f064542de --- /dev/null +++ b/src/modules/networkcfg/main.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# encoding: utf-8 +# === This file is part of Calamares - === +# +# Copyright 2014, Philip Müller +# Copyright 2014, Teo Mrnjavac +# +# 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 . + +import os +import shutil + +import libcalamares + + +def run(): + """ Setup network configuration """ + + root_mount_point = libcalamares.globalstorage.value("rootMountPoint") + source_nm = "/etc/NetworkManager/system-connections/" + target_nm = os.path.join(root_mount_point, + "etc/NetworkManager/system-connections/") + + # Sanity checks. We don't want to do anything if a network + # configuration already exists on the target + if os.path.exists(source_nm) and os.path.exists(target_nm): + for network in os.listdir(source_nm): + # Skip LTSP live + if network == "LTSP": + continue + + source_network = os.path.join(source_nm, network) + target_network = os.path.join(target_nm, network) + + if os.path.exists(target_network): + continue + + try: + shutil.copy(source_network, target_network) + except FileNotFoundError: + libcalamares.utils.debug( + "Can't copy network configuration files in {}".format(source_network)) + except FileExistsError: + pass + + return None diff --git a/src/modules/networkcfg/module.desc b/src/modules/networkcfg/module.desc new file mode 100644 index 000000000..2377972b8 --- /dev/null +++ b/src/modules/networkcfg/module.desc @@ -0,0 +1,6 @@ +--- +type: "job" +name: "networkcfg" +interface: "python" +requires: [] +script: "main.py"