source: ogLive-Builder-Git/chroot-tasks.py @ 53310a8

browserbuild-browserdeps-vadimfilebeat-installerimprove-versionlgromero-testsmainno-apt-moduleoglive-ipv6pull-from-cloning-enginepybuilder
Last change on this file since 53310a8 was 53310a8, checked in by Natalia Serrano <natalia.serrano@…>, 9 months ago

refs #596 remove debconf_settings2, do chdir first

  • Property mode set to 100755
File size: 5.1 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
[d1822ec]13config = utils.read_config ('mkoglive.cfg')
[e6aa11e]14if config is None:
15    sys.exit (1)
[ef212bc]16debconf_settings = config['General'].get ('debconf_settings')
[ec2ab82]17
[cc5701c]18def _oghook_deactivate():
19    #Desactivamos el hook del oginitrd.img para evitar problemas, al final de este escripts se activará
[ec2ab82]20    os.rename ('/etc/initramfs-tools/hooks/oghooks', '/etc/initramfs-tools/oghooks')
[cc5701c]21
22def _oghook_activate():
23    #Activamos el hook del oginitrd.img
[ec2ab82]24    os.rename ('/etc/initramfs-tools/oghooks', '/etc/initramfs-tools/hooks/oghooks')
[cc5701c]25
26def boottoolsSoftwareInstall (osarch, osrelease):
27    os.environ['LANGUAGE'] = 'C'
28    os.environ['LC_ALL'] = 'C'
29    os.environ['LANG'] = 'C'
30    os.environ['DEBIAN_FRONTEND'] = 'noninteractive'
31
[95a24ac]32    stdout, _ = utils.run (['dpkg-divert', '--list'])
[ec2ab82]33    if not re.findall (r'local diversion of /sbin/initctl to /sbin/initctl.distrib', stdout):
[95a24ac]34        utils.run (['dpkg-divert', '--local', '--rename', '--add', '/sbin/initctl'])
[ec2ab82]35        os.symlink ('/bin/true', '/sbin/initctl')
[cc5701c]36
37    pkgs32 = []
38    if 'i386' != osarch:
[95a24ac]39        utils.run (['dpkg', '--add-architecture', 'i386'])
[ec2ab82]40        pkgs32 = 'lib32gcc-s1 lib32stdc++6 lib32z1 libc6-i386'.split (' ')         ## he cambiado lib32gcc1 por lib32gcc-s1 pero como queramos crear un oglive viejo, esto va a petar
[cc5701c]41
42    _oghook_deactivate()
[ec2ab82]43
44    subprocess.run (['debconf-set-selections'], input=debconf_settings, text=True)
[53310a8]45    utils.run (['dpkg-reconfigure', '--frontend', 'noninteractive', 'console-setup', 'locales'])   ## despues de esto, debconf-get-selections devuelve los valores antiguos, no se por que...
[cc5701c]46
[3fffd21]47    pkgs = []
48    for section in config.options('Packages'):
49        pkgs += re.split (r'[ \n]', config['Packages'].get(section).strip())
[53310a8]50
51    apt.install (
52        [f'linux-image-{osrelease}', f'linux-headers-{osrelease}', f'linux-modules-{osrelease}', f'linux-modules-extra-{osrelease}', 'dkms', 'shim-signed', 'openssl', 'sshfs', 'kexec-tools'] + pkgs32 + pkgs,
53        opts={'DPkg::Options::': '--force-confdef'}         ## hace falta --force-confdef para evitar un tema interactivo del /etc/ssh/ssh_config
54    )
[cc5701c]55
56    # Instalar módulos que algunos paquetes puedan tener pendientes de compilar.
[95a24ac]57    stdout, _ = utils.run (['dkms', 'status'])
[2a2da12]58    for l in stdout.strip().split ('\n'):
59        if not l: continue
[c5e9f68]60        print (f'l "{l}"')
[2a2da12]61        mod, vers, status = l.split (',')
62        if 'added' in status:
[c5e9f68]63            print (f'dkms installing {mod} {vers}')
[95a24ac]64            utils.run (['dkms', 'install', '-m', mod.strip(), '-v', vers.strip()])
[cc5701c]65
66    _oghook_activate()
[9a6fecf]67    apt.clean()
68    apt.autoremove()
[cc5701c]69
[feae768]70def boottoolsSoftwareCompile():
[53310a8]71    env_language = os.environ['LANGUAGE']
72    env_lc_all   = os.environ['LC_ALL']
73    env_lang     = os.environ['LANG']
[feae768]74    os.environ['LANGUAGE'] = os.environ['LC_ALL'] = os.environ['LANG'] = 'C'
75    os.chdir ('/tmp')
76
77    print ('ms-sys')
78    try: utils.run (['which', 'ms-sys'])
79    except:
80        utils.run (['wget', 'https://sourceforge.net/projects/ms-sys/files/latest/download', '-O', 'ms-sys.tar.gz'])
81        utils.run (['tar', '-xpzf', 'ms-sys.tar.gz'])
82        mssys_dir = subprocess.run (['tar tzf ms-sys.tar.gz |head -n 1'], shell=True, capture_output=True, text=True).stdout.strip()
83        print (f'mssys_dir "{mssys_dir}"')
84        os.chdir (mssys_dir)
85        utils.run (['make', 'install'])
86        os.chdir ('..')
87
88    print ('spartlnx')
89    try: utils.run (['which', 'spartl64.run'])
90    except:
91        utils.run (['wget', 'http://damien.guibouret.free.fr/savepart.zip'])
92        utils.run (['unzip', '-o', 'savepart.zip', '-d', '/sbin/', 'spartl64.run'])
93        utils.run (['mkdir', '/usr/share/doc/spartlnx'])
94        utils.run (['unzip', '-j', '-o', 'savepart.zip', '-d', '/usr/share/doc/spartlnx/', 'doc/en/*'])
95
96    if not os.path.exists ('python-libfdisk'):
97        print ('python-libfdisk')
98        apt.install (['python3-psutil', 'python3-dev', 'libfdisk-dev', 'python3-setuptools'])
99        utils.run (['git', 'clone', 'git://git.48k.eu/python-libfdisk'])
100        os.chdir ('python-libfdisk')
101        utils.run (['python3', 'setup.py', 'install'])
102        os.chdir ('..')
103        apt.remove (['python3-dev', 'python3-setuptools'])
104
[53310a8]105    os.environ['LANGUAGE'] = env_language
106    os.environ['LC_ALL']   = env_lc_all
107    os.environ['LANG']     = env_lang
[feae768]108
109def boottoolsInitrdGenerate (osrelease):
110    for f in glob.glob ('/usr/lib/initramfs-tools/bin/*'):
111        os.unlink (f)
112    shutil.copy ('/bin/busybox', '/usr/lib/initramfs-tools/bin')
113
114    os.chdir ('/tmp')
115    utils.run (['mkinitramfs', '-o', f'/tmp/initrd.img-{osrelease}', '-v', osrelease])
116    shutil.copy (f'/boot/vmlinuz-{osrelease}', '/tmp/')
117
[cc5701c]118if __name__ == '__main__':
119    parser = argparse.ArgumentParser()
[feae768]120    parser.add_argument ('--osarch',    help='OS architecture', action='store', required=True)
121    parser.add_argument ('--osrelease', help='OS release',      action='store', required=True)
[cc5701c]122    args = parser.parse_args()
123    boottoolsSoftwareInstall (args.osarch, args.osrelease)
[feae768]124    boottoolsSoftwareCompile()
125    boottoolsInitrdGenerate (args.osrelease)
Note: See TracBrowser for help on using the repository browser.