cleaning up... it's feeling super complete

This commit is contained in:
brent s. 2016-12-01 23:42:27 -05:00
parent b3bb0391c8
commit 3d83164371
8 changed files with 53 additions and 24 deletions

View File

@ -50,11 +50,11 @@ def chroot(chrootdir, chroot_hostname, cmd = '/root/pre-build.sh'):
if (chrootdir + '/tmp') not in mounts: if (chrootdir + '/tmp') not in mounts:
subprocess.call(['/bin/mount', '-t', 'tmpfs', '-o', 'mode=1777,strictatime,nodev,nosuid', 'tmp', chrootdir + '/tmp']) subprocess.call(['/bin/mount', '-t', 'tmpfs', '-o', 'mode=1777,strictatime,nodev,nosuid', 'tmp', chrootdir + '/tmp'])


print("Now performing '{0}' in chroot for {1}...".format(cmd, chrootdir)) print("Performing '{0}' in chroot for {1}...".format(cmd, chrootdir))
print("You can view the progress via:\n\n\ttail -f {0}/var/log/chroot_install.log\n".format(chrootdir)) print("You can view the progress via:\n\n\ttail -f {0}/var/log/chroot_install.log\n".format(chrootdir))
real_root = os.open("/", os.O_RDONLY) real_root = os.open("/", os.O_RDONLY)
os.chroot(chrootdir) os.chroot(chrootdir)
os.system('locale-gen') os.system('locale-gen > /dev/null 2>&1')
os.system('/root/pre-build.sh') os.system('/root/pre-build.sh')
os.fchdir(real_root) os.fchdir(real_root)
os.chroot('.') os.chroot('.')

View File

@ -16,7 +16,7 @@ if __name__ == '__main__':
conf = host.parseConfig(host.getConfig())[1] conf = host.parseConfig(host.getConfig())[1]
prep.dirChk(conf) prep.dirChk(conf)
prep.buildChroot(conf['build']) prep.buildChroot(conf['build'])
prep.prepChroot(conf['build'], conf['bdisk']) prep.prepChroot(conf['build'], conf['bdisk'], conf['user'])
arch = conf['build']['arch'] arch = conf['build']['arch']
for a in arch: for a in arch:
bchroot.chroot(conf['build']['chrootdir'] + '/root.' + a, 'bdisk.square-r00t.net') bchroot.chroot(conf['build']['chrootdir'] + '/root.' + a, 'bdisk.square-r00t.net')
@ -24,5 +24,6 @@ if __name__ == '__main__':
prep.postChroot(conf['build']) prep.postChroot(conf['build'])
build.genImg(conf['build'], conf['bdisk']) build.genImg(conf['build'], conf['bdisk'])
build.genUEFI(conf['build'], conf['bdisk']) build.genUEFI(conf['build'], conf['bdisk'])
build.genISO(conf) fulliso = build.geniso(conf)
build.displayStats(fulliso)
print('Finished successfully at {0}.'.format(datetime.datetime.now())) print('Finished successfully at {0}.'.format(datetime.datetime.now()))

View File

@ -5,6 +5,7 @@ import glob
import subprocess import subprocess
import hashlib import hashlib
import jinja2 import jinja2
import humanize
from urllib.request import urlopen from urllib.request import urlopen




