source: ogLive-Builder-Git/chroot-tasks.py @ 7123d35

deps-vadimfilebeat-installerimprove-versionlgromero-testsmainpull-from-cloning-engine
Last change on this file since 7123d35 was c1a9ff2, checked in by Natalia Serrano <natalia.serrano@…>, 6 months ago

refs #809 install packages and a pip module, try to invalidate docker cache at a specific point

  • Property mode set to 100755
File size: 6.4 KB
Line 
1#!/usr/bin/python3
2
3import argparse
4import shutil
5import os
6import glob
7import sys
8import re
9import subprocess
10
11from boottools import utils, apt
12
13def _oghook_deactivate():
14    #Desactivamos el hook del oginitrd.img para evitar problemas, al final de este escripts se activará
15    os.rename ('/etc/initramfs-tools/hooks/oghooks', '/etc/initramfs-tools/oghooks')
16
17def _oghook_activate():
18    #Activamos el hook del oginitrd.img
19    os.rename ('/etc/initramfs-tools/oghooks', '/etc/initramfs-tools/hooks/oghooks')
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
27    stdout, _ = utils.run (['dpkg-divert', '--list'])
28    if not re.findall (r'local diversion of /sbin/initctl to /sbin/initctl.distrib', stdout):
29        utils.run (['dpkg-divert', '--local', '--rename', '--add', '/sbin/initctl'])
30        os.symlink ('/bin/true', '/sbin/initctl')
31
32    pkgs32 = []
33    if 'i386' != osarch:
34        utils.run (['dpkg', '--add-architecture', 'i386'])
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
36
37    _oghook_deactivate()
38
39    print ('boottoolsSoftwareInstall: debconf-set-selections', file=sys.stderr)
40    subprocess.run (['debconf-set-selections'], input=debconf_settings, text=True)
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...
42
43    pkgs = glob.glob ('/tmp/opengnsys/oglive_builder/ogagent_*.deb') + glob.glob ('/tmp/opengnsys/oglive_builder/OGBrowser*.deb')
44    for section in config.options('Packages'):
45        pkgs += re.split (r'[ \n]', config['Packages'].get(section).strip())
46
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)
49    apt.install (pkgs, opts={'DPkg::Options::': '--force-confdef'})         ## --force-confdef is required to avoid an interactive question regarding /etc/ssh/ssh_config
50
51    # Instalar módulos que algunos paquetes puedan tener pendientes de compilar.
52    print ('boottoolsSoftwareInstall: dkms', file=sys.stderr)
53    stdout, _ = utils.run (['dkms', 'status'])
54    for l in stdout.strip().split ('\n'):
55        if not l: continue
56        #print (f'l "{l}"')
57        mod, vers, status = l.split (',')
58        if 'added' in status:
59            print (f'dkms installing {mod} {vers}')
60            utils.run (['dkms', 'install', '-m', mod.strip(), '-v', vers.strip()])
61
62    _oghook_activate()
63    apt.clean()
64    apt.autoremove()
65
66def boottoolsSoftwareCompile():
67    env_language = os.environ['LANGUAGE']
68    env_lc_all   = os.environ['LC_ALL']
69    env_lang     = os.environ['LANG']
70    os.environ['LANGUAGE'] = os.environ['LC_ALL'] = os.environ['LANG'] = 'C'
71    os.chdir ('/tmp')
72
73    print ('boottoolsSoftwareCompile: ms-sys', file=sys.stderr)
74    try: utils.run (['which', 'ms-sys'])
75    except:
76        utils.run (['wget', '--quiet', 'https://sourceforge.net/projects/ms-sys/files/latest/download', '-O', 'ms-sys.tar.gz'])
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
84    print ('boottoolsSoftwareCompile: spartlnx', file=sys.stderr)
85    try: utils.run (['which', 'spartl64.run'])
86    except:
87        utils.run (['wget', '--quiet', 'http://damien.guibouret.free.fr/savepart.zip'])
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'):
93        print ('boottoolsSoftwareCompile: python-libfdisk', file=sys.stderr)
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
101    os.environ['LANGUAGE'] = env_language
102    os.environ['LC_ALL']   = env_lc_all
103    os.environ['LANG']     = env_lang
104
105def boottoolsPythonModules():
106    utils.run (['pip3', 'install', 'pyblkid'])
107
108def boottoolsInitrdGenerate (osrelease):
109    print ('boottoolsInitrdGenerate', file=sys.stderr)
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    initrd_img = f'/tmp/initrd.img-{osrelease}'
115
116    os.chdir ('/tmp')
117    utils.run (['mkinitramfs', '-o', initrd_img, osrelease])
118    shutil.copy (f'/boot/vmlinuz-{osrelease}', '/tmp/')
119
120    ## turn cpio-with-prepended-stuff into a regular cpio, see #975
121    utils.run (['unmkinitramfs', initrd_img, 'undone'])
122    os.mkdir ('undone/merged')
123    subprocess.run (['rsync -aH undone/early/* undone/main/* undone/merged/'], shell=True)
124    shutil.rmtree ('undone/early')
125    shutil.rmtree ('undone/main')
126    os.chdir ('undone/merged/')
127    subprocess.run ([f'find . |cpio -H newc -oa >{initrd_img}'], shell=True)
128    os.chdir ('/tmp')
129    shutil.rmtree ('undone')
130
131if __name__ == '__main__':
132    parser = argparse.ArgumentParser()
133    parser.add_argument ('--osarch',    help='OS architecture',            action='store', required=True)
134    parser.add_argument ('--osrelease', help='OS release',                 action='store', required=True)
135    parser.add_argument ('--config',    help='Path to configuration file', action='store')
136    args = parser.parse_args()
137
138    config = utils.read_config (args.config or 'mkoglive.cfg')
139    if config is None:
140        sys.exit (1)
141    debconf_settings = config['General'].get ('debconf_settings')
142
143    boottoolsSoftwareInstall (args.osarch, args.osrelease)
144    boottoolsSoftwareCompile()
145    boottoolsPythonModules()
146    boottoolsInitrdGenerate (args.osrelease)
Note: See TracBrowser for help on using the repository browser.