refs #596 use sys.exit(), improve logging, remove uninstallable packages

pybuilder
Natalia Serrano 2024-08-13 09:42:36 +02:00
parent 8419065f0b
commit a193b678c0
4 changed files with 39 additions and 15 deletions

View File

@ -2,6 +2,7 @@
import argparse
import os
import sys
import re
import subprocess
import configparser
@ -9,6 +10,9 @@ import configparser
from boottoolsfunctions import _run
config = configparser.ConfigParser (inline_comment_prefixes='#')
if not os.path.exists ('boottoolsgenerator.cfg'): ## si pongo uno que no existe,
print ('configuration file "boottoolsgenerator.cfg" not found') ## este error no llega al caller...
sys.exit (1)
config.read ('boottoolsgenerator.cfg')
debconf_settings = """

View File

@ -12,8 +12,14 @@ logger = logging.getLogger ('boottools')
def _run (args):
cp = subprocess.run (args, text=True, capture_output=True)
if cp.returncode:
logger.error ('stdout "{}" stderr "{}"'.format (cp.stdout, cp.stderr))
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()

View File

@ -1,23 +1,27 @@
[Packages]
basic =
dialog man-db fbset gdebi-core bash-static busybox-static locales lshw gawk git python-openssl python php-cli dmidecode rpm sqlite3 os-prober moreutils jq
dialog man-db fbset gdebi-core bash-static busybox-static locales lshw gawk git python3-openssl python3 php-cli dmidecode rpm sqlite3 os-prober moreutils jq
#console-data # ogLive anterior a Ubuntu 20.04
#subversion # ogLive anterior a Ubuntu 18.04
#php5-cli # ogLive anterior a Ubuntu 16.04
#realpath # ogLive hasta Ubuntu 16.04
#zypper # PROBAR
cloning = fsarchiver pv pxe-kexec mbuffer parted gdisk chntpw clonezilla registry-tools reglookup libparse-win32registry-perl libwin-hivex-perl grokevt libhivex0 libhivex-bin rsync
cloning = fsarchiver pv
#pxe-kexec # ubuntu noble: Unable to locate package
mbuffer parted gdisk chntpw clonezilla registry-tools reglookup libparse-win32registry-perl libwin-hivex-perl grokevt libhivex0 libhivex-bin rsync
compile =
build-essential libattr1 libattr1-dev uuid-dev attr make m4 gettext libmhash-dev
#libattr* # Satura el tamaño del archivo en Ubuntu 15.04
#libattr* # Satura el tamaño del archivo en Ubuntu 15.04
compressor = lzma zip unzip gzip lzop pigz pbzip2 lbzip2 rzip p7zip-full
filesystem_local =
squashfs-tools unionfs-fuse ntfs-3g dosfstools fatresize exfat-utils dmraid dmsetup lvm2 e2fsprogs
squashfs-tools unionfs-fuse ntfs-3g dosfstools fatresize
#exfat-utils # ubuntu noble: has no installation candidate
dmraid dmsetup lvm2 e2fsprogs
jfsutils reiserfsprogs reiser4progs xfsprogs mhddfs hfsplus hfsprogs hfsutils nilfs-tools vmfs-tools
btrfs-progs # ogLive a partir de Ubuntu 20.04
zfsutils-linux # ogLive a partir de Ubuntu 16.04
@ -34,11 +38,13 @@ filesystem_local =
filesystem_remote =
sshfs cifs-utils smbclient open-iscsi openssh-server
#nfs-common # Provoca error de instalación en Ubuntu 15.04
#bittornado # ogLive anterior a Ubuntu 20.04
#bittornado # ogLive anterior a Ubuntu 20.04
monitoring = htop ncdu bwbar bmon iftop ifstat dstat hdparm sdparm blktool testdisk
networking = netpipes curl wget tftp dnsutils trickle lighttpd ethtool ssmping tcpdump nmap arping ntpdate ctorrent udpcast #iptraf
networking = netpipes curl wget tftp-hpa dnsutils
#trickle # ubuntu noble: has no installation candidate
lighttpd ethtool ssmping tcpdump nmap arping ntpdate ctorrent udpcast #iptraf
testing =
screen schroot xmlstarlet

View File

@ -12,7 +12,15 @@ curdir = os.path.dirname (__file__)
sys.path.insert (0, curdir)
from boottoolsfunctions import _run, _is_mounted, btogGetOsInfo1, btogGetOsInfo2, btogGetVar, btogSetFsVirtual, btogSetFsAccess, btogSetFsBase
logging.basicConfig (filename='/tmp/boot-tools_installation.log', filemode='a', format='%(levelname)s %(asctime)s (%(funcName)s) %(message)s', level=logging.INFO)
#logging.root.handlers = []
logging.basicConfig (
format='%(levelname)s %(asctime)s (%(funcName)s) %(message)s',
level=logging.INFO,
handlers = [
logging.FileHandler ('/tmp/boot-tools_installation.log'),
logging.StreamHandler (sys.stdout),
],
)
logger = logging.getLogger ('boottools')
#config = configparser.ConfigParser()
@ -33,9 +41,9 @@ type_client = sys.argv[1] if len(sys.argv)>1 else 'host'
if os.getuid():
logger.error ('ERROR: this program must run under root privileges!!')
os._exit (1)
sys.exit (1)
os.chdir ('/tmp')
#os.chdir ('/tmp')
#for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done
#for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done
@ -63,7 +71,7 @@ elif acse_gpxe:
pxepkg = 'gpxe'
else:
logger.error ('neither gpxe nor ipxe found in apt-cache')
os._exit (1)
sys.exit (1)
logger.info ('PXE package is "{}"'.format (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]) #>>/tmp/fase2.out
@ -78,7 +86,7 @@ if (rc): ## 'file|grep' failed
try: btogSetFsVirtual (btrootfsimg, btrootfsimglabel, btrootfsmnt, btvirtualdisksize, bttargetdir, osarch)
except Exception as e:
logger.error (str (e))
os._exit (2)
sys.exit (2)
#echo ================= nati after btogSetFsVirtual; ls -la /opt/opengnsys/tftpboot/ogclient/
logger.info ('Fase 3.2 - Configurar acceso schroot al Segundo Sistema de archivos (img)')
@ -97,11 +105,11 @@ if (cp.returncode):
try: _run (['mount', btrootfsimg, btrootfsmnt, '-o', 'loop,offset=32256'])
except:
logger.error ('mount failed')
os._exit (3)
sys.exit (3)
try: btogSetFsBase (btrootfsimg, btrootfsmnt, osarch, oscodename, oshttp) #>>/tmp/fase3.out
except Exception as e:
logger.error (str (e))
os._exit (3)
sys.exit (3)
#echo ================= nati after fase 3; ls -la /opt/opengnsys/tftpboot/ogclient/
###########################################################################
@ -129,7 +137,7 @@ if (not _is_mounted (btrootfsmnt)):
try: _run (['mount', btrootfsimg, btrootfsmnt, '-o', 'loop,offset=32256'])
except:
logger.error ('mount failed')
os._exit (3)
sys.exit (3)
logger.debug ('running \'{}/02-boottoolsFsOpengnsys.py --mntpt "{}" --osdistrib "{}" --oscodename "{}" --osrelease "{}" --osarch "{}" --oshttp "{}"\''.format (curdir, btrootfsmnt, osdistrib, oscodename, osrelease, osarch, oshttp))
stdout, _ = _run (['{}/02-boottoolsFsOpengnsys.py'.format (curdir), '--mntpt', btrootfsmnt, '--osdistrib', osdistrib, '--oscodename', oscodename, '--osrelease', osrelease, '--osarch', osarch, '--oshttp', oshttp])