refs #596 use apt modules rather than forking apt-get

pull/1/head
Natalia Serrano 2024-08-16 12:15:10 +02:00
parent 1bd24c9733
commit 9a6fecf90d
3 changed files with 21 additions and 43 deletions

View File

@ -6,31 +6,13 @@ import sys
import re
import subprocess
from boottoolsfunctions import utils
from boottoolsfunctions import utils, apt
config = utils.read_config ('boottoolsgenerator.cfg')
if config is None:
sys.exit (1)
debconf_settings = config['General'].get ('debconf_settings')
def _aptget_clean():
utils.run (['apt-get', '--yes', 'clean'])
def _aptget_autoclean():
utils.run (['apt-get', '--yes', 'autoclean'])
def _aptget_autoremove():
utils.run (['apt-get', '--yes', 'autoremove'])
def _aptget_update():
utils.run (['apt-get', '--yes', 'update'])
def _aptget_upgrade():
utils.run (['apt-get', '--yes', 'upgrade'])
def _aptget_install (pkgs, opts=[]):
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á
os.rename ('/etc/initramfs-tools/hooks/oghooks', '/etc/initramfs-tools/oghooks')
@ -60,29 +42,24 @@ def boottoolsSoftwareInstall (osarch, osrelease):
utils.run (['dpkg-divert', '--local', '--rename', '--add', '/sbin/initctl'])
os.symlink ('/bin/true', '/sbin/initctl')
_aptget_clean()
pkgs32 = []
if 'i386' != osarch:
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...
_oghook_deactivate()
_aptget_upgrade()
#_mock_mtab()
_aptget_install ([f'linux-image-{osrelease}', f'linux-headers-{osrelease}', f'linux-modules-{osrelease}', f'linux-modules-extra-{osrelease}', 'dkms', 'shim-signed', 'openssl'])
apt.install ([f'linux-image-{osrelease}', f'linux-headers-{osrelease}', f'linux-modules-{osrelease}', f'linux-modules-extra-{osrelease}', 'dkms', 'shim-signed', 'openssl'])
subprocess.run (['debconf-set-selections'], input=debconf_settings, text=True)
_aptget_install (['sshfs', 'kexec-tools'] + pkgs32, opts=['-o', 'DPkg::Options::=--force-confdef']) ## hace falta --force-confdef para evitar un tema interactivo del /etc/ssh/ssh_config
apt.install (['sshfs', 'kexec-tools'] + pkgs32, opts={'DPkg::Options::': '--force-confdef'}) ## hace falta --force-confdef para evitar un tema interactivo del /etc/ssh/ssh_config
pkgs = []
for section in config.options('Packages'):
pkgs += re.split (r'[ \n]', config['Packages'].get(section).strip())
print ('about to install these packages: "{}"'.format (' '.join (pkgs)))
## TODO don't fail when there are unknown/uninstallable packages
_aptget_install (pkgs)
apt.install (pkgs)
# Instalar módulos que algunos paquetes puedan tener pendientes de compilar.
stdout, _ = utils.run (['dkms', 'status'])
@ -96,9 +73,8 @@ def boottoolsSoftwareInstall (osarch, osrelease):
_oghook_activate()
#_restore_mtab()
_aptget_clean()
_aptget_autoclean()
_aptget_autoremove()
apt.clean()
apt.autoremove()
if __name__ == '__main__':
parser = argparse.ArgumentParser()

View File

@ -2,7 +2,7 @@
import os
import subprocess
from boottoolsfunctions import utils
from boottoolsfunctions import utils, apt
os.environ['LANGUAGE'] = os.environ['LC_ALL'] = os.environ['LANG'] = 'C'
os.chdir ('/tmp')
@ -28,9 +28,9 @@ except:
if not os.path.exists ('python-libfdisk'):
print ('python-libfdisk')
utils.run (['apt-get', '-y', 'install', 'python3-psutil', 'python3-dev', 'libfdisk-dev', 'python3-setuptools'])
apt.install (['python3-psutil', 'python3-dev', 'libfdisk-dev', 'python3-setuptools'])
utils.run (['git', 'clone', 'git://git.48k.eu/python-libfdisk'])
os.chdir ('python-libfdisk')
utils.run (['python3', 'setup.py', 'install'])
os.chdir ('..')
utils.run (['apt-get', '-y', 'remove', 'python3-dev', 'python3-setuptools'])
apt.remove (['python3-dev', 'python3-setuptools'])

View File

@ -10,7 +10,7 @@ import shutil
curdir = os.path.dirname (__file__)
sys.path.insert (0, curdir)
from boottoolsfunctions import utils, btog
from boottoolsfunctions import utils, apt, btog
def _logging():
#logging.root.handlers = []
@ -41,17 +41,18 @@ def _mount_rootfs():
logger.error ('mount failed')
sys.exit (1)
def _apt_update_upgrade():
apt.update()
apt.upgrade()
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
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:
pxepkg = 'gpxe'
else:
logger.error ('neither gpxe nor ipxe found in apt-cache')
pxepkg = None
cache = apt.cache_search (['gpxe', 'ipxe'])
if cache['gpxe']: pxepkg = 'gpxe'
if cache['ipxe']: pxepkg = 'ipxe'
if pxepkg is None:
logger.error ('neither gpxe nor ipxe found in apt cache')
sys.exit (1)
logger.info (f'PXE package is "{pxepkg}"')
return pxepkg
@ -185,6 +186,7 @@ try: utils.umount (btrootfsmnt)
except: pass
logger.info ('FASE 2 - Instalación de software adicional.')
_apt_update_upgrade()
pxepkg = _get_pxepkg()
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?