From 29392f24ee02f7b71933cd070b0f516eb34decaf Mon Sep 17 00:00:00 2001 From: Philip Date: Sat, 10 Sep 2016 14:17:04 +0200 Subject: [PATCH] [mhwdcfg] replace hardwarecfg --- settings.conf | 2 +- src/modules/mhwdcfg/main.py | 98 ++++++++++++++++++++++++++++++++ src/modules/mhwdcfg/mhwdcfg.conf | 17 ++++++ src/modules/mhwdcfg/module.desc | 6 ++ 4 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 src/modules/mhwdcfg/main.py create mode 100644 src/modules/mhwdcfg/mhwdcfg.conf create mode 100644 src/modules/mhwdcfg/module.desc diff --git a/settings.conf b/settings.conf index e12434026..0b0bd7238 100644 --- a/settings.conf +++ b/settings.conf @@ -81,7 +81,7 @@ sequence: - initcpio - users - displaymanager - - hardwarecfg + - mhwdcfg - networkcfg - hwclock - services diff --git a/src/modules/mhwdcfg/main.py b/src/modules/mhwdcfg/main.py new file mode 100644 index 000000000..95ed66c97 --- /dev/null +++ b/src/modules/mhwdcfg/main.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# === This file is part of Calamares - === +# +# Copyright 2016, Artoo +# +# 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 libcalamares + +from libcalamares.utils import check_target_env_call, target_env_call, debug +from os.path import join +from subprocess import check_call, call + +class MhwdController: + def __init__(self): + self.__root = libcalamares.globalstorage.value( "rootMountPoint" ) + self.__bus = libcalamares.job.configuration.get('bus', []) + self.__identifier = libcalamares.job.configuration.get('identifier', []) + self.__local = libcalamares.job.configuration['local'] + self.__repo = libcalamares.job.configuration['repo'] + self._driver = libcalamares.job.configuration['driver'] + + @property + def driver(self): + return self._driver + + @driver.setter + def driver(self, value): + self._driver = value + + @property + def root(self): + return self.__root + + @property + def local(self): + return self.__local + + @property + def repo(self): + return self.__repo + + @property + def identifier(self): + return self.__identifier + + @property + def bus(self): + return self.__bus + + def umount(self, mp): + call(["umount", "-l", join(self.root, mp)]) + + def mount(self, mp): + call(["mount", "-Br", "/" + mp, join(self.root, mp)]) + + def configure(self, name, id): + cmd = ["mhwd", "-a", str(name), str(self.driver), str(id).zfill(4)] + if self.local: + self.mount("opt") + cmd.extend(["--pmconfig", self.repo]) + + self.mount("etc/resolv.conf") + check_target_env_call(cmd) + + if self.local: + self.umount("opt") + self.umount("etc/resolv.conf") + + def run(self): + for id in self.identifier['net']: + for b in self.bus: + self.configure(b, id) + for id in self.identifier['video']: + for b in self.bus: + self.configure(b, id) + + return None + +def run(): + """ Configure the hardware """ + + mhwd = MhwdController() + + return mhwd.run() diff --git a/src/modules/mhwdcfg/mhwdcfg.conf b/src/modules/mhwdcfg/mhwdcfg.conf new file mode 100644 index 000000000..a4752f720 --- /dev/null +++ b/src/modules/mhwdcfg/mhwdcfg.conf @@ -0,0 +1,17 @@ +--- +identifier: + net: + - 200 + - 280 + video: + - 300 + +bus: + - pci + - usb + +driver: free + +local: true + +repo: /opt/pacman-mhwd.conf diff --git a/src/modules/mhwdcfg/module.desc b/src/modules/mhwdcfg/module.desc new file mode 100644 index 000000000..1e719bb0b --- /dev/null +++ b/src/modules/mhwdcfg/module.desc @@ -0,0 +1,6 @@ +# Syntax is YAML 1.2 +--- +type: "job" +name: "mhwdcfg" +interface: "python" +script: "main.py" #assumed relative to the current directory