refs #596 sort phases out
parent
f04ace2b3c
commit
e6aa11e5b3
|
@ -9,6 +9,8 @@ import subprocess
|
||||||
from boottoolsfunctions import _run, _read_config
|
from boottoolsfunctions import _run, _read_config
|
||||||
|
|
||||||
config = _read_config ('boottoolsgenerator.cfg')
|
config = _read_config ('boottoolsgenerator.cfg')
|
||||||
|
if config is None:
|
||||||
|
sys.exit (1)
|
||||||
debconf_settings = config['General'].get ('debconf_settings')
|
debconf_settings = config['General'].get ('debconf_settings')
|
||||||
|
|
||||||
def _aptget_clean():
|
def _aptget_clean():
|
||||||
|
|
|
@ -5,6 +5,8 @@ import subprocess
|
||||||
from boottoolsfunctions import _run, _read_config
|
from boottoolsfunctions import _run, _read_config
|
||||||
|
|
||||||
config = _read_config ('boottoolsgenerator.cfg')
|
config = _read_config ('boottoolsgenerator.cfg')
|
||||||
|
if config is None:
|
||||||
|
sys.exit (1)
|
||||||
debconf_settings2 = config['General'].get ('debconf_settings2')
|
debconf_settings2 = config['General'].get ('debconf_settings2')
|
||||||
|
|
||||||
subprocess.run (['debconf-set-selections'], input=debconf_settings2, text=True)
|
subprocess.run (['debconf-set-selections'], input=debconf_settings2, text=True)
|
||||||
|
|
|
@ -75,7 +75,7 @@ def _umount (mntpt):
|
||||||
def _read_config (fn):
|
def _read_config (fn):
|
||||||
if not os.path.exists (fn):
|
if not os.path.exists (fn):
|
||||||
print (f'configuration file "{fn}" not found')
|
print (f'configuration file "{fn}" not found')
|
||||||
sys.exit (1)
|
return
|
||||||
config = configparser.ConfigParser (comment_prefixes='#', inline_comment_prefixes='#')
|
config = configparser.ConfigParser (comment_prefixes='#', inline_comment_prefixes='#')
|
||||||
config.read (fn)
|
config.read (fn)
|
||||||
return config
|
return config
|
||||||
|
|
|
@ -12,10 +12,6 @@ curdir = os.path.dirname (__file__)
|
||||||
sys.path.insert (0, curdir)
|
sys.path.insert (0, curdir)
|
||||||
from boottoolsfunctions import _run, _mount, _umount, _read_config, btogGetOsInfo1, btogGetOsInfo2, btogGetVar, btogSetFsVirtual, btogSetFsAccess, btogSetFsBase, boottoolsSshServer, boottoolsSshClient, btogFsInitrd, btogFsSqfs, btogIsoGenerator
|
from boottoolsfunctions import _run, _mount, _umount, _read_config, btogGetOsInfo1, btogGetOsInfo2, btogGetVar, btogSetFsVirtual, btogSetFsAccess, btogSetFsBase, boottoolsSshServer, boottoolsSshClient, btogFsInitrd, btogFsSqfs, btogIsoGenerator
|
||||||
|
|
||||||
config = _read_config ('boottoolsgenerator.cfg')
|
|
||||||
isolinux_tpl = config['General'].get ('isolinux_template')
|
|
||||||
lvl = config['General'].get ('logging_level')
|
|
||||||
|
|
||||||
def _logging():
|
def _logging():
|
||||||
#logging.root.handlers = []
|
#logging.root.handlers = []
|
||||||
|
|
||||||
|
@ -44,7 +40,7 @@ def _mount_rootfs():
|
||||||
|
|
||||||
def _get_pxepkg():
|
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
|
#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']) #>>/tmp/fase2.out
|
_run (['apt-get', 'update'])
|
||||||
acse_gpxe, _ = _run (['apt-cache', 'search', 'gpxe'])
|
acse_gpxe, _ = _run (['apt-cache', 'search', 'gpxe'])
|
||||||
acse_ipxe, _ = _run (['apt-cache', 'search', 'ipxe'])
|
acse_ipxe, _ = _run (['apt-cache', 'search', 'ipxe'])
|
||||||
if acse_ipxe:
|
if acse_ipxe:
|
||||||
|
@ -58,18 +54,24 @@ def _get_pxepkg():
|
||||||
return pxepkg
|
return pxepkg
|
||||||
|
|
||||||
def _mkrootfs():
|
def _mkrootfs():
|
||||||
|
logger.info ('Fase 3.1 Generar y formatear el disco virtual. Generar el dispositivo loop.')
|
||||||
rc = subprocess.run (f'file "{btrootfsimg}" |grep -q "partition 1 *: ID=0x83"', shell=True).returncode
|
rc = subprocess.run (f'file "{btrootfsimg}" |grep -q "partition 1 *: ID=0x83"', shell=True).returncode
|
||||||
print (rc)
|
print (rc)
|
||||||
if (rc): ## 'file|grep' failed
|
if (rc): ## 'file|grep' failed
|
||||||
try: btogSetFsVirtual (btrootfsimg, btrootfsimglabel, btrootfsmnt, btvirtualdisksize, bttargetdir, osarch)
|
try: btogSetFsVirtual (btrootfsimg, btrootfsimglabel, btrootfsmnt, btvirtualdisksize, bttargetdir, osarch)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error (str (e))
|
logger.error (str (e))
|
||||||
sys.exit (2)
|
sys.exit (1)
|
||||||
|
|
||||||
|
def _schroot (btrootfsimg):
|
||||||
|
logger.info ('Fase 3.2 - Configurar acceso schroot al Segundo Sistema de archivos (img)')
|
||||||
|
btogSetFsAccess (btrootfsimg)
|
||||||
|
|
||||||
## para hacer schroot --cosas, el mntpt tiene que estar desmontado
|
## 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.'
|
## 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.'
|
||||||
|
|
||||||
def _debootstrap():
|
def _debootstrap():
|
||||||
|
logger.info ('Fase 3.3 Generar sistema de archivos con debootstrap')
|
||||||
logger.debug ('Try creation of a file within chroot (this operation may fail with "... etc/resolv.conf: No such file or directory"--that is ok)')
|
logger.debug ('Try creation of a file within chroot (this operation may fail with "... etc/resolv.conf: No such file or directory"--that is ok)')
|
||||||
logger.debug ('Running \'schroot --chroot IMGogclient -- stat /etc\'')
|
logger.debug ('Running \'schroot --chroot IMGogclient -- stat /etc\'')
|
||||||
cp = subprocess.run (['schroot', '--chroot', 'IMGogclient', '--', 'stat', '/etc'])
|
cp = subprocess.run (['schroot', '--chroot', 'IMGogclient', '--', 'stat', '/etc'])
|
||||||
|
@ -78,17 +80,23 @@ def _debootstrap():
|
||||||
try: _mount_rootfs()
|
try: _mount_rootfs()
|
||||||
except:
|
except:
|
||||||
logger.error ('mount failed')
|
logger.error ('mount failed')
|
||||||
sys.exit (3)
|
sys.exit (1)
|
||||||
try: btogSetFsBase (btrootfsimg, btrootfsmnt, osarch, oscodename, oshttp) #>>/tmp/fase3.out
|
try: btogSetFsBase (btrootfsimg, btrootfsmnt, osarch, oscodename, oshttp)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error (str (e))
|
logger.error (str (e))
|
||||||
sys.exit (3)
|
sys.exit (1)
|
||||||
|
|
||||||
|
# Incluir revisión.
|
||||||
|
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'])
|
||||||
|
|
||||||
def _cerodos():
|
def _cerodos():
|
||||||
try: _mount_rootfs()
|
try: _mount_rootfs()
|
||||||
except:
|
except:
|
||||||
logger.error ('mount failed')
|
logger.error ('mount failed')
|
||||||
sys.exit (3)
|
sys.exit (1)
|
||||||
|
|
||||||
logger.debug (f'running \'{curdir}/02-boottoolsFsOpengnsys.py --mntpt "{btrootfsmnt}" --osdistrib "{osdistrib}" --oscodename "{oscodename}" --osrelease "{osrelease}" --osarch "{osarch}" --oshttp "{oshttp}"\'')
|
logger.debug (f'running \'{curdir}/02-boottoolsFsOpengnsys.py --mntpt "{btrootfsmnt}" --osdistrib "{osdistrib}" --oscodename "{oscodename}" --osrelease "{osrelease}" --osarch "{osarch}" --oshttp "{oshttp}"\'')
|
||||||
stdout, _ = _run ([f'{curdir}/02-boottoolsFsOpengnsys.py', '--mntpt', btrootfsmnt, '--osdistrib', osdistrib, '--oscodename', oscodename, '--osrelease', osrelease, '--osarch', osarch, '--oshttp', oshttp])
|
stdout, _ = _run ([f'{curdir}/02-boottoolsFsOpengnsys.py', '--mntpt', btrootfsmnt, '--osdistrib', osdistrib, '--oscodename', oscodename, '--osrelease', osrelease, '--osarch', osarch, '--oshttp', oshttp])
|
||||||
|
@ -98,12 +106,14 @@ def _cerodos():
|
||||||
_umount (btrootfsmnt)
|
_umount (btrootfsmnt)
|
||||||
|
|
||||||
def _chroot_cerotres():
|
def _chroot_cerotres():
|
||||||
|
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}"\'')
|
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, _ = _run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/03-boottoolsSoftwareInstall.py', '--osrelease', osrelease, '--osarch', osarch])
|
||||||
logger.debug (f'03-boottoolsSoftwareInstall stdout follows:')
|
logger.debug (f'03-boottoolsSoftwareInstall stdout follows:')
|
||||||
for i in stdout.strip().split('\n'): logger.debug (' ' + i)
|
for i in stdout.strip().split('\n'): logger.debug (' ' + i)
|
||||||
|
|
||||||
def _chroot_cerocuatro():
|
def _chroot_cerocuatro():
|
||||||
|
logger.info ('Fase 5.2 compilar software.')
|
||||||
logger.debug ('running \'schroot --chroot IMGogclient -- {}/04-boottoolsSoftwareCompile.py\'')
|
logger.debug ('running \'schroot --chroot IMGogclient -- {}/04-boottoolsSoftwareCompile.py\'')
|
||||||
#cd /
|
#cd /
|
||||||
stdout, _ = _run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/04-boottoolsSoftwareCompile.py'])
|
stdout, _ = _run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/04-boottoolsSoftwareCompile.py'])
|
||||||
|
@ -112,10 +122,11 @@ def _chroot_cerocuatro():
|
||||||
for i in stdout.strip().split('\n'): logger.debug (' ' + i)
|
for i in stdout.strip().split('\n'): logger.debug (' ' + i)
|
||||||
|
|
||||||
def _ssh_stuff():
|
def _ssh_stuff():
|
||||||
|
logger.info ('Fase 6.1 Configurar ssh')
|
||||||
try: _mount_rootfs()
|
try: _mount_rootfs()
|
||||||
except:
|
except:
|
||||||
logger.error ('mount failed')
|
logger.error ('mount failed')
|
||||||
sys.exit (3)
|
sys.exit (1)
|
||||||
|
|
||||||
#cd /
|
#cd /
|
||||||
#schroot --chroot IMGogclient -- /usr/bin/boot-tools/boottoolsSshServer.sh ## no necesita chroot
|
#schroot --chroot IMGogclient -- /usr/bin/boot-tools/boottoolsSshServer.sh ## no necesita chroot
|
||||||
|
@ -133,12 +144,14 @@ def _ssh_stuff():
|
||||||
## - las dos claves públicas (una de cada par) están autorizadan en el rootfs /var/lib/tftpboot/ogclient/ogclientmount/root/.ssh/authorized_keys
|
## - 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 _chroot_cerocinco():
|
def _chroot_cerocinco():
|
||||||
|
logger.info ('Fase 6.2 Configurar las locales')
|
||||||
logger.debug (f'running \'schroot --chroot IMGogclient -- {curdir}/05-boottoolsFsLocales.py\'')
|
logger.debug (f'running \'schroot --chroot IMGogclient -- {curdir}/05-boottoolsFsLocales.py\'')
|
||||||
stdout, _ = _run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/05-boottoolsFsLocales.py'])
|
stdout, _ = _run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/05-boottoolsFsLocales.py'])
|
||||||
logger.debug (f'05-boottoolsFsLocales stdout follows:')
|
logger.debug (f'05-boottoolsFsLocales stdout follows:')
|
||||||
for i in stdout.strip().split('\n'): logger.debug (' ' + i)
|
for i in stdout.strip().split('\n'): logger.debug (' ' + i)
|
||||||
|
|
||||||
def _chroot_ceroseis():
|
def _chroot_ceroseis():
|
||||||
|
logger.info ('Fase 6.3 Crear initrd') ## what??
|
||||||
#cd /
|
#cd /
|
||||||
#schroot -c IMGogclient -- /usr/bin/boot-tools/boottoolsInitrdGenerate.sh
|
#schroot -c IMGogclient -- /usr/bin/boot-tools/boottoolsInitrdGenerate.sh
|
||||||
logger.debug (f'running \'schroot --chroot IMGogclient -- {curdir}/06-boottoolsInitrdGenerate.py --osrelease "{osrelease}"\'')
|
logger.debug (f'running \'schroot --chroot IMGogclient -- {curdir}/06-boottoolsInitrdGenerate.py --osrelease "{osrelease}"\'')
|
||||||
|
@ -147,6 +160,25 @@ def _chroot_ceroseis():
|
||||||
for i in stdout.strip().split('\n'): logger.debug (' ' + i)
|
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
|
## esto deja initrd.img-6.8.0-31-generic y vmlinuz-6.8.0-31-generic en /tmp
|
||||||
|
|
||||||
|
def _mkinitrd (bttargetdir, osrelease):
|
||||||
|
logger.info ('Fase 7.1 Generar el initrd') ## what??
|
||||||
|
btogFsInitrd (bttargetdir, osrelease)
|
||||||
|
|
||||||
|
def _mksquashfs (bttargetdir, btrootfsmnt):
|
||||||
|
logger.info ('Fase 7.2 Generar fichero sqfs a partir del fichero img')
|
||||||
|
btogFsSqfs (bttargetdir, btrootfsmnt)
|
||||||
|
|
||||||
|
def _mkisofs (pxepkg, isolinux_tpl, bttargetdir, nameisoclient):
|
||||||
|
logger.info ('Fase 7.3 Generar la ISO')
|
||||||
|
btogIsoGenerator (pxepkg, isolinux_tpl, bttargetdir, nameisoclient)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
config = _read_config ('boottoolsgenerator.cfg')
|
||||||
|
if config is None:
|
||||||
|
sys.exit (1)
|
||||||
|
isolinux_tpl = config['General'].get ('isolinux_template')
|
||||||
|
lvl = config['General'].get ('logging_level')
|
||||||
|
|
||||||
logger = _logging()
|
logger = _logging()
|
||||||
type_client = sys.argv[1] if len(sys.argv)>1 else 'host'
|
type_client = sys.argv[1] if len(sys.argv)>1 else 'host'
|
||||||
|
@ -173,62 +205,35 @@ try: _umount (btrootfsmnt)
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
logger.info ('FASE 2 - Instalación de software adicional.')
|
logger.info ('FASE 2 - Instalación de software adicional.')
|
||||||
|
|
||||||
pxepkg = _get_pxepkg()
|
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?
|
_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))')
|
logger.info ('FASE 3 - Creación del Sistema raiz RootFS (Segundo Sistema archivos (img))')
|
||||||
logger.info ('Fase 3.1 Generar y formatear el disco virtual. Generar el dispositivo loop.')
|
|
||||||
_mkrootfs()
|
_mkrootfs()
|
||||||
|
_schroot (btrootfsimg)
|
||||||
logger.info ('Fase 3.2 - Configurar acceso schroot al Segundo Sistema de archivos (img)')
|
|
||||||
btogSetFsAccess (btrootfsimg)
|
|
||||||
|
|
||||||
logger.info ('Fase 3.3 Generar sistema de archivos con debootstrap')
|
|
||||||
_debootstrap()
|
_debootstrap()
|
||||||
|
|
||||||
logger.info ('FASE 4 - Incorporando ficheros OpenGnsys al sistema raíz rootfs')
|
logger.info ('FASE 4 - Incorporando ficheros OpenGnsys al sistema raíz rootfs')
|
||||||
|
_initramfs_version (gitrelease, osrelease, btdir)
|
||||||
# Incluir revisión.
|
|
||||||
## 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'])
|
|
||||||
|
|
||||||
_cerodos()
|
_cerodos()
|
||||||
|
|
||||||
logger.info ('FASE 5 - Instalar software')
|
logger.info ('FASE 5 - Instalar software')
|
||||||
logger.info ('Fase 5.1 instalar paquetes deb con apt-get')
|
|
||||||
_chroot_cerotres()
|
_chroot_cerotres()
|
||||||
|
|
||||||
logger.info ('Fase 5.2 compilar software.')
|
|
||||||
_chroot_cerocuatro()
|
_chroot_cerocuatro()
|
||||||
|
|
||||||
|
|
||||||
logger.info ('FASE 6 - Personalizar el sistema creado')
|
logger.info ('FASE 6 - Personalizar el sistema creado')
|
||||||
logger.info ('Fase 6.1 Incorporar la clave publica del servidor')
|
|
||||||
logger.info ('Fase 6.2 Incorporar la clave publica del propio cliente')
|
|
||||||
_ssh_stuff()
|
_ssh_stuff()
|
||||||
|
|
||||||
logger.info ('Fase 6.3 Configurando las locales')
|
|
||||||
_chroot_cerocinco()
|
_chroot_cerocinco()
|
||||||
|
|
||||||
_chroot_ceroseis()
|
_chroot_ceroseis()
|
||||||
|
|
||||||
logger.info ('FASE 7 - Generar distribucion')
|
logger.info ('FASE 7 - Generar distribucion')
|
||||||
logger.info ('Fase 7.1 Generar el initrd')
|
_mkinitrd (bttargetdir, osrelease)
|
||||||
btogFsInitrd (bttargetdir, osrelease)
|
|
||||||
|
|
||||||
|
|
||||||
logger.info ('Fase 7.2 Generar fichero sqfs a partir del fichero img')
|
|
||||||
try: _mount_rootfs()
|
try: _mount_rootfs()
|
||||||
except:
|
except:
|
||||||
logger.error ('mount failed')
|
logger.error ('mount failed')
|
||||||
sys.exit (3)
|
sys.exit (1)
|
||||||
btogFsSqfs (bttargetdir, btrootfsmnt)
|
_mksquashfs (bttargetdir, btrootfsmnt)
|
||||||
_umount (btrootfsmnt)
|
_umount (btrootfsmnt)
|
||||||
|
_mkisofs (pxepkg, isolinux_tpl, bttargetdir, nameisoclient)
|
||||||
logger.info ('Fase 7.3 Generar la ISO')
|
|
||||||
btogIsoGenerator (pxepkg, isolinux_tpl, bttargetdir, nameisoclient)
|
|
||||||
|
|
||||||
logger.info ('OpenGnsys installation finished')
|
logger.info ('OpenGnsys installation finished')
|
||||||
|
|
Loading…
Reference in New Issue