source: ogLive-Builder-Git/chroot-tasks.py @ 86a5c81

filebeat-installer
Last change on this file since 86a5c81 was 86a5c81, checked in by lgromero <lgromero@…>, 8 days ago

refs #1719 adds filebeat installation and includes filebeat configuration and certs

  • Property mode set to 100755
File size: 6.9 KB
RevLine 
[cc5701c]1#!/usr/bin/python3
2
3import argparse
[feae768]4import shutil
[cc5701c]5import os
[feae768]6import glob
[a193b67]7import sys
[ec2ab82]8import re
[cc5701c]9import subprocess
10
[d1822ec]11from boottools import utils, apt
[ec2ab82]12
[cc5701c]13def _oghook_deactivate():
14    #Desactivamos el hook del oginitrd.img para evitar problemas, al final de este escripts se activará
[ec2ab82]15    os.rename ('/etc/initramfs-tools/hooks/oghooks', '/etc/initramfs-tools/oghooks')
[cc5701c]16
17def _oghook_activate():
18    #Activamos el hook del oginitrd.img
[ec2ab82]19    os.rename ('/etc/initramfs-tools/oghooks', '/etc/initramfs-tools/hooks/oghooks')
[cc5701c]20
21def boottoolsSoftwareInstall (osarch, osrelease):
22    os.environ['LANGUAGE'] = 'C'
23    os.environ['LC_ALL'] = 'C'
24    os.environ['LANG'] = 'C'
25    os.environ['DEBIAN_FRONTEND'] = 'noninteractive'
26
[95a24ac]27    stdout, _ = utils.run (['dpkg-divert', '--list'])
[ec2ab82]28    if not re.findall (r'local diversion of /sbin/initctl to /sbin/initctl.distrib', stdout):
[95a24ac]29        utils.run (['dpkg-divert', '--local', '--rename', '--add', '/sbin/initctl'])
[ec2ab82]30        os.symlink ('/bin/true', '/sbin/initctl')
[cc5701c]31
32    pkgs32 = []
33    if 'i386' != osarch:
[95a24ac]34        utils.run (['dpkg', '--add-architecture', 'i386'])
[68c5a27]35        pkgs32 = 'lib32gcc-s1 lib32stdc++6 lib32z1 libc6-i386'.split (' ')
[cc5701c]36
37    _oghook_deactivate()
[ec2ab82]38
[c79d715]39    print ('boottoolsSoftwareInstall: debconf-set-selections', file=sys.stderr)
[ec2ab82]40    subprocess.run (['debconf-set-selections'], input=debconf_settings, text=True)
[0ab0e61]41    utils.run (['dpkg-reconfigure', '--frontend', 'noninteractive', 'console-setup', 'locales'])   ## XXX: despues de esto, debconf-get-selections devuelve los valores antiguos, no se por que...
[cc5701c]42
[48528a4]43    pkgs = glob.glob ('/tmp/opengnsys/oglive_builder/ogagent_*.deb') + glob.glob ('/tmp/opengnsys/oglive_builder/OGBrowser*.deb')
[3fffd21]44    for section in config.options('Packages'):
45        pkgs += re.split (r'[ \n]', config['Packages'].get(section).strip())
[53310a8]46
[68c5a27]47    apt.update()
48    apt.upgrade()
49
[86a5c81]50    pkgs = [f'linux-image-{osrelease}', f'linux-headers-{osrelease}', f'linux-modules-{osrelease}', f'linux-modules-extra-{osrelease}', 'dkms', 'shim-signed', 'openssl', 'sshfs', 'kexec-tools', 'filebeat'] + pkgs32 + pkgs
[c79d715]51    print (f'boottoolsSoftwareInstall: installing packages: {str(pkgs)}', file=sys.stderr)
[0ab0e61]52    apt.install (pkgs, opts={'DPkg::Options::': '--force-confdef'})         ## --force-confdef is required to avoid an interactive question regarding /etc/ssh/ssh_config
[cc5701c]53
54    # Instalar módulos que algunos paquetes puedan tener pendientes de compilar.
[c79d715]55    print ('boottoolsSoftwareInstall: dkms', file=sys.stderr)
[95a24ac]56    stdout, _ = utils.run (['dkms', 'status'])
[2a2da12]57    for l in stdout.strip().split ('\n'):
58        if not l: continue
[c79d715]59        #print (f'l "{l}"')
[2a2da12]60        mod, vers, status = l.split (',')
61        if 'added' in status:
[c5e9f68]62            print (f'dkms installing {mod} {vers}')
[95a24ac]63            utils.run (['dkms', 'install', '-m', mod.strip(), '-v', vers.strip()])
[cc5701c]64
65    _oghook_activate()
[9a6fecf]66    apt.clean()
67    apt.autoremove()
[cc5701c]68
[feae768]69def boottoolsSoftwareCompile():
[53310a8]70    env_language = os.environ['LANGUAGE']
71    env_lc_all   = os.environ['LC_ALL']
72    env_lang     = os.environ['LANG']
[feae768]73    os.environ['LANGUAGE'] = os.environ['LC_ALL'] = os.environ['LANG'] = 'C'
74    os.chdir ('/tmp')
75
[c79d715]76    print ('boottoolsSoftwareCompile: ms-sys', file=sys.stderr)
[feae768]77    try: utils.run (['which', 'ms-sys'])
78    except:
[d4564f6]79        utils.run (['wget', '--quiet', 'https://sourceforge.net/projects/ms-sys/files/latest/download', '-O', 'ms-sys.tar.gz'])
[feae768]80        utils.run (['tar', '-xpzf', 'ms-sys.tar.gz'])
81        mssys_dir = subprocess.run (['tar tzf ms-sys.tar.gz |head -n 1'], shell=True, capture_output=True, text=True).stdout.strip()
82        print (f'mssys_dir "{mssys_dir}"')
83        os.chdir (mssys_dir)
84        utils.run (['make', 'install'])
85        os.chdir ('..')
86
[c79d715]87    print ('boottoolsSoftwareCompile: spartlnx', file=sys.stderr)
[feae768]88    try: utils.run (['which', 'spartl64.run'])
89    except:
[d4564f6]90        utils.run (['wget', '--quiet', 'http://damien.guibouret.free.fr/savepart.zip'])
[68c5a27]91        utils.run (['unzip', '-o', 'savepart.zip', '-d', '/sbin/', 'spartl64.run', 'spartlnx.run'])
[feae768]92        utils.run (['mkdir', '/usr/share/doc/spartlnx'])
93        utils.run (['unzip', '-j', '-o', 'savepart.zip', '-d', '/usr/share/doc/spartlnx/', 'doc/en/*'])
94
95    if not os.path.exists ('python-libfdisk'):
[c79d715]96        print ('boottoolsSoftwareCompile: python-libfdisk', file=sys.stderr)
[feae768]97        apt.install (['python3-psutil', 'python3-dev', 'libfdisk-dev', 'python3-setuptools'])
[149d3ff]98        utils.run (['git', 'clone', 'https://ognproject.evlt.uma.es/gitea/48k.eu-mirror/python-libfdisk.git'])
[feae768]99        os.chdir ('python-libfdisk')
100        utils.run (['python3', 'setup.py', 'install'])
101        os.chdir ('..')
102
[53310a8]103    os.environ['LANGUAGE'] = env_language
104    os.environ['LC_ALL']   = env_lc_all
105    os.environ['LANG']     = env_lang
[feae768]106
[7b51a04]107def updateCaCertificates():
[419f983]108    print ('Updating CA trust Store', file=sys.stderr)
[7b51a04]109    utils.run (['update-ca-certificates'])
110
[c1a9ff2]111def boottoolsPythonModules():
[865470e]112    utils.run (['pip3', 'install', 'pyblkid', '--break-system-packages'])
[c1a9ff2]113
[7467f99]114def boottoolsRemovePackages():
115    apt.remove (['python3-dev', 'python3-setuptools', 'python3-pip'])
116
[c9fa4ef]117def setup_resolvconf():
118    if os.path.islink('/etc/resolc.conf'):
119        os.unlink ('/etc/resolv.conf')
120    f = open ('/etc/resolv.conf', 'w')
121    f.write ('nameserver 8.8.8.8')
122    f.close()
123
[feae768]124def boottoolsInitrdGenerate (osrelease):
[c79d715]125    print ('boottoolsInitrdGenerate', file=sys.stderr)
[feae768]126    for f in glob.glob ('/usr/lib/initramfs-tools/bin/*'):
127        os.unlink (f)
128    shutil.copy ('/bin/busybox', '/usr/lib/initramfs-tools/bin')
129
[13b086f]130    initrd_img = f'/tmp/initrd.img-{osrelease}'
131
[feae768]132    os.chdir ('/tmp')
[13b086f]133    utils.run (['mkinitramfs', '-o', initrd_img, osrelease])
[feae768]134    shutil.copy (f'/boot/vmlinuz-{osrelease}', '/tmp/')
135
[13b086f]136    ## turn cpio-with-prepended-stuff into a regular cpio, see #975
137    utils.run (['unmkinitramfs', initrd_img, 'undone'])
138    os.mkdir ('undone/merged')
139    subprocess.run (['rsync -aH undone/early/* undone/main/* undone/merged/'], shell=True)
140    shutil.rmtree ('undone/early')
141    shutil.rmtree ('undone/main')
142    os.chdir ('undone/merged/')
143    subprocess.run ([f'find . |cpio -H newc -oa >{initrd_img}'], shell=True)
144    os.chdir ('/tmp')
145    shutil.rmtree ('undone')
146
[7b51a04]147
[cc5701c]148if __name__ == '__main__':
149    parser = argparse.ArgumentParser()
[d4564f6]150    parser.add_argument ('--osarch',    help='OS architecture',            action='store', required=True)
151    parser.add_argument ('--osrelease', help='OS release',                 action='store', required=True)
152    parser.add_argument ('--config',    help='Path to configuration file', action='store')
[cc5701c]153    args = parser.parse_args()
[d4564f6]154
155    config = utils.read_config (args.config or 'mkoglive.cfg')
156    if config is None:
157        sys.exit (1)
158    debconf_settings = config['General'].get ('debconf_settings')
159
[2e8981f]160    updateCaCertificates()
[c9fa4ef]161    setup_resolvconf()
[cc5701c]162    boottoolsSoftwareInstall (args.osarch, args.osrelease)
[feae768]163    boottoolsSoftwareCompile()
[c1a9ff2]164    boottoolsPythonModules()
[7467f99]165    boottoolsRemovePackages()
[1785456]166    setup_resolvconf()    ## do this again, since someone seems to be overwriting the file
[feae768]167    boottoolsInitrdGenerate (args.osrelease)
Note: See TracBrowser for help on using the repository browser.