From 06c99221d2516da7ff50619584ee3411c0c3f50a Mon Sep 17 00:00:00 2001 From: brent s Date: Tue, 10 Dec 2019 06:59:47 -0500 Subject: [PATCH] okay, some minor changes to the XML stuff. getting there --- aif.xsd | 1170 --------------------------------------- aif/network/__init__.py | 43 +- aif/network/main.py | 42 -- aif/system/__init__.py | 17 +- aif/system/console.py | 16 +- aif/system/locales.py | 36 +- aif/system/services.py | 2 +- examples/aif.xml | 21 +- 8 files changed, 103 insertions(+), 1244 deletions(-) delete mode 100644 aif.xsd delete mode 100644 aif/network/main.py diff --git a/aif.xsd b/aif.xsd deleted file mode 100644 index 57bc91e..0000000 --- a/aif.xsd +++ /dev/null @@ -1,1170 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/aif/network/__init__.py b/aif/network/__init__.py index 648f978..24eb646 100644 --- a/aif/network/__init__.py +++ b/aif/network/__init__.py @@ -1,8 +1,9 @@ +import os +## from . import _common from . import netctl from . import networkd from . import networkmanager -from . import main # No longer necessary: # try: @@ -18,3 +19,43 @@ from . import main # from . import networkd # except ImportError: # from . import networkd_fallback as networkd + + +class Net(object): + def __init__(self, chroot_base, network_xml): + self.xml = network_xml + self.chroot_base = chroot_base + self.hostname = self.xml.attrib['hostname'].strip() + self.provider = self.xml.attrib.get('provider', 'networkd').strip() + if self.provider == 'netctl': + self.provider = netctl + elif self.provider == 'nm': + self.provider = networkmanager + elif self.provider == 'networkd': + self.provider = networkd + else: + raise RuntimeError('Could not determine provider') + self.connections = [] + self._initConns() + + def _initConns(self): + for e in self.xml.xpath('ethernet|wireless'): + conn = None + if e.tag == 'ethernet': + conn = self.provider.Ethernet(e) + elif e.tag == 'wireless': + conn = self.provider.Wireless(e) + self.connections.append(conn) + + def apply(self, chroot_base): + cfg = os.path.join(chroot_base, 'etc', 'hostname') + with open(cfg, 'w') as fh: + fh.write('{0}\n'.format(self.hostname)) + os.chown(cfg, 0, 0) + os.chmod(cfg, 0o0644) + for iface in self.connections: + for src, dest in iface.services.items(): + realdest = os.path.join(chroot_base, dest) + os.symlink(src, realdest) + iface.writeConf(chroot_base) + return () diff --git a/aif/network/main.py b/aif/network/main.py deleted file mode 100644 index 937bf40..0000000 --- a/aif/network/main.py +++ /dev/null @@ -1,42 +0,0 @@ -import os - - -class Network(object): - def __init__(self, network_xml): - self.xml = network_xml - self.hostname = self.xml.attrib['hostname'].strip() - self.provider = self.xml.attrib.get('provider', 'networkd').strip() - handler = None - if self.provider == 'netctl': - import aif.network.netctl as handler - elif self.provider == 'nm': - import aif.network.networkmanager as handler - elif self.provider == 'networkd': - import aif.network.networkd as handler - self.provider = handler - if not self.provider: - raise RuntimeError('Could not determine handler') - self.connections = [] - self._initConns() - - def _initConns(self): - for e in self.xml.xpath('ethernet|wireless'): - conn = None - if e.tag == 'ethernet': - conn = self.provider.Ethernet(e) - elif e.tag == 'wireless': - conn = self.provider.Wireless(e) - self.connections.append(conn) - - def apply(self, chroot_base): - cfg = os.path.join(chroot_base, 'etc', 'hostname') - with open(cfg, 'w') as fh: - fh.write('{0}\n'.format(self.hostname)) - os.chown(cfg, 0, 0) - os.chmod(cfg, 0o0644) - for iface in self.connections: - for src, dest in iface.services.items(): - realdest = os.path.join(chroot_base, dest) - os.symlink(src, realdest) - iface.writeConf(chroot_base) - return() diff --git a/aif/system/__init__.py b/aif/system/__init__.py index 0a0bb0a..6f339b1 100644 --- a/aif/system/__init__.py +++ b/aif/system/__init__.py @@ -4,5 +4,18 @@ from . import users from . import services -def main(system_xml): - pass +class Sys(object): + def __init__(self, chroot_base, system_xml): + self.xml = system_xml + self.chroot_base = chroot_base + self.locale = locales.Locale(self.chroot_base, self.xml.find('locales')) + self.tz = locales.Timezone(self.chroot_base, self.xml.attrib.get('timezone', 'UTC')) + self.user = users.UserDB(self.chroot_base, self.xml.find('rootPassword'), self.xml.find('users')) + self.services = services.ServiceDB(self.chroot_base, self.xml.find('services')) + + def apply(self): + self.locale.writeConf() + self.tz.apply() + self.user.writeConf() + self.services.apply() + return() diff --git a/aif/system/console.py b/aif/system/console.py index 56175a2..7cc5774 100644 --- a/aif/system/console.py +++ b/aif/system/console.py @@ -34,8 +34,9 @@ class Font(object): class Keyboard(object): - def __init__(self, keyboard_xml): + def __init__(self, chroot_base, keyboard_xml): self.xml = keyboard_xml + self.chroot_base = chroot_base self.settings = {} if self.xml: chk = {'KEYMAP': self.xml.find('map'), @@ -44,14 +45,14 @@ class Keyboard(object): if xml: self.settings[setting] = xml.text.strip() - def verify(self, chroot_base): + def verify(self): kbdnames = [] for i in ('KEYMAP', 'KEYMAP_TOGGLE'): if i in self.settings.keys(): kbdnames.append(self.settings[i]) if not kbdnames: return(None) - keymapdir = os.path.join(chroot_base, 'usr', 'share', 'kbd', 'keymaps') + keymapdir = os.path.join(self.chroot_base, 'usr', 'share', 'kbd', 'keymaps') kbdmaps = [] for root, dirs, files in os.walk(keymapdir, topdown = True): if root.endswith('/include'): @@ -69,8 +70,9 @@ class Keyboard(object): class Console(object): - def __init__(self, console_xml): + def __init__(self, chroot_base, console_xml): self.xml = console_xml + self.chroot_base = chroot_base self._cfg = configparser.ConfigParser() self._cfg.optionxform(str) self.keyboard = Keyboard(self.xml.find('keyboard')) @@ -79,10 +81,10 @@ class Console(object): for i in (self.keyboard, self.font): self._cfg['BASE'].update(i.settings) - def writeConf(self, chroot_base): + def writeConf(self): for x in (self.font, self.keyboard): - x.verify(chroot_base) - cfg = os.path.join(chroot_base, 'etc', 'vconsole.conf') + x.verify() + cfg = os.path.join(self.chroot_base, 'etc', 'vconsole.conf') # We have to strip out the section from the ini. cfgbuf = io.StringIO() self._cfg.write(cfgbuf, space_around_delimiters = False) diff --git a/aif/system/locales.py b/aif/system/locales.py index 9cc424e..41fcad0 100644 --- a/aif/system/locales.py +++ b/aif/system/locales.py @@ -11,8 +11,9 @@ _locale_def_re = re.compile(r'([^.]*)[^@]*(.*)') class Locale(object): - def __init__(self, locales_xml): + def __init__(self, chroot_base, locales_xml): self.xml = locales_xml + self.chroot_base = chroot_base self.syslocales = {} self.userlocales = [] self.rawlocales = None @@ -31,8 +32,8 @@ class Locale(object): self.userlocales = ['en_US', 'en_US.UTF-8'] return() - def _verify(self, chroot_base): - localegen = os.path.join(chroot_base, 'etc', 'locale.gen') # This *should* be brand new. + def _verify(self): + localegen = os.path.join(self.chroot_base, 'etc', 'locale.gen') # This *should* be brand new. with open(localegen, 'r') as fh: self.rawlocales = fh.read().splitlines() for idx, line in enumerate(self.rawlocales[:]): @@ -50,12 +51,12 @@ class Locale(object): raise ValueError('non-existent locale specified') return() - def writeConf(self, chroot_base): + def writeConf(self): # We basically recreate locale-gen in python here, more or less. - self._verify(chroot_base) - localegen = os.path.join(chroot_base, 'etc', 'locale.gen') - localedbdir = os.path.join(chroot_base, 'usr', 'lib', 'locale') - localesrcdir = os.path.join(chroot_base, 'usr', 'share', 'i18n') + self._verify() + localegen = os.path.join(self.chroot_base, 'etc', 'locale.gen') + localedbdir = os.path.join(self.chroot_base, 'usr', 'lib', 'locale') + localesrcdir = os.path.join(self.chroot_base, 'usr', 'share', 'i18n') with open(localegen, 'w') as fh: fh.write('# Generated by AIF-NG.\n\n') fh.write('\n'.join(self.rawlocales)) @@ -86,12 +87,12 @@ class Locale(object): # '--charmap={0}'.format(os.path.join(localesrcdir, 'charmaps', charset)), '--inputfile={0}'.format(ldef_name), '--charmap={0}'.format(charset), - '--alias-file={0}'.format(os.path.join(chroot_base, + '--alias-file={0}'.format(os.path.join(self.chroot_base, 'usr', 'share', 'locale', 'locale.alias')), - '--prefix={0}'.format(chroot_base), + '--prefix={0}'.format(self.chroot_base), locale], env = env) - cfg = os.path.join(chroot_base, 'etc', 'locale.conf') + cfg = os.path.join(self.chroot_base, 'etc', 'locale.conf') # And now we write the variables. # We have to strip out the section from the ini. cfgbuf = io.StringIO() @@ -108,19 +109,20 @@ class Locale(object): class Timezone(object): - def __init__(self, timezone): + def __init__(self, chroot_base, timezone): self.tz = timezone.strip().replace('.', '/') + self.chroot_base = chroot_base - def _verify(self, chroot_base): + def _verify(self): tzfilebase = os.path.join('usr', 'share', 'zoneinfo', self.tz) - tzfile = os.path.join(chroot_base, tzfilebase) + tzfile = os.path.join(self.chroot_base, tzfilebase) if not os.path.isfile(tzfile): raise ValueError('Invalid timezone') return(tzfilebase) - def apply(self, chroot_base): - tzsrcfile = os.path.join('/', self._verify(chroot_base)) - tzdestfile = os.path.join(chroot_base, 'etc', 'localtime') + def apply(self): + tzsrcfile = os.path.join('/', self._verify()) + tzdestfile = os.path.join(self.chroot_base, 'etc', 'localtime') if os.path.isfile(tzdestfile): os.remove(tzdestfile) os.symlink(tzsrcfile, tzdestfile) diff --git a/aif/system/services.py b/aif/system/services.py index 6cd3f64..26a9032 100644 --- a/aif/system/services.py +++ b/aif/system/services.py @@ -37,7 +37,7 @@ class Service(object): class ServiceDB(object): - def __init__(self, services_xml, chroot_base): + def __init__(self, chroot_base, services_xml): self.xml = services_xml self.chroot_base = chroot_base self.systemd_sys = os.path.join(self.chroot_base, 'usr', 'lib', 'systemd', 'system') diff --git a/examples/aif.xml b/examples/aif.xml index 85e7844..4b73f64 100644 --- a/examples/aif.xml +++ b/examples/aif.xml @@ -1,10 +1,23 @@ + reboot="false"> + + https://arch.mirror.square-r00t.net/iso/latest/archlinux-bootstrap-2019.12.01-x86_64.tar.gz + + + + https://arch.mirror.square-r00t.net/iso/latest/archlinux-bootstrap-2019.12.01-x86_64.tar.gz.sig + + + + http://arch.mirror.square-r00t.net/iso/latest/md5sums.txt + http://arch.mirror.square-r00t.net/iso/latest/sha1sums.txt + + +