diff --git a/03-boottoolsSoftwareInstall.py b/03-boottoolsSoftwareInstall.py index e45bdf3..6d0cefe 100755 --- a/03-boottoolsSoftwareInstall.py +++ b/03-boottoolsSoftwareInstall.py @@ -6,30 +6,30 @@ import sys import re import subprocess -from boottoolsfunctions import _run, _read_config +from boottoolsfunctions import utils -config = _read_config ('boottoolsgenerator.cfg') +config = utils.read_config ('boottoolsgenerator.cfg') if config is None: sys.exit (1) debconf_settings = config['General'].get ('debconf_settings') def _aptget_clean(): - _run (['apt-get', '--yes', 'clean']) + utils.run (['apt-get', '--yes', 'clean']) def _aptget_autoclean(): - _run (['apt-get', '--yes', 'autoclean']) + utils.run (['apt-get', '--yes', 'autoclean']) def _aptget_autoremove(): - _run (['apt-get', '--yes', 'autoremove']) + utils.run (['apt-get', '--yes', 'autoremove']) def _aptget_update(): - _run (['apt-get', '--yes', 'update']) + utils.run (['apt-get', '--yes', 'update']) def _aptget_upgrade(): - _run (['apt-get', '--yes', 'upgrade']) + utils.run (['apt-get', '--yes', 'upgrade']) def _aptget_install (pkgs, opts=[]): - _run (['apt-get', '--yes'] + opts + ['install'] + pkgs) + utils.run (['apt-get', '--yes'] + opts + ['install'] + pkgs) def _oghook_deactivate(): #Desactivamos el hook del oginitrd.img para evitar problemas, al final de este escripts se activará @@ -55,15 +55,15 @@ def boottoolsSoftwareInstall (osarch, osrelease): os.environ['LANG'] = 'C' os.environ['DEBIAN_FRONTEND'] = 'noninteractive' - stdout, _ = _run (['dpkg-divert', '--list']) + stdout, _ = utils.run (['dpkg-divert', '--list']) if not re.findall (r'local diversion of /sbin/initctl to /sbin/initctl.distrib', stdout): - _run (['dpkg-divert', '--local', '--rename', '--add', '/sbin/initctl']) + utils.run (['dpkg-divert', '--local', '--rename', '--add', '/sbin/initctl']) os.symlink ('/bin/true', '/sbin/initctl') _aptget_clean() pkgs32 = [] if 'i386' != osarch: - _run (['dpkg', '--add-architecture', 'i386']) + 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 _aptget_update() ## esto ya esta hecho... @@ -85,14 +85,14 @@ def boottoolsSoftwareInstall (osarch, osrelease): _aptget_install (pkgs) # Instalar módulos que algunos paquetes puedan tener pendientes de compilar. - stdout, _ = _run (['dkms', 'status']) + 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}') - _run (['dkms', 'install', '-m', mod.strip(), '-v', vers.strip()]) + utils.run (['dkms', 'install', '-m', mod.strip(), '-v', vers.strip()]) _oghook_activate() #_restore_mtab() diff --git a/04-boottoolsSoftwareCompile.py b/04-boottoolsSoftwareCompile.py index 912008c..484cde5 100755 --- a/04-boottoolsSoftwareCompile.py +++ b/04-boottoolsSoftwareCompile.py @@ -2,35 +2,35 @@ import os import subprocess -from boottoolsfunctions import _run +from boottoolsfunctions import utils os.environ['LANGUAGE'] = os.environ['LC_ALL'] = os.environ['LANG'] = 'C' os.chdir ('/tmp') print ('ms-sys') -try: _run (['which', 'ms-sys']) +try: utils.run (['which', 'ms-sys']) except: - _run (['wget', 'https://sourceforge.net/projects/ms-sys/files/latest/download', '-O', 'ms-sys.tar.gz']) - _run (['tar', '-xpzf', 'ms-sys.tar.gz']) + 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) - _run (['make', 'install']) + utils.run (['make', 'install']) os.chdir ('..') print ('spartlnx') -try: _run (['which', 'spartl64.run']) +try: utils.run (['which', 'spartl64.run']) except: - _run (['wget', 'http://damien.guibouret.free.fr/savepart.zip']) - _run (['unzip', '-o', 'savepart.zip', '-d', '/sbin/', 'spartl64.run']) - _run (['mkdir', '/usr/share/doc/spartlnx']) - _run (['unzip', '-j', '-o', 'savepart.zip', '-d', '/usr/share/doc/spartlnx/', 'doc/en/*']) + 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') - _run (['apt-get', '-y', 'install', 'python3-psutil', 'python3-dev', 'libfdisk-dev', 'python3-setuptools']) - _run (['git', 'clone', 'git://git.48k.eu/python-libfdisk']) + utils.run (['apt-get', '-y', 'install', 'python3-psutil', 'python3-dev', 'libfdisk-dev', 'python3-setuptools']) + utils.run (['git', 'clone', 'git://git.48k.eu/python-libfdisk']) os.chdir ('python-libfdisk') - _run (['python3', 'setup.py', 'install']) + utils.run (['python3', 'setup.py', 'install']) os.chdir ('..') - _run (['apt-get', '-y', 'remove', 'python3-dev', 'python3-setuptools']) + utils.run (['apt-get', '-y', 'remove', 'python3-dev', 'python3-setuptools']) diff --git a/05-boottoolsFsLocales.py b/05-boottoolsFsLocales.py index 2d04c60..02684ca 100755 --- a/05-boottoolsFsLocales.py +++ b/05-boottoolsFsLocales.py @@ -2,9 +2,9 @@ import os import subprocess -from boottoolsfunctions import _run, _read_config +from boottoolsfunctions import utils -config = _read_config ('boottoolsgenerator.cfg') +config = utils.read_config ('boottoolsgenerator.cfg') if config is None: sys.exit (1) debconf_settings2 = config['General'].get ('debconf_settings2') @@ -12,4 +12,4 @@ debconf_settings2 = config['General'].get ('debconf_settings2') subprocess.run (['debconf-set-selections'], input=debconf_settings2, text=True) ## despues de esto, debconf-get-selections devuelve los valores antiguos, no se por que... -_run (['dpkg-reconfigure', '--frontend', 'noninteractive', 'console-setup', 'locales']) +utils.run (['dpkg-reconfigure', '--frontend', 'noninteractive', 'console-setup', 'locales']) diff --git a/06-boottoolsInitrdGenerate.py b/06-boottoolsInitrdGenerate.py index 254743e..02c94b1 100755 --- a/06-boottoolsInitrdGenerate.py +++ b/06-boottoolsInitrdGenerate.py @@ -4,7 +4,7 @@ import argparse import shutil import os import glob -from boottoolsfunctions import _run +from boottoolsfunctions import utils def boottoolsInitrdGenerate (osrelease): for f in glob.glob ('/usr/lib/initramfs-tools/bin/*'): @@ -12,7 +12,7 @@ def boottoolsInitrdGenerate (osrelease): shutil.copy ('/bin/busybox', '/usr/lib/initramfs-tools/bin') os.chdir ('/tmp') - _run (['mkinitramfs', '-o', f'/tmp/initrd.img-{osrelease}', '-v', osrelease]) + utils.run (['mkinitramfs', '-o', f'/tmp/initrd.img-{osrelease}', '-v', osrelease]) shutil.copy (f'/boot/vmlinuz-{osrelease}', '/tmp/') if __name__ == '__main__': diff --git a/boottoolsfunctions/__init__.py b/boottoolsfunctions/__init__.py index 592daff..d605174 100644 --- a/boottoolsfunctions/__init__.py +++ b/boottoolsfunctions/__init__.py @@ -1,15 +1,14 @@ import platform import os -import re import time import logging import subprocess import shutil import glob import datetime -import configparser logger = logging.getLogger ('boottools') +from . import utils schroot_conf_tpl = """ [IMGogclient] @@ -39,53 +38,6 @@ proc /proc proc defaults 0 0 /tmp /tmp none rw,bind 0 0 """.strip() -def _run (args): - cp = subprocess.run (args, text=True, capture_output=True) - if cp.returncode: - logger.error ('command "{}" failed with rc "{}"'.format (' '.join(args), cp.returncode)) - - logger.error ('stdout follows:') - for i in cp.stdout.strip().split('\n'): logger.error (' ' + i) - - logger.error ('stderr follows:') - for i in cp.stderr.strip().split('\n'): logger.error (' ' + i) - - raise Exception ('command "{}" failed with rc "{}"'.format (' '.join(args), cp.returncode)) - stdout = cp.stdout.strip() - stderr = cp.stderr.strip() - return stdout, stderr - -def _grep (regex, file): - with open (file, 'r') as f: - for l in f: - if (re.findall (regex, l)): return 1 - return 0 - -def _is_mounted (mntpt): - return _grep (mntpt, '/proc/mounts') - -def _mount (dev, mntpt, opts=[]): - if not _is_mounted (mntpt): - _run (['mount', dev, mntpt] + opts) - -def _umount (mntpt): - if (_is_mounted (mntpt)): - _run (['umount', mntpt]) - -def _read_config (fn): - if not os.path.exists (fn): - print (f'configuration file "{fn}" not found') - return - config = configparser.ConfigParser (comment_prefixes='#', inline_comment_prefixes='#') - config.read (fn) - return config - -def _write_md5 (fn): - md5, _ = _run (['md5sum', fn]) - md5, rest = md5.split (' ', 1) - with open (f'{fn}.sum', 'w') as fd: - fd.write (md5 + '\n') - def btogGetVar (osarch): btdir = '/tmp/opengnsys/oglive_builder' bttargetdir = '/var/lib/tftpboot/ogclient/' @@ -195,7 +147,7 @@ def btogGetOsInfo1 (type_client): osdistrib=platform.freedesktop_os_release()['NAME'] oscodename=platform.freedesktop_os_release()['VERSION_CODENAME'] osrelease=platform.uname()[2] - osarch, _=_run (['dpkg', '--print-architecture']) + osarch, _=utils.run (['dpkg', '--print-architecture']) oshttp='http://es.archive.ubuntu.com/ubuntu/' else: # Parámetro desconocido print ('Parámetro no válido.') @@ -211,66 +163,66 @@ def btogGetOsInfo2 (ogrepo_dir, versionboottools, oscodename, osrelease, osarch) def btogSetFsVirtual (btrootfsimg, btrootfsimglabel, btrootfsmnt, btvirtualdisksize, bttargetdir, osarch): logger.info (f'Creación y formateo del disco virtual "{btrootfsimg}" "{btvirtualdisksize}" MB') - try: _umount (btrootfsmnt) + try: utils.umount (btrootfsmnt) except: pass - if (_is_mounted (btrootfsmnt)): + if (utils.is_mounted (btrootfsmnt)): raise Exception (f'failed to umount "{btrootfsmnt}"') try: os.makedirs (btrootfsmnt, exist_ok=True) except: raise Exception (f'Creando directorio "{btrootfsmnt}" : ERROR') - try: _run (['chown', '-R', 'root:opengnsys', bttargetdir]) + try: utils.run (['chown', '-R', 'root:opengnsys', bttargetdir]) except: raise Exception (f'Failed to chown root:opengnsys "{btrootfsmnt}"') logger.info (f'Creating disk image "{btrootfsimg}"') if 'i386' == osarch: - try: _run (['dd', 'if=/dev/zero', f'of={btrootfsimg}', 'bs=1048576', f'count={btvirtualdisksize}']) + try: utils.run (['dd', 'if=/dev/zero', f'of={btrootfsimg}', 'bs=1048576', f'count={btvirtualdisksize}']) except: raise Exception (f'Creando el disco virtual "{btrootfsimg}" con tamaño maxima "{btvirtualdisksize}" MB : ERROR') else: - try: _run (['qemu-img', 'create', btrootfsimg, btvirtualdisksize]) + try: utils.run (['qemu-img', 'create', btrootfsimg, btvirtualdisksize]) except: raise Exception (f'Creando el disco virtual "{btrootfsimg}" con tamaño maxima "{btvirtualdisksize}" MB : ERROR') logger.debug ('losetup --find') - diskloop, _ = _run (['losetup', '--find']) + diskloop, _ = utils.run (['losetup', '--find']) if not diskloop: raise Exception ('no diskloop') logger.debug ('losetup attach') - try: _run (['losetup', '--partscan', diskloop, btrootfsimg]) + try: utils.run (['losetup', '--partscan', diskloop, btrootfsimg]) except: raise Exception ('losetup failed') logger.info ('Partitioning disk image') - stdout, _ = _run (['bash', '-c', f"echo $'n\np\n1\n\n\nt\n83\nw' |fdisk {diskloop}"]) + stdout, _ = utils.run (['bash', '-c', f"echo $'n\np\n1\n\n\nt\n83\nw' |fdisk {diskloop}"]) logger.debug (f'fdisk stdout follows:') for i in stdout.strip().split('\n'): logger.debug (' ' + i) time.sleep (3) logger.debug ('losetup --detach') - try: _run (['losetup', '--detach', diskloop]) + try: utils.run (['losetup', '--detach', diskloop]) except: raise Exception ('Liberando disco virtual despues del particionado: ERROR') logger.debug ('losetup --find') - partloop, _ = _run (['losetup', '--find']) + partloop, _ = utils.run (['losetup', '--find']) if not partloop: raise Exception ('no partloop') logger.debug ('losetup --offset attach') - _run (['losetup', '--offset', '32256', partloop, btrootfsimg]) + utils.run (['losetup', '--offset', '32256', partloop, btrootfsimg]) logger.info ('Creating ext4 filesystem') - try: _run (['mkfs.ext4', '-b', '4096', '-L', btrootfsimglabel, partloop]) + try: utils.run (['mkfs.ext4', '-b', '4096', '-L', btrootfsimglabel, partloop]) except: raise Exception ('Formateando la particion principal del disco virtual: ERROR') time.sleep (3) logger.debug ('losetup --detach') - try: _run (['losetup', '--detach', partloop]) + try: utils.run (['losetup', '--detach', partloop]) except: raise Exception ('Liberando la particion virtual despues del formateo: ERROR') @@ -278,7 +230,7 @@ def btogSetFsVirtual (btrootfsimg, btrootfsimglabel, btrootfsmnt, btvirtualdisks #btogSetFsAcces: habilita el acceso al sistema root del cliente con schroot def btogSetFsAccess (btrootfsimg): - if (_grep (btrootfsimg, '/etc/schroot/schroot.conf')): + if (utils.grep (btrootfsimg, '/etc/schroot/schroot.conf')): return logger.info ('Iniciando la configuración del schroot') @@ -305,7 +257,7 @@ def btogSetFsBase (btrootfsimg, btrootfsmnt, osarch, oscodename, oshttp): logger.info ('debootstrapping system') logger.debug (f'debootstrap --arch="{osarch}" --components=main,universe "{oscodename}" "{btrootfsmnt}" "{oshttp}"') - try: _run (['debootstrap', f'--arch={osarch}', '--components=main,universe', oscodename, btrootfsmnt, oshttp]) + try: utils.run (['debootstrap', f'--arch={osarch}', '--components=main,universe', oscodename, btrootfsmnt, oshttp]) except: raise Exception (f'debootstrap --arch="{osarch}" --components=main,universe "{oscodename}" "{btrootfsmnt}" "{oshttp}" : ha fallado!') logger.info (f'debootstrap --arch="{osarch}" --components=main,universe "{oscodename}" "{btrootfsmnt}" "{oshttp}" : ok') @@ -351,7 +303,7 @@ def boottoolsFsOpengnsys (builder, og_shared, og_engine, ogclientmount, osdistri def boottoolsSshServer (btrootfsmnt): if not os.path.exists ('/root/.ssh/id_rsa'): ## crea un par de claves en la VM, no en el chroot - _run (['ssh-keygen', '-q', '-f', '/root/.ssh/id_rsa', '-N', '']) + utils.run (['ssh-keygen', '-q', '-f', '/root/.ssh/id_rsa', '-N', '']) logger.debug ('comprobando directorio .ssh del root') if not os.path.exists (f'{btrootfsmnt}/root/.ssh'): ## crea directorio dentro del chroot @@ -381,7 +333,7 @@ def boottoolsSshServer (btrootfsmnt): def boottoolsSshClient (btrootfsmnt): if not os.path.exists (f'{btrootfsmnt}/root/.ssh/id_rsa'): - _run (['ssh-keygen', '-q', '-f', f'{btrootfsmnt}/root/.ssh/id_rsa', '-N', '']) ## crea un par de claves en el chroot + utils.run (['ssh-keygen', '-q', '-f', f'{btrootfsmnt}/root/.ssh/id_rsa', '-N', '']) ## crea un par de claves en el chroot #cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys ## coge la publica y se la autoriza a sí mismo fdin = open (f'{btrootfsmnt}//root/.ssh/id_rsa.pub', 'r') @@ -413,8 +365,8 @@ def btogFsInitrd (bttargetdir, osrelease): shutil.copy (f'/tmp/initrd.img-{osrelease}', f'{bttargetdir}/oginitrd.img') shutil.copy (f'/tmp/vmlinuz-{osrelease}', f'{bttargetdir}/ogvmlinuz') - _write_md5 (f'{bttargetdir}/oginitrd.img') - _write_md5 (f'{bttargetdir}/ogvmlinuz') + utils.write_md5 (f'{bttargetdir}/oginitrd.img') + utils.write_md5 (f'{bttargetdir}/ogvmlinuz') #chmod -R 755 $BTTARGETDIR for f in glob.glob (f'{bttargetdir}/oginitrd*') + glob.glob (f'{bttargetdir}/vmlinuz*'): @@ -429,10 +381,10 @@ def btogFsSqfs (bttargetdir, btrootfsmnt): now = datetime.datetime.now(datetime.timezone.utc).strftime ('%Y%m%d-%H%M%S%z') os.rename (f'{bttargetdir}/ogclient.sqfs', f'{bttargetdir}/ogclient.sqfs.{now}') - _run (['mksquashfs', btrootfsmnt, f'{bttargetdir}/ogclient.sqfs']) + utils.run (['mksquashfs', btrootfsmnt, f'{bttargetdir}/ogclient.sqfs']) os.chmod (f'{bttargetdir}/ogclient.sqfs', 0o744) - _write_md5 (f'{bttargetdir}/ogclient.sqfs') + utils.write_md5 (f'{bttargetdir}/ogclient.sqfs') # btogIsoGenerator genera la iso del cliente def btogIsoGenerator (pxepkg, isolinux_tpl, bttargetdir, nameisoclient): @@ -452,9 +404,9 @@ def btogIsoGenerator (pxepkg, isolinux_tpl, bttargetdir, nameisoclient): # Si existe el fichero ISO, montarlo para extraer isolinux.bin. if os.path.exists (f'/tmp/iso/isolinux/{pxepkg}.iso'): os.mkdir ('/tmp/iso/isolinux/mount') - _run (['mount', '-o', 'loop', f'/tmp/iso/isolinux/{pxepkg}.iso', '/tmp/iso/isolinux/mount']) + utils.run (['mount', '-o', 'loop', f'/tmp/iso/isolinux/{pxepkg}.iso', '/tmp/iso/isolinux/mount']) subprocess.run (['cp -a /tmp/iso/isolinux/mount/* /tmp/iso/isolinux'], shell=True) - _umount ('/tmp/iso/isolinux/mount') + utils.umount ('/tmp/iso/isolinux/mount') os.rmdir ('/tmp/iso/isolinux/mount') os.unlink (f'/tmp/iso/isolinux/{pxepkg}.iso') @@ -478,9 +430,9 @@ def btogIsoGenerator (pxepkg, isolinux_tpl, bttargetdir, nameisoclient): oldpwd = os.getcwd() os.chdir ('/tmp') logger.debug (f'mkisofs -V ogClient -o {nameisoclient}.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -J -no-emul-boot -boot-load-size 4 -boot-info-table /tmp/iso') - _run (['mkisofs', '-V', 'ogClient', '-o', f'{nameisoclient}.iso', '-b', 'isolinux/isolinux.bin', '-c', 'isolinux/boot.cat', '-J', '-no-emul-boot', '-boot-load-size', '4', '-boot-info-table', '/tmp/iso']) + utils.run (['mkisofs', '-V', 'ogClient', '-o', f'{nameisoclient}.iso', '-b', 'isolinux/isolinux.bin', '-c', 'isolinux/boot.cat', '-J', '-no-emul-boot', '-boot-load-size', '4', '-boot-info-table', '/tmp/iso']) - _write_md5 (f'{nameisoclient}.iso') + utils.write_md5 (f'{nameisoclient}.iso') os.chdir (oldpwd) os.rename (f'/tmp/{nameisoclient}.iso' , f'/var/lib/tftpboot/ogclient/{nameisoclient}.iso') diff --git a/boottoolsgenerator.py b/boottoolsgenerator.py index 2dc47ca..dbd6e60 100755 --- a/boottoolsgenerator.py +++ b/boottoolsgenerator.py @@ -10,7 +10,7 @@ import shutil curdir = os.path.dirname (__file__) sys.path.insert (0, curdir) -from boottoolsfunctions import _run, _mount, _umount, _read_config, btogGetOsInfo1, btogGetOsInfo2, btogGetVar, btogSetFsVirtual, btogSetFsAccess, btogSetFsBase, boottoolsFsOpengnsys, boottoolsSshServer, boottoolsSshClient, btogFsInitrd, btogFsSqfs, btogIsoGenerator +from boottoolsfunctions import utils, btogGetOsInfo1, btogGetOsInfo2, btogGetVar, btogSetFsVirtual, btogSetFsAccess, btogSetFsBase, boottoolsFsOpengnsys, boottoolsSshServer, boottoolsSshClient, btogFsInitrd, btogFsSqfs, btogIsoGenerator def _logging(): #logging.root.handlers = [] @@ -31,21 +31,21 @@ def _logging(): def clone_client_dirs (ogrepo_url, ogrepo_branch, ogrepo_dir): if not os.path.exists ('/tmp/opengnsys/engine'): - _run (['git', 'clone', '-c', 'http.sslVerify=false', '--branch', ogrepo_branch, ogrepo_url, ogrepo_dir]) - _run (['rsync', '-aH', f'{ogrepo_dir}/client/engine', f'{ogrepo_dir}/client/shared', '/tmp/opengnsys/']) + utils.run (['git', 'clone', '-c', 'http.sslVerify=false', '--branch', ogrepo_branch, ogrepo_url, ogrepo_dir]) + utils.run (['rsync', '-aH', f'{ogrepo_dir}/client/engine', f'{ogrepo_dir}/client/shared', '/tmp/opengnsys/']) def _mount_rootfs(): global btrootfsimg, btrootfsmnt - try: _mount (btrootfsimg, btrootfsmnt, opts=['-o', 'loop,offset=32256']) + try: utils.mount (btrootfsimg, btrootfsmnt, opts=['-o', 'loop,offset=32256']) except: logger.error ('mount failed') sys.exit (1) def _get_pxepkg(): #grep "http://free.nchc.org.tw/drbl-core" /etc/apt/sources.list || echo "deb http://free.nchc.org.tw/drbl-core drbl stable" >> /etc/apt/sources.list - _run (['apt-get', 'update']) - acse_gpxe, _ = _run (['apt-cache', 'search', 'gpxe']) - acse_ipxe, _ = _run (['apt-cache', 'search', 'ipxe']) + utils.run (['apt-get', 'update']) + acse_gpxe, _ = utils.run (['apt-cache', 'search', 'gpxe']) + acse_ipxe, _ = utils.run (['apt-cache', 'search', 'ipxe']) if acse_ipxe: pxepkg = 'ipxe' elif acse_gpxe: @@ -90,7 +90,7 @@ def _debootstrap(): def _initramfs_version (gitrelease, osrelease, btdir): ## FIXME esto la incluye incondicionalmente, y luego terminamos con "OpenGnsys Client 1.2.0-rc1 gitrelease (osrelease) gitrelease (osrelease) gitrelease (osrelease) gitrelease (osrelease) gitrelease (osrelease) gitrelease (osrelease) ..." #sed -i "1 s/$/ $GITRELEASE ($OSRELEASE)/" ${BTDIR}/includes/etc/initramfs-tools/scripts/VERSION.txt - _run (['sed', '-i', f'1 s/$/ {gitrelease} ({osrelease})/', f'{btdir}/includes/etc/initramfs-tools/scripts/VERSION.txt']) + utils.run (['sed', '-i', f'1 s/$/ {gitrelease} ({osrelease})/', f'{btdir}/includes/etc/initramfs-tools/scripts/VERSION.txt']) def _copy_files (btrootfsmnt, osdistrib, oscodename): _mount_rootfs() @@ -98,31 +98,31 @@ def _copy_files (btrootfsmnt, osdistrib, oscodename): og_shared = '/tmp/opengnsys/shared' og_engine = '/tmp/opengnsys/engine' boottoolsFsOpengnsys (builder, og_shared, og_engine, btrootfsmnt, osdistrib, oscodename) - _umount (btrootfsmnt) + utils.umount (btrootfsmnt) def _install_compile_software (curdir, osrelease, osarch): logger.info ('Fase 5.1 instalar paquetes deb con apt-get') logger.debug (f'running \'schroot --chroot IMGogclient -- {curdir}/03-boottoolsSoftwareInstall.py --osrelease "{osrelease}" --osarch "{osarch}"\'') - stdout, _ = _run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/03-boottoolsSoftwareInstall.py', '--osrelease', osrelease, '--osarch', osarch]) + stdout, _ = utils.run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/03-boottoolsSoftwareInstall.py', '--osrelease', osrelease, '--osarch', osarch]) logger.debug (f'03-boottoolsSoftwareInstall stdout follows:') for i in stdout.strip().split('\n'): logger.debug (' ' + i) logger.info ('Fase 5.2 compilar software.') logger.debug (f'running \'schroot --chroot IMGogclient -- {curdir}/04-boottoolsSoftwareCompile.py\'') - stdout, _ = _run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/04-boottoolsSoftwareCompile.py']) + stdout, _ = utils.run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/04-boottoolsSoftwareCompile.py']) logger.debug (f'04-boottoolsSoftwareCompile stdout follows:') for i in stdout.strip().split('\n'): logger.debug (' ' + i) def _debconf2 (curdir): logger.info ('Fase 6.1 Configurar las locales') logger.debug (f'running \'schroot --chroot IMGogclient -- {curdir}/05-boottoolsFsLocales.py\'') - stdout, _ = _run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/05-boottoolsFsLocales.py']) + stdout, _ = utils.run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/05-boottoolsFsLocales.py']) logger.debug (f'05-boottoolsFsLocales stdout follows:') for i in stdout.strip().split('\n'): logger.debug (' ' + i) logger.info ('Fase 6.3 Crear initrd') logger.debug (f'running \'schroot --chroot IMGogclient -- {curdir}/06-boottoolsInitrdGenerate.py --osrelease "{osrelease}"\'') - stdout, _ = _run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/06-boottoolsInitrdGenerate.py', '--osrelease', osrelease]) + stdout, _ = utils.run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/06-boottoolsInitrdGenerate.py', '--osrelease', osrelease]) logger.debug (f'06-boottoolsInitrdGenerate stdout follows:') for i in stdout.strip().split('\n'): logger.debug (' ' + i) ## esto deja initrd.img-6.8.0-31-generic y vmlinuz-6.8.0-31-generic en /tmp @@ -132,27 +132,27 @@ def _ssh_stuff(): _mount_rootfs() boottoolsSshServer (btrootfsmnt) boottoolsSshClient (btrootfsmnt) - _umount (btrootfsmnt) + utils.umount (btrootfsmnt) ## el resultado es: ## - hay un nuevo par de claves en la VM /root/.ssh ## - hay otro nuevo par de claves en el rootfs /var/lib/tftpboot/ogclient/ogclientmount/root/.ssh ## - las dos claves públicas (una de cada par) están autorizadan en el rootfs /var/lib/tftpboot/ogclient/ogclientmount/root/.ssh/authorized_keys -def _mkinitrd_squashfs_isofs (bttargetdir, osrelease, btrootfsmnt, pxepkg, isolinux_tpl nameisoclient): +def _mkinitrd_squashfs_isofs (bttargetdir, osrelease, btrootfsmnt, pxepkg, isolinux_tpl, nameisoclient): logger.info ('Fase 7.1 Copiar el initrd a su sitio') _mount_rootfs() btogFsInitrd (bttargetdir, osrelease) logger.info ('Fase 7.2 Generar fichero sqfs a partir del fichero img') btogFsSqfs (bttargetdir, btrootfsmnt) - _umount (btrootfsmnt) + utils.umount (btrootfsmnt) logger.info ('Fase 7.3 Generar la ISO') btogIsoGenerator (pxepkg, isolinux_tpl, bttargetdir, nameisoclient) -config = _read_config ('boottoolsgenerator.cfg') +config = utils.read_config ('boottoolsgenerator.cfg') if config is None: sys.exit (1) isolinux_tpl = config['General'].get ('isolinux_template') @@ -181,12 +181,12 @@ gitrelease, nameisoclient, namehostclient = btogGetOsInfo2(ogrepo_dir, versionbo logger.info (':'.join ([osdistrib, oscodename, osrelease, osarch, oshttp])) ## this is convenient in case the previous run failed and we want to run this program again -try: _umount (btrootfsmnt) +try: utils.umount (btrootfsmnt) except: pass logger.info ('FASE 2 - Instalación de software adicional.') pxepkg = _get_pxepkg() -_run (['apt-get', '-y', 'install', 'jq', 'syslinux', 'syslinux-efi', 'syslinux-utils', 'debootstrap', 'subversion', 'schroot', 'squashfs-tools', 'syslinux', 'genisoimage', 'qemu-utils', 'lsof', pxepkg]) ## TODO qemu no existe, hace falta? +utils.run (['apt-get', '-y', 'install', 'jq', 'syslinux', 'syslinux-efi', 'syslinux-utils', 'debootstrap', 'subversion', 'schroot', 'squashfs-tools', 'syslinux', 'genisoimage', 'qemu-utils', 'lsof', pxepkg]) ## TODO qemu no existe, hace falta? logger.info ('FASE 3 - Creación del Sistema raiz RootFS (Segundo Sistema archivos (img))') _mkrootfs() @@ -195,7 +195,7 @@ _debootstrap() logger.info ('FASE 4 - Incorporando ficheros OpenGnsys al sistema raíz rootfs') _initramfs_version (gitrelease, osrelease, btdir) -_copy_files (btrootfsmnt, osdistrib, oscodename, osrelease, osarch, oshttp) +_copy_files (btrootfsmnt, osdistrib, oscodename) logger.info ('FASE 5 - Instalar software') _install_compile_software (curdir, osrelease, osarch) @@ -205,6 +205,6 @@ _debconf2 (curdir) _ssh_stuff() logger.info ('FASE 7 - Generar distribucion') -_mkinitrd_squashfs_isofs (bttargetdir, osrelease, btrootfsmnt, pxepkg, isolinux_tpl nameisoclient) +_mkinitrd_squashfs_isofs (bttargetdir, osrelease, btrootfsmnt, pxepkg, isolinux_tpl, nameisoclient) logger.info ('OpenGnsys installation finished')