@ -38,7 +39,7 @@ def genImg(build, bdisk):
'-comp', 'xz'] '-comp', 'xz']
subprocess.call(cmd, stdout = DEVNULL, stderr = subprocess.STDOUT) subprocess.call(cmd, stdout = DEVNULL, stderr = subprocess.STDOUT)
# Generate the checksum files # Generate the checksum files
print("Now generating SHA256 and MD5 hash checksum files for {0}. Please wait...".format(squashimg)) print("Generating SHA256 and MD5 hash checksum files for {0}. Please wait...".format(squashimg))
hashes['sha256'][a] = hashlib.sha256() hashes['sha256'][a] = hashlib.sha256()
hashes['md5'][a] = hashlib.md5() hashes['md5'][a] = hashlib.md5()
with open(squashimg, 'rb') as f: with open(squashimg, 'rb') as f:
@ -103,7 +104,7 @@ def genUEFI(build, bdisk):
with open(shell1_path, 'wb+') as dl: with open(shell1_path, 'wb+') as dl:
dl.write(shell1_fetch.read()) dl.write(shell1_fetch.read())
shell1_fetch.close() shell1_fetch.close()
print("Now configuring UEFI bootloading...") print("Configuring UEFI bootloading...")
## But wait! That's not all! We need more binaries. ## But wait! That's not all! We need more binaries.
# http://blog.hansenpartnership.com/linux-foundation-secure-boot-system-released/ # http://blog.hansenpartnership.com/linux-foundation-secure-boot-system-released/
shim_url = 'http://blog.hansenpartnership.com/wp-uploads/2013/' shim_url = 'http://blog.hansenpartnership.com/wp-uploads/2013/'
@ -162,7 +163,7 @@ def genUEFI(build, bdisk):
fname = os.path.join(path, file) fname = os.path.join(path, file)
sizetotal += os.path.getsize(fname) sizetotal += os.path.getsize(fname)
# And now we create the file... # And now we create the file...
print("Now creating a {0} bytes EFI ESP image at {1}. Please wait...".format(sizetotal, efiboot_img)) print("Creating a {0} bytes EFI ESP image at {1}. Please wait...".format(sizetotal, efiboot_img))
if os.path.isfile(efiboot_img): if os.path.isfile(efiboot_img):
os.remove(efiboot_img) os.remove(efiboot_img)
with open(efiboot_img, 'wb+') as f: with open(efiboot_img, 'wb+') as f:
@ -269,7 +270,7 @@ def genISO(conf):
usbfile = '{0}-{1}-mini.usb.img'.format(bdisk['uxname'], bdisk['ver']) usbfile = '{0}-{1}-mini.usb.img'.format(bdisk['uxname'], bdisk['ver'])
minipath = build['isodir'] + '/' + usbfile minipath = build['isodir'] + '/' + usbfile
# Copy isolinux files # Copy isolinux files
print("Now staging some files for ISO preparation. Please wait...") print("Staging some files for ISO preparation. Please wait...")
isolinux_files = ['isolinux.bin', isolinux_files = ['isolinux.bin',
'vesamenu.c32', 'vesamenu.c32',
'linux.c32', 'linux.c32',
@ -298,7 +299,7 @@ def genISO(conf):
f.write(tpl_out) f.write(tpl_out)
# And we need to build the ISO! # And we need to build the ISO!
# TODO: only include UEFI support if we actually built it! # TODO: only include UEFI support if we actually built it!
print("Now generating the full ISO at {0}. Please wait.".format(isopath)) print("Generating the full ISO at {0}. Please wait.".format(isopath))
if efi: if efi:
cmd = ['/usr/bin/xorriso', cmd = ['/usr/bin/xorriso',
'-as', 'mkisofs', '-as', 'mkisofs',
@ -350,6 +351,28 @@ def genISO(conf):
# print(line) # print(line)
#p.stdout.close() #p.stdout.close()
#p.wait() #p.wait()
# Get size of ISO
iso = {}
iso['sha'] = hashlib.sha256()
with open(isopath, 'rb') as f:
while True:
stream = f.read(65536) # 64kb chunks
if not stream:
break
iso['sha'].update(stream)
iso['sha'] = iso['sha'].hexdigest()
iso['file'] = isopath
iso['size'] = humanize.naturalsize(os.path.getsize(isopath))
iso['type'] = 'Full'
iso['fmt'] = 'Hybrid ISO'
return(iso)

def displayStats(iso):
print('== {0} {1} =='.format(iso['type'], iso['fmt']))
print('Size: {0}'.format(iso['size']))
print('SHA256: {0}'.format(iso['sha']))
print('Location: {0}'.format(iso['file']))
print()


def cleanUp(): def cleanUp():
# TODO: clear out all of tempdir? # TODO: clear out all of tempdir?

View File

@ -21,7 +21,7 @@ def buildIPXE(conf):
ipxe_src = srcdir + '/ipxe' ipxe_src = srcdir + '/ipxe'
ipxe_git_uri = 'git://git.ipxe.org/ipxe.git' ipxe_git_uri = 'git://git.ipxe.org/ipxe.git'
patches_git_uri = 'https://github.com/eworm-de/ipxe.git' patches_git_uri = 'https://github.com/eworm-de/ipxe.git'
print('Now building iPXE in {0}. Please wait...'.format(ipxe_src)) print('Building iPXE in {0}. Please wait...'.format(ipxe_src))
# Get the source and apply some cherrypicks # Get the source and apply some cherrypicks
if os.path.isdir(ipxe_src): if os.path.isdir(ipxe_src):
shutil.rmtree(ipxe_src) shutil.rmtree(ipxe_src)

View File

@ -44,7 +44,7 @@ def downloadTarball(build):
if build['mirrorgpgsig'] != '': if build['mirrorgpgsig'] != '':
# we don't want to futz with the user's normal gpg. # we don't want to futz with the user's normal gpg.
gpg = gnupg.GPG(gnupghome = dlpath + '/.gnupg') gpg = gnupg.GPG(gnupghome = dlpath + '/.gnupg')
print("\nNow generating a GPG key. Please wait...") print("\nGenerating a GPG key. Please wait...")
# python-gnupg 0.3.9 spits this error in Arch. it's harmless, but ugly af. # python-gnupg 0.3.9 spits this error in Arch. it's harmless, but ugly af.
# TODO: remove this when the error doesn't happen anymore. # TODO: remove this when the error doesn't happen anymore.
print("If you see a \"ValueError: Unknown status message: 'KEY_CONSIDERED'\" error, it can be safely ignored.") print("If you see a \"ValueError: Unknown status message: 'KEY_CONSIDERED'\" error, it can be safely ignored.")
@ -102,7 +102,7 @@ def unpackTarball(tarball_path, build):
# Make the dir if it doesn't exist # Make the dir if it doesn't exist
shutil.rmtree(chrootdir, ignore_errors = True) shutil.rmtree(chrootdir, ignore_errors = True)
os.makedirs(chrootdir, exist_ok = True) os.makedirs(chrootdir, exist_ok = True)
print("Now extracting the tarball(s). Please wait...") print("Extracting the tarball(s). Please wait...")
# Open and extract the tarball # Open and extract the tarball
for a in build['arch']: for a in build['arch']:
tar = tarfile.open(tarball_path[a], 'r:gz') tar = tarfile.open(tarball_path[a], 'r:gz')
@ -154,18 +154,15 @@ def buildChroot(build):
shutil.copy2(extradir + '/pre-build.d/' + a + '/' + file, chrootdir + '/root.' + a + '/' + file, follow_symlinks = False) shutil.copy2(extradir + '/pre-build.d/' + a + '/' + file, chrootdir + '/root.' + a + '/' + file, follow_symlinks = False)
os.chown(chrootdir + '/root.' + a + '/' + file, 0, 0) os.chown(chrootdir + '/root.' + a + '/' + file, 0, 0)


def prepChroot(build, bdisk): def prepChroot(build, bdisk, user):
chrootdir = build['chrootdir'] chrootdir = build['chrootdir']
tempdir = build['tempdir'] tempdir = build['tempdir']
arch = build['arch'] arch = build['arch']
bdisk_repo_dir = build['basedir'] bdisk_repo_dir = build['basedir']
dlpath = build['dlpath']
templates_dir = bdisk_repo_dir + '/extra/templates' templates_dir = bdisk_repo_dir + '/extra/templates'
build = {} #build = {} # why was this here?
## let's prep some variables to write out the version info.txt ## let's prep some variables to write out the version info.txt
## get the git tag and short commit hash
#repo = git.Repo(bdisk_repo_dir)
#refs = repo.git.describe(repo.head.commit).split('-')
#build['ver'] = refs[0] + '-' + refs[2]
# and these should be passed in from the args, from the most part. # and these should be passed in from the args, from the most part.
build['name'] = bdisk['name'] build['name'] = bdisk['name']
build['time'] = datetime.datetime.utcnow().strftime("%a %b %d %H:%M:%S UTC %Y") build['time'] = datetime.datetime.utcnow().strftime("%a %b %d %H:%M:%S UTC %Y")
@ -173,18 +170,23 @@ def prepChroot(build, bdisk):
build['user'] = os.environ['USER'] build['user'] = os.environ['USER']
if 'SUDO_USER' in os.environ: if 'SUDO_USER' in os.environ:
build['realuser'] = os.environ['SUDO_USER'] build['realuser'] = os.environ['SUDO_USER']
if os.path.isfile(dlpath + '/buildnum'):
with open(dlpath + '/buildnum') as f:
build['buildnum'] = int(f.readlines())
else:
build['buildnum'] = 0
# and now that we have that dict, let's write out the VERSION_INFO.txt file. # and now that we have that dict, let's write out the VERSION_INFO.txt file.
loader = jinja2.FileSystemLoader(templates_dir) loader = jinja2.FileSystemLoader(templates_dir)
env = jinja2.Environment(loader = loader) env = jinja2.Environment(loader = loader)
tpl = env.get_template('VERSION_INFO.txt.j2') tpl = env.get_template('VERSION_INFO.txt.j2')
tpl_out = tpl.render(build = build, bdisk = bdisk, hostname = host.getHostname()) tpl_out = tpl.render(build = build, bdisk = bdisk, hostname = host.getHostname(), distro = host.getOS())
for a in arch: for a in arch:
with open('{0}/root.{1}/root/VERSION_INFO.txt'.format(chrootdir, a), 'w+') as f: with open('{0}/root.{1}/root/VERSION_INFO.txt'.format(chrootdir, a), 'w+') as f:
f.write(tpl_out) f.write(tpl_out)
with open(tempdir + '/VERSION_INFO.txt', 'w+') as f: with open(tempdir + '/VERSION_INFO.txt', 'w+') as f:
f.write(tpl_out) f.write(tpl_out)
tpl = env.get_template('VARS.txt.j2') tpl = env.get_template('VARS.txt.j2')
tpl_out = tpl.render(bdisk = bdisk) tpl_out = tpl.render(bdisk = bdisk, user = user)
for a in arch: for a in arch:
with open('{0}/root.{1}/root/VARS.txt'.format(chrootdir, a), 'w+') as f: with open('{0}/root.{1}/root/VARS.txt'.format(chrootdir, a), 'w+') as f:
f.write(tpl_out) f.write(tpl_out)

View File

@ -1,5 +1,8 @@
#!/bin/bash #!/bin/bash


source /etc/bashrc
source /root/.bashrc

# we need this fix before anything. # we need this fix before anything.
dirmngr </dev/null > /dev/null 2>&1 dirmngr </dev/null > /dev/null 2>&1



View File

@ -4,5 +4,5 @@ export PNAME='{{ bdisk['name'] }}'
export DISTPUB='{{ bdisk['dev'] }}' export DISTPUB='{{ bdisk['dev'] }}'
export DISTDESC='{{ bdisk['desc'] }}' export DISTDESC='{{ bdisk['desc'] }}'
export REGUSR='{{ bdisk['name']|lower }}' export REGUSR='{{ bdisk['name']|lower }}'
export REGUSR_PASS='{{ bdisk['usr_pass'] }}' export REGUSR_PASS='{{ user['password'] }}'
export ROOT_PASS='{{ bdisk['root_pass'] }}' export ROOT_PASS='{{ bdisk['root_password'] }}'

View File

@ -1,6 +1,6 @@
Version: {{ bdisk['ver'] }} Version: {{ bdisk['ver'] }}
Build: {{ build['name'] }} Build: {{ build['buildnum'] }}
Time: {{ build['time'] }} Time: {{ build['time'] }}
Machine: {{ hostname }} Machine: {{ hostname }} ({{ distro }})
User: {{ build['user'] }}{% if build['realuser'] is defined and build['realuser'] > 0 %} ({{ build['realuser'] }}){% endif %} User: {{ build['user'] }}{% if build['realuser'] is defined and build['realuser'] > 0 %} ({{ build['realuser'] }}){% endif %}