From d1822ec5fb38cf6ec5869037fdbdb463302c8209 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Fri, 16 Aug 2024 13:00:10 +0200 Subject: [PATCH] refs #596 rename files and functions --- 04-boottoolsSoftwareCompile.py | 0 05-boottoolsFsLocales.py | 0 06-boottoolsInitrdGenerate.py | 0 {boottoolsfunctions => boottools}/apt.py | 0 {boottoolsfunctions => boottools}/btog.py | 24 ++++++------- {boottoolsfunctions => boottools}/utils.py | 0 ...toolsSoftwareInstall.py => chroot-tasks.py | 4 +-- boottoolsgenerator.cfg => mkoglive.cfg | 0 boottoolsgenerator.py => mkoglive.py | 34 +++++++++---------- 9 files changed, 31 insertions(+), 31 deletions(-) delete mode 100755 04-boottoolsSoftwareCompile.py delete mode 100755 05-boottoolsFsLocales.py delete mode 100755 06-boottoolsInitrdGenerate.py rename {boottoolsfunctions => boottools}/apt.py (100%) rename {boottoolsfunctions => boottools}/btog.py (97%) rename {boottoolsfunctions => boottools}/utils.py (100%) rename 03-boottoolsSoftwareInstall.py => chroot-tasks.py (98%) rename boottoolsgenerator.cfg => mkoglive.cfg (100%) rename boottoolsgenerator.py => mkoglive.py (86%) diff --git a/04-boottoolsSoftwareCompile.py b/04-boottoolsSoftwareCompile.py deleted file mode 100755 index e69de29..0000000 diff --git a/05-boottoolsFsLocales.py b/05-boottoolsFsLocales.py deleted file mode 100755 index e69de29..0000000 diff --git a/06-boottoolsInitrdGenerate.py b/06-boottoolsInitrdGenerate.py deleted file mode 100755 index e69de29..0000000 diff --git a/boottoolsfunctions/apt.py b/boottools/apt.py similarity index 100% rename from boottoolsfunctions/apt.py rename to boottools/apt.py diff --git a/boottoolsfunctions/btog.py b/boottools/btog.py similarity index 97% rename from boottoolsfunctions/btog.py rename to boottools/btog.py index 3f14d92..bb2049b 100644 --- a/boottoolsfunctions/btog.py +++ b/boottools/btog.py @@ -161,7 +161,7 @@ def GetOsInfo2 (ogrepo_dir, versionboottools, oscodename, osrelease, osarch): namehostclient = '-'.join ([versionboottools, oscodename, gitrelease]) return gitrelease, nameisoclient, namehostclient -def SetFsVirtual (btrootfsimg, btrootfsimglabel, btrootfsmnt, btvirtualdisksize, bttargetdir, osarch): +def mkrootfs (btrootfsimg, btrootfsimglabel, btrootfsmnt, btvirtualdisksize, bttargetdir, osarch): logger.info (f'Creación y formateo del disco virtual "{btrootfsimg}" "{btvirtualdisksize}" MB') try: utils.umount (btrootfsmnt) @@ -230,7 +230,7 @@ def SetFsVirtual (btrootfsimg, btrootfsimglabel, btrootfsmnt, btvirtualdisksize, logger.info (f'"{btrootfsimg}" "{btvirtualdisksize}" MB : OK') #SetFsAcces: habilita el acceso al sistema root del cliente con schroot -def SetFsAccess (btrootfsimg): +def configure_schroot (btrootfsimg): if (utils.grep (btrootfsimg, '/etc/schroot/schroot.conf')): return logger.info ('Iniciando la configuración del schroot') @@ -264,8 +264,8 @@ def SetFsBase (btrootfsimg, btrootfsmnt, osarch, oscodename, oshttp): logger.info (f'debootstrap --arch="{osarch}" --components=main,universe "{oscodename}" "{btrootfsmnt}" "{oshttp}" : ok') return 0 -def FsOpengnsys (builder, og_shared, og_engine, ogclientmount, osdistrib, oscodename): - print ('Iniciando la personalización con datos del repositorio') +def copy_og_files (builder, og_shared, og_engine, ogclientmount, osdistrib, oscodename): + logger.info ('Iniciando la personalización con datos del repositorio') sources_list_in = f'{builder}/includes/etc/apt/sources.list.{osdistrib.lower()}' sources_list_out = f'{builder}/includes/etc/apt/sources.list' @@ -302,7 +302,7 @@ def FsOpengnsys (builder, og_shared, og_engine, ogclientmount, osdistrib, oscode if os.path.exists (f'{og_shared}/bin/browser'): shutil.copy (f'{og_shared}/bin/browser', f'{ogclientmount}/bin/') if os.path.exists (f'{og_shared}/bin/ogAdmClient'): shutil.copy (f'{og_shared}/bin/ogAdmClient', f'{ogclientmount}/bin/') -def SshServer (btrootfsmnt): +def ssh_server (btrootfsmnt): if not os.path.exists ('/root/.ssh/id_rsa'): ## crea un par de claves en la VM, no en el chroot utils.run (['ssh-keygen', '-q', '-f', '/root/.ssh/id_rsa', '-N', '']) @@ -332,7 +332,7 @@ def SshServer (btrootfsmnt): else: logger.error ('no key publica og') -def SshClient (btrootfsmnt): +def ssh_client (btrootfsmnt): if not os.path.exists (f'{btrootfsmnt}/root/.ssh/id_rsa'): utils.run (['ssh-keygen', '-q', '-f', f'{btrootfsmnt}/root/.ssh/id_rsa', '-N', '']) ## crea un par de claves en el chroot @@ -349,8 +349,8 @@ def SshClient (btrootfsmnt): ## TODO: exportamos la publica a los repos #cp /root/.ssh/id_rsa.pub /tmp/rsa.ogclient.pub -#FsInitrd genera un initrd. -def FsInitrd (bttargetdir, osrelease): +#move_initrd genera un initrd. +def move_initrd (bttargetdir, osrelease): #echo "cp /tmp/*-${OSRELEASE} ${BTTARGETDIR}" #cp /tmp/*-${OSRELEASE} ${BTTARGETDIR} ## esto copia algo?? @@ -373,8 +373,8 @@ def FsInitrd (bttargetdir, osrelease): for f in glob.glob (f'{bttargetdir}/oginitrd*') + glob.glob (f'{bttargetdir}/vmlinuz*'): os.chmod (f, 0o755) -#FsSqfs convierte el sistema root en sqfs -def FsSqfs (bttargetdir, btrootfsmnt): +#mksquashfs convierte el sistema root en sqfs +def mksquashfs (bttargetdir, btrootfsmnt): logger.info ('Iniciando la creación del sistema de archivos en sqfs') # si ya existe un sqfs lo renombramos @@ -387,8 +387,8 @@ def FsSqfs (bttargetdir, btrootfsmnt): utils.write_md5 (f'{bttargetdir}/ogclient.sqfs') -# IsoGenerator genera la iso del cliente -def IsoGenerator (pxepkg, isolinux_tpl, bttargetdir, nameisoclient): +# mkisofs genera la iso del cliente +def mkisofs (pxepkg, isolinux_tpl, bttargetdir, nameisoclient): #Preparamos los gestores de arranque try: os.makedirs ('/tmp/iso/isolinux', exist_ok=True) except: raise diff --git a/boottoolsfunctions/utils.py b/boottools/utils.py similarity index 100% rename from boottoolsfunctions/utils.py rename to boottools/utils.py diff --git a/03-boottoolsSoftwareInstall.py b/chroot-tasks.py similarity index 98% rename from 03-boottoolsSoftwareInstall.py rename to chroot-tasks.py index 70ea143..25de7c2 100755 --- a/03-boottoolsSoftwareInstall.py +++ b/chroot-tasks.py @@ -8,9 +8,9 @@ import sys import re import subprocess -from boottoolsfunctions import utils, apt +from boottools import utils, apt -config = utils.read_config ('boottoolsgenerator.cfg') +config = utils.read_config ('mkoglive.cfg') if config is None: sys.exit (1) debconf_settings = config['General'].get ('debconf_settings') diff --git a/boottoolsgenerator.cfg b/mkoglive.cfg similarity index 100% rename from boottoolsgenerator.cfg rename to mkoglive.cfg diff --git a/boottoolsgenerator.py b/mkoglive.py similarity index 86% rename from boottoolsgenerator.py rename to mkoglive.py index c18046e..32eeef2 100755 --- a/boottoolsgenerator.py +++ b/mkoglive.py @@ -10,7 +10,7 @@ import shutil curdir = os.path.dirname (__file__) sys.path.insert (0, curdir) -from boottoolsfunctions import utils, apt, btog +from boottools import utils, apt, btog def _logging(): #logging.root.handlers = [] @@ -58,14 +58,14 @@ def _mkrootfs(): rc = subprocess.run (f'file "{btrootfsimg}" |grep -q "partition 1 *: ID=0x83"', shell=True).returncode print (rc) if (rc): ## 'file|grep' failed - try: btog.SetFsVirtual (btrootfsimg, btrootfsimglabel, btrootfsmnt, btvirtualdisksize, bttargetdir, osarch) + try: btog.mkrootfs (btrootfsimg, btrootfsimglabel, btrootfsmnt, btvirtualdisksize, bttargetdir, osarch) except Exception as e: logger.error (str (e)) sys.exit (1) def _schroot (btrootfsimg): logger.info ('Stage 3.2 - configure schroot in the VM') - btog.SetFsAccess (btrootfsimg) + btog.configure_schroot (btrootfsimg) ## para hacer schroot --cosas, el mntpt tiene que estar desmontado ## si está montado da un pete tal que 'E: 10mount: mount: /run/schroot/mount/IMGogclient-7fbf51a2-e37e-48e5-8e5d-83f8901fc7ed: wrong fs type, bad option, bad superblock on /dev/loop1, missing codepage or helper program, or other error.' @@ -76,9 +76,9 @@ def _debootstrap(): logger.debug ('Running \'schroot --chroot IMGogclient -- stat /etc\'') cp = subprocess.run (['schroot', '--chroot', 'IMGogclient', '--', 'stat', '/etc']) if (cp.returncode): - logger.debug (f'schroot returned code "{cp.returncode}", calling btog.SetFsBase()') + logger.debug (f'schroot returned code "{cp.returncode}", calling btog.debootstrap()') _mount_rootfs() - try: btog.SetFsBase (btrootfsimg, btrootfsmnt, osarch, oscodename, oshttp) + try: btog.debootstrap (btrootfsimg, btrootfsmnt, osarch, oscodename, oshttp) except Exception as e: logger.error (str (e)) sys.exit (1) @@ -89,25 +89,25 @@ def _initramfs_version (gitrelease, osrelease, btdir): #sed -i "1 s/$/ $GITRELEASE ($OSRELEASE)/" ${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): +def _copy_og_files (btrootfsmnt, osdistrib, oscodename): _mount_rootfs() builder = '/tmp/opengnsys/oglive_builder' og_shared = '/tmp/opengnsys/shared' og_engine = '/tmp/opengnsys/engine' - btog.FsOpengnsys (builder, og_shared, og_engine, btrootfsmnt, osdistrib, oscodename) + btog.copy_og_files (builder, og_shared, og_engine, btrootfsmnt, osdistrib, oscodename) utils.umount (btrootfsmnt) def _chroot_tasks (curdir, osrelease, osarch): - logger.debug (f'running \'schroot --chroot IMGogclient -- {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:') + logger.debug (f'running \'schroot --chroot IMGogclient -- {curdir}/chroot-tasks.py --osrelease "{osrelease}" --osarch "{osarch}"\'') + stdout, _ = utils.run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/chroot-tasks.py', '--osrelease', osrelease, '--osarch', osarch]) + logger.debug (f'chroot-tasks.py stdout follows:') ## esto deja initrd.img-6.8.0-31-generic y vmlinuz-6.8.0-31-generic en /tmp for i in stdout.strip().split ('\n'): logger.debug (' ' + i) def _ssh_stuff(): _mount_rootfs() - btog.SshServer (btrootfsmnt) - btog.SshClient (btrootfsmnt) + btog.ssh_server (btrootfsmnt) + btog.ssh_client (btrootfsmnt) utils.umount (btrootfsmnt) ## el resultado es: ## - hay un nuevo par de claves en la VM /root/.ssh @@ -117,18 +117,18 @@ def _ssh_stuff(): def _mkinitrd_squashfs_isofs (bttargetdir, osrelease, btrootfsmnt, pxepkg, isolinux_tpl, nameisoclient): logger.info ('Stage 6.1 - Put initrd in place') _mount_rootfs() - btog.FsInitrd (bttargetdir, osrelease) + btog.move_initrd (bttargetdir, osrelease) logger.info ('Stage 6.2 - make squash filesystem') - btog.FsSqfs (bttargetdir, btrootfsmnt) + btog.mksquashfs (bttargetdir, btrootfsmnt) utils.umount (btrootfsmnt) logger.info ('Stage 6.3 - make iso filesystem') - btog.IsoGenerator (pxepkg, isolinux_tpl, bttargetdir, nameisoclient) + btog.mkisofs (pxepkg, isolinux_tpl, bttargetdir, nameisoclient) -config = utils.read_config ('boottoolsgenerator.cfg') +config = utils.read_config ('mkoglive.cfg') if config is None: sys.exit (1) isolinux_tpl = config['General'].get ('isolinux_template') @@ -173,7 +173,7 @@ _debootstrap() logger.info ('STAGE 4 - copy files to the rootfs') _initramfs_version (gitrelease, osrelease, btdir) -_copy_files (btrootfsmnt, osdistrib, oscodename) +_copy_og_files (btrootfsmnt, osdistrib, oscodename) logger.info ('STAGE 5 - perform tasks within the chroot') _chroot_tasks (curdir, osrelease, osarch)