#!/usr/bin/python3 import argparse import shutil import os import glob import sys import re import subprocess from boottools import utils, apt config = utils.read_config ('mkoglive.cfg') if config is None: sys.exit (1) debconf_settings = config['General'].get ('debconf_settings') def _oghook_deactivate(): #Desactivamos el hook del oginitrd.img para evitar problemas, al final de este escripts se activará os.rename ('/etc/initramfs-tools/hooks/oghooks', '/etc/initramfs-tools/oghooks') def _oghook_activate(): #Activamos el hook del oginitrd.img os.rename ('/etc/initramfs-tools/oghooks', '/etc/initramfs-tools/hooks/oghooks') def boottoolsSoftwareInstall (osarch, osrelease): os.environ['LANGUAGE'] = 'C' os.environ['LC_ALL'] = 'C' os.environ['LANG'] = 'C' os.environ['DEBIAN_FRONTEND'] = 'noninteractive' stdout, _ = utils.run (['dpkg-divert', '--list']) if not re.findall (r'local diversion of /sbin/initctl to /sbin/initctl.distrib', stdout): utils.run (['dpkg-divert', '--local', '--rename', '--add', '/sbin/initctl']) os.symlink ('/bin/true', '/sbin/initctl') pkgs32 = [] if 'i386' != osarch: utils.run (['dpkg', '--add-architecture', 'i386']) 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 _oghook_deactivate() subprocess.run (['debconf-set-selections'], input=debconf_settings, text=True) utils.run (['dpkg-reconfigure', '--frontend', 'noninteractive', 'console-setup', 'locales']) ## despues de esto, debconf-get-selections devuelve los valores antiguos, no se por que... pkgs = [] for section in config.options('Packages'): pkgs += re.split (r'[ \n]', config['Packages'].get(section).strip()) apt.install ( [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, opts={'DPkg::Options::': '--force-confdef'} ## hace falta --force-confdef para evitar un tema interactivo del /etc/ssh/ssh_config ) # Instalar módulos que algunos paquetes puedan tener pendientes de compilar. stdout, _ = utils.run (['dkms', 'status']) for l in stdout.strip().split ('\n'): if not l: continue print (f'l "{l}"') mod, vers, status = l.split (',') if 'added' in status: print (f'dkms installing {mod} {vers}') utils.run (['dkms', 'install', '-m', mod.strip(), '-v', vers.strip()]) _oghook_activate() apt.clean() apt.autoremove() def boottoolsSoftwareCompile(): env_language = os.environ['LANGUAGE'] env_lc_all = os.environ['LC_ALL'] env_lang = os.environ['LANG'] os.environ['LANGUAGE'] = os.environ['LC_ALL'] = os.environ['LANG'] = 'C' os.chdir ('/tmp') print ('ms-sys') try: utils.run (['which', 'ms-sys']) except: utils.run (['wget', 'https://sourceforge.net/projects/ms-sys/files/latest/download', '-O', 'ms-sys.tar.gz']) utils.run (['tar', '-xpzf', 'ms-sys.tar.gz']) mssys_dir = subprocess.run (['tar tzf ms-sys.tar.gz |head -n 1'], shell=True, capture_output=True, text=True).stdout.strip() print (f'mssys_dir "{mssys_dir}"') os.chdir (mssys_dir) utils.run (['make', 'install']) os.chdir ('..') print ('spartlnx') try: utils.run (['which', 'spartl64.run']) except: utils.run (['wget', 'http://damien.guibouret.free.fr/savepart.zip']) utils.run (['unzip', '-o', 'savepart.zip', '-d', '/sbin/', 'spartl64.run']) utils.run (['mkdir', '/usr/share/doc/spartlnx']) utils.run (['unzip', '-j', '-o', 'savepart.zip', '-d', '/usr/share/doc/spartlnx/', 'doc/en/*']) if not os.path.exists ('python-libfdisk'): print ('python-libfdisk') apt.install (['python3-psutil', 'python3-dev', 'libfdisk-dev', 'python3-setuptools']) utils.run (['git', 'clone', 'git://git.48k.eu/python-libfdisk']) os.chdir ('python-libfdisk') utils.run (['python3', 'setup.py', 'install']) os.chdir ('..') apt.remove (['python3-dev', 'python3-setuptools']) os.environ['LANGUAGE'] = env_language os.environ['LC_ALL'] = env_lc_all os.environ['LANG'] = env_lang def boottoolsInitrdGenerate (osrelease): for f in glob.glob ('/usr/lib/initramfs-tools/bin/*'): os.unlink (f) shutil.copy ('/bin/busybox', '/usr/lib/initramfs-tools/bin') os.chdir ('/tmp') utils.run (['mkinitramfs', '-o', f'/tmp/initrd.img-{osrelease}', '-v', osrelease]) shutil.copy (f'/boot/vmlinuz-{osrelease}', '/tmp/') if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument ('--osarch', help='OS architecture', action='store', required=True) parser.add_argument ('--osrelease', help='OS release', action='store', required=True) args = parser.parse_args() boottoolsSoftwareInstall (args.osarch, args.osrelease) boottoolsSoftwareCompile() boottoolsInitrdGenerate (args.osrelease)