From e94fe963b913f85516fed6fe867e526db89d38f8 Mon Sep 17 00:00:00 2001 From: r00t Date: Mon, 21 Nov 2016 01:35:45 -0500 Subject: [PATCH] checkin so i can checkout RO elsewhere --- bdisk/__main__.py | 20 ++++++++++++++++++++ bdisk/{chroot.py => bchroot.py} | 7 +++++++ bdisk/host.py | 11 +++++------ bdisk/prep.py | 9 +++++++++ extra/dist.build.ini | 16 ++++++++-------- 5 files changed, 49 insertions(+), 14 deletions(-) create mode 100755 bdisk/__main__.py rename bdisk/{chroot.py => bchroot.py} (89%) diff --git a/bdisk/__main__.py b/bdisk/__main__.py new file mode 100755 index 0000000..69c8362 --- /dev/null +++ b/bdisk/__main__.py @@ -0,0 +1,20 @@ +import host +import prep +import bchroot + +# we need to: +# 1.) import the config- this gives us info about things like build paths, etc. host.parseConfig(host.getConfig()) should do this +# 2.) prep.dirChk +# 3.) prep.downloadTarball +# 4.) prep.unpackTarball +# 5.) prep.buildChroot +# 6.) prep.prepChroot +# 7.) prep.chrootCmd (TODO)- this should run the /root/pre-build.sh script +# 7.5) ....figure out a way to get those dirs to *un*mount... and only mount in 7. if they're not currently mounted. +# 8.) build.chrootClean (TODO) see jenny_craig in old bdisk. i can *probably* do this within the chroot for the most part as part of pre-build.sh +# 9.) build.genImg (TODO)- build the squashed image, etc. see will_it_blend in old bdisk +# 10.) build.genUEFI (TODO)- build the uefi binary/bootloading. see stuffy in old bdisk +# 11.) build.genISO (TODO)- build the .iso file (full boot). see yo_dj in old bdisk +# +# we also need to figure out how to implement "mentos" (old bdisk) like functionality, letting us reuse an existing chroot install if possible to save time for future builds. +# if not, though, it's no big deal. diff --git a/bdisk/chroot.py b/bdisk/bchroot.py similarity index 89% rename from bdisk/chroot.py rename to bdisk/bchroot.py index 2610c75..caa77fa 100755 --- a/bdisk/chroot.py +++ b/bdisk/bchroot.py @@ -10,6 +10,7 @@ import sys import psutil #from pychroot.base import Chroot import pychroot +import subprocess #class mountpoints(argparse.Action): # @@ -59,3 +60,9 @@ def chroot(chrootdir, chroot_hostname, cmd = '/root/pre-build.sh'): import os os.system(cmd) chroot.cleanup() + return(chrootdir, cmnts) + +#def chrootUnmount(chrootdir, cmnts): +def chrootUnmount(chrootdir): + # TODO: https://github.com/pkgcore/pychroot/issues/22 try to do this more pythonically. then we can remove subprocess + subprocess.call(['umount', '-lR', chrootdir]) diff --git a/bdisk/host.py b/bdisk/host.py index ff32dc9..87f058c 100755 --- a/bdisk/host.py +++ b/bdisk/host.py @@ -37,7 +37,8 @@ def getConfig(conf_file='/etc/bdisk/build.ini'): else: conf = conf_file if not conf: - # okay, so let's check for distributed/"blank" ini's then since we can't seem to find one. + # okay, so let's check for distributed/"blank" ini's + # since we can't seem to find one. dist_conf_paths = [re.sub('(build\.ini)','dist.\\1', s) for s in default_conf_paths] for q in dist_conf_paths: if os.path.isfile(q): @@ -53,8 +54,8 @@ def parseConfig(conf): config_dict = {s:dict(config.items(s)) for s in config.sections()} # Convert the booleans to pythonic booleans in the dict... config_dict['bdisk']['user'] = config['bdisk'].getboolean('user') - conifg_dict['build']['i_am_a_racecar'] = config['build'].getboolean('i_am_a_racecar') - conifg_dict['build']['multiarch'] = config['build'].getboolean('multiarch') + config_dict['build']['i_am_a_racecar'] = config['build'].getboolean('i_am_a_racecar') + config_dict['build']['multiarch'] = config['build'].getboolean('multiarch') for i in ('http', 'tftp', 'rsync', 'git'): config_dict['sync'][i] = config['sync'].getboolean(i) config_dict['ipxe']['iso'] = config['ipxe'].getboolean('iso') @@ -76,7 +77,7 @@ def parseConfig(conf): exit(('ERROR: {0} is not a valid host and cannot be used for rsyncing.' + 'Check your configuration.').format(config_dict['rsync']['host'])) # Validate the URI. - if config_dict['sync']['ipxe']: + if config_dict['build']['ipxe']: # so this won't validate e.g. custom LAN domains (https://pxeserver/bdisk.php). TODO. if not validators.url(config_dict['ipxe']['uri']): if not re.match('^https?://localhost(/.*)?$'): @@ -105,6 +106,4 @@ def parseConfig(conf): if not os.path.isfile(config_dict['ipxe']['ssl_ca']): exit(('ERROR: {0} is not an existing file. Check your' + 'configuration.').format(config_dict['ipxe']['ssl_ca'])) - - return(config, config_dict) diff --git a/bdisk/prep.py b/bdisk/prep.py index af4664b..0e90b81 100755 --- a/bdisk/prep.py +++ b/bdisk/prep.py @@ -17,6 +17,15 @@ def archChk(arch): else: exit("{0} is not a valid architecture. Must be one of i686 or x86_64.".format(arch)) +def dirChk(config_dict): + # Make dirs if they don't exist + for d in ('archboot', 'isodir', 'mountpt', 'srcdir', 'tempdir'): + os.makedirs(config_dict['build'][d], exists_ok = True) + # Make dirs for sync staging if we need to + for x in ('http', 'tftp'): + if config_dict['sync'][x]: + os.makedirs(config_dict[x]['path'], exist_ok = True) + def downloadTarball(arch, dlpath): # arch - should be i686 or x86_64 # returns path/filename e.g. /some/path/to/file.tar.gz diff --git a/extra/dist.build.ini b/extra/dist.build.ini index 79e5d41..44f35f3 100644 --- a/extra/dist.build.ini +++ b/extra/dist.build.ini @@ -87,7 +87,7 @@ root_password = ; yes|no ; true|false ; 1|0 -; If it is undefined/commented out, it is assumed to be no. +; If it is undefined, it is assumed to be no. user = yes @@ -167,7 +167,7 @@ mountpt = /mnt/${bdisk:uxname} ; yes|no ; true|false ; 1|0 -; If it is undefined/commented out, it is assumed to be no. +; If it is undefined, it is assumed to be no. multiarch = yes ; Would you like to enable iPXE functionality? @@ -177,7 +177,7 @@ multiarch = yes ; yes|no ; true|false ; 1|0 -; If it is undefined/commented out, it is assumed to be no. +; If it is undefined, it is assumed to be no. ipxe = yes ; This option should only be enabled if you are on a fairly @@ -190,7 +190,7 @@ ipxe = yes ; yes|no ; true|false ; 1|0 -; If it is undefined/commented out, it is assumed to be no. +; If it is undefined, it is assumed to be no. i_am_a_racecar = yes @@ -208,7 +208,7 @@ i_am_a_racecar = yes ; yes|no ; true|false ; 1|0 -; If it is undefined/commented out, it is assumed to be no. +; If it is undefined, it is assumed to be no. http = yes ; Should we generate/prepare TFTP files? @@ -219,7 +219,7 @@ http = yes ; yes|no ; true|false ; 1|0 -; If it is undefined/commented out, it is assumed to be no. +; If it is undefined, it is assumed to be no. tftp = yes ; Enable automatic Git pushing for any changes done to the @@ -230,7 +230,7 @@ tftp = yes ; yes|no ; true|false ; 1|0 -; If it is undefined/commented out, it is assumed to be no. +; If it is undefined, it is assumed to be no. git = yes ; Enable rsync pushing for the ISO (and other files, if @@ -298,7 +298,7 @@ group = root ; yes|no ; true|false ; 1|0 -; If it is undefined/commented out, it is assumed to be no. +; If it is undefined, it is assumed to be no. iso = yes ; Build a "mini-USB" image? Same concept as the ISO file