[cc5701c] | 1 | #!/usr/bin/python3 |
---|
| 2 | |
---|
| 3 | import argparse |
---|
[feae768] | 4 | import shutil |
---|
[cc5701c] | 5 | import os |
---|
[feae768] | 6 | import glob |
---|
[a193b67] | 7 | import sys |
---|
[ec2ab82] | 8 | import re |
---|
[cc5701c] | 9 | import subprocess |
---|
| 10 | |
---|
[d1822ec] | 11 | from boottools import utils, apt |
---|
[ec2ab82] | 12 | |
---|
[cc5701c] | 13 | def _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 | |
---|
| 17 | def _oghook_activate(): |
---|
| 18 | #Activamos el hook del oginitrd.img |
---|
[ec2ab82] | 19 | os.rename ('/etc/initramfs-tools/oghooks', '/etc/initramfs-tools/hooks/oghooks') |
---|
[cc5701c] | 20 | |
---|
| 21 | def 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']) |
---|
[0ab0e61] | 35 | pkgs32 = 'lib32gcc-s1 lib32stdc++6 lib32z1 libc6-i386'.split (' ') ## nserrano: he cambiado lib32gcc1 por lib32gcc-s1 pero como queramos crear un oglive viejo, esto va a petar |
---|
[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 | |
---|
[c79d715] | 47 | 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'] + pkgs32 + pkgs |
---|
| 48 | print (f'boottoolsSoftwareInstall: installing packages: {str(pkgs)}', file=sys.stderr) |
---|
[0ab0e61] | 49 | apt.install (pkgs, opts={'DPkg::Options::': '--force-confdef'}) ## --force-confdef is required to avoid an interactive question regarding /etc/ssh/ssh_config |
---|
[cc5701c] | 50 | |
---|
| 51 | # Instalar módulos que algunos paquetes puedan tener pendientes de compilar. |
---|
[c79d715] | 52 | print ('boottoolsSoftwareInstall: dkms', file=sys.stderr) |
---|
[95a24ac] | 53 | stdout, _ = utils.run (['dkms', 'status']) |
---|
[2a2da12] | 54 | for l in stdout.strip().split ('\n'): |
---|
| 55 | if not l: continue |
---|
[c79d715] | 56 | #print (f'l "{l}"') |
---|
[2a2da12] | 57 | mod, vers, status = l.split (',') |
---|
| 58 | if 'added' in status: |
---|
[c5e9f68] | 59 | print (f'dkms installing {mod} {vers}') |
---|
[95a24ac] | 60 | utils.run (['dkms', 'install', '-m', mod.strip(), '-v', vers.strip()]) |
---|
[cc5701c] | 61 | |
---|
| 62 | _oghook_activate() |
---|
[9a6fecf] | 63 | apt.clean() |
---|
| 64 | apt.autoremove() |
---|
[cc5701c] | 65 | |
---|
[feae768] | 66 | def boottoolsSoftwareCompile(): |
---|
[53310a8] | 67 | env_language = os.environ['LANGUAGE'] |
---|
| 68 | env_lc_all = os.environ['LC_ALL'] |
---|
| 69 | env_lang = os.environ['LANG'] |
---|
[feae768] | 70 | os.environ['LANGUAGE'] = os.environ['LC_ALL'] = os.environ['LANG'] = 'C' |
---|
| 71 | os.chdir ('/tmp') |
---|
| 72 | |
---|
[c79d715] | 73 | print ('boottoolsSoftwareCompile: ms-sys', file=sys.stderr) |
---|
[feae768] | 74 | try: utils.run (['which', 'ms-sys']) |
---|
| 75 | except: |
---|
[d4564f6] | 76 | utils.run (['wget', '--quiet', 'https://sourceforge.net/projects/ms-sys/files/latest/download', '-O', 'ms-sys.tar.gz']) |
---|
[feae768] | 77 | utils.run (['tar', '-xpzf', 'ms-sys.tar.gz']) |
---|
| 78 | mssys_dir = subprocess.run (['tar tzf ms-sys.tar.gz |head -n 1'], shell=True, capture_output=True, text=True).stdout.strip() |
---|
| 79 | print (f'mssys_dir "{mssys_dir}"') |
---|
| 80 | os.chdir (mssys_dir) |
---|
| 81 | utils.run (['make', 'install']) |
---|
| 82 | os.chdir ('..') |
---|
| 83 | |
---|
[c79d715] | 84 | print ('boottoolsSoftwareCompile: spartlnx', file=sys.stderr) |
---|
[feae768] | 85 | try: utils.run (['which', 'spartl64.run']) |
---|
| 86 | except: |
---|
[d4564f6] | 87 | utils.run (['wget', '--quiet', 'http://damien.guibouret.free.fr/savepart.zip']) |
---|
[feae768] | 88 | utils.run (['unzip', '-o', 'savepart.zip', '-d', '/sbin/', 'spartl64.run']) |
---|
| 89 | utils.run (['mkdir', '/usr/share/doc/spartlnx']) |
---|
| 90 | utils.run (['unzip', '-j', '-o', 'savepart.zip', '-d', '/usr/share/doc/spartlnx/', 'doc/en/*']) |
---|
| 91 | |
---|
| 92 | if not os.path.exists ('python-libfdisk'): |
---|
[c79d715] | 93 | print ('boottoolsSoftwareCompile: python-libfdisk', file=sys.stderr) |
---|
[feae768] | 94 | apt.install (['python3-psutil', 'python3-dev', 'libfdisk-dev', 'python3-setuptools']) |
---|
| 95 | utils.run (['git', 'clone', 'git://git.48k.eu/python-libfdisk']) |
---|
| 96 | os.chdir ('python-libfdisk') |
---|
| 97 | utils.run (['python3', 'setup.py', 'install']) |
---|
| 98 | os.chdir ('..') |
---|
| 99 | apt.remove (['python3-dev', 'python3-setuptools']) |
---|
| 100 | |
---|
[53310a8] | 101 | os.environ['LANGUAGE'] = env_language |
---|
| 102 | os.environ['LC_ALL'] = env_lc_all |
---|
| 103 | os.environ['LANG'] = env_lang |
---|
[feae768] | 104 | |
---|
| 105 | def boottoolsInitrdGenerate (osrelease): |
---|
[c79d715] | 106 | print ('boottoolsInitrdGenerate', file=sys.stderr) |
---|
[feae768] | 107 | for f in glob.glob ('/usr/lib/initramfs-tools/bin/*'): |
---|
| 108 | os.unlink (f) |
---|
| 109 | shutil.copy ('/bin/busybox', '/usr/lib/initramfs-tools/bin') |
---|
| 110 | |
---|
[13b086f] | 111 | initrd_img = f'/tmp/initrd.img-{osrelease}' |
---|
| 112 | |
---|
[feae768] | 113 | os.chdir ('/tmp') |
---|
[13b086f] | 114 | utils.run (['mkinitramfs', '-o', initrd_img, osrelease]) |
---|
[feae768] | 115 | shutil.copy (f'/boot/vmlinuz-{osrelease}', '/tmp/') |
---|
| 116 | |
---|
[13b086f] | 117 | ## turn cpio-with-prepended-stuff into a regular cpio, see #975 |
---|
| 118 | utils.run (['unmkinitramfs', initrd_img, 'undone']) |
---|
| 119 | os.mkdir ('undone/merged') |
---|
| 120 | subprocess.run (['rsync -aH undone/early/* undone/main/* undone/merged/'], shell=True) |
---|
| 121 | shutil.rmtree ('undone/early') |
---|
| 122 | shutil.rmtree ('undone/main') |
---|
| 123 | os.chdir ('undone/merged/') |
---|
| 124 | subprocess.run ([f'find . |cpio -H newc -oa >{initrd_img}'], shell=True) |
---|
| 125 | os.chdir ('/tmp') |
---|
| 126 | shutil.rmtree ('undone') |
---|
| 127 | |
---|
[cc5701c] | 128 | if __name__ == '__main__': |
---|
| 129 | parser = argparse.ArgumentParser() |
---|
[d4564f6] | 130 | parser.add_argument ('--osarch', help='OS architecture', action='store', required=True) |
---|
| 131 | parser.add_argument ('--osrelease', help='OS release', action='store', required=True) |
---|
| 132 | parser.add_argument ('--config', help='Path to configuration file', action='store') |
---|
[cc5701c] | 133 | args = parser.parse_args() |
---|
[d4564f6] | 134 | |
---|
| 135 | config = utils.read_config (args.config or 'mkoglive.cfg') |
---|
| 136 | if config is None: |
---|
| 137 | sys.exit (1) |
---|
| 138 | debconf_settings = config['General'].get ('debconf_settings') |
---|
| 139 | |
---|
[cc5701c] | 140 | boottoolsSoftwareInstall (args.osarch, args.osrelease) |
---|
[feae768] | 141 | boottoolsSoftwareCompile() |
---|
| 142 | boottoolsInitrdGenerate (args.osrelease) |
---|