cleaning up... it's feeling super complete
This commit is contained in:
parent
b3bb0391c8
commit
3d83164371
@ -50,11 +50,11 @@ def chroot(chrootdir, chroot_hostname, cmd = '/root/pre-build.sh'):
|
||||
if (chrootdir + '/tmp') not in mounts:
|
||||
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))
|
||||
real_root = os.open("/", os.O_RDONLY)
|
||||
os.chroot(chrootdir)
|
||||
os.system('locale-gen')
|
||||
os.system('locale-gen > /dev/null 2>&1')
|
||||
os.system('/root/pre-build.sh')
|
||||
os.fchdir(real_root)
|
||||
os.chroot('.')
|
||||
|
@ -16,7 +16,7 @@ if __name__ == '__main__':
|
||||
conf = host.parseConfig(host.getConfig())[1]
|
||||
prep.dirChk(conf)
|
||||
prep.buildChroot(conf['build'])
|
||||
prep.prepChroot(conf['build'], conf['bdisk'])
|
||||
prep.prepChroot(conf['build'], conf['bdisk'], conf['user'])
|
||||
arch = conf['build']['arch']
|
||||
for a in arch:
|
||||
bchroot.chroot(conf['build']['chrootdir'] + '/root.' + a, 'bdisk.square-r00t.net')
|
||||
@ -24,5 +24,6 @@ if __name__ == '__main__':
|
||||
prep.postChroot(conf['build'])
|
||||
build.genImg(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()))
|
||||
|
@ -5,6 +5,7 @@ import glob
|
||||
import subprocess
|
||||
import hashlib
|
||||
import jinja2
|
||||
import humanize
|
||||
from urllib.request import urlopen
|
||||
|
||||
|
||||
@ -38,7 +39,7 @@ def genImg(build, bdisk):
|
||||
'-comp', 'xz']
|
||||
subprocess.call(cmd, stdout = DEVNULL, stderr = subprocess.STDOUT)
|
||||
# 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['md5'][a] = hashlib.md5()
|
||||
with open(squashimg, 'rb') as f:
|
||||
@ -103,7 +104,7 @@ def genUEFI(build, bdisk):
|
||||
with open(shell1_path, 'wb+') as dl:
|
||||
dl.write(shell1_fetch.read())
|
||||
shell1_fetch.close()
|
||||
print("Now configuring UEFI bootloading...")
|
||||
print("Configuring UEFI bootloading...")
|
||||
## But wait! That's not all! We need more binaries.
|
||||
# http://blog.hansenpartnership.com/linux-foundation-secure-boot-system-released/
|
||||
shim_url = 'http://blog.hansenpartnership.com/wp-uploads/2013/'
|
||||
@ -162,7 +163,7 @@ def genUEFI(build, bdisk):
|
||||
fname = os.path.join(path, file)
|
||||
sizetotal += os.path.getsize(fname)
|
||||
# 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):
|
||||
os.remove(efiboot_img)
|
||||
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'])
|
||||
minipath = build['isodir'] + '/' + usbfile
|
||||
# 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',
|
||||
'vesamenu.c32',
|
||||
'linux.c32',
|
||||
@ -298,7 +299,7 @@ def genISO(conf):
|
||||
f.write(tpl_out)
|
||||
# And we need to build the ISO!
|
||||
# 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:
|
||||
cmd = ['/usr/bin/xorriso',
|
||||
'-as', 'mkisofs',
|
||||
@ -350,6 +351,28 @@ def genISO(conf):
|
||||
# print(line)
|
||||
#p.stdout.close()
|
||||
#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():
|
||||
# TODO: clear out all of tempdir?
|
||||
|
@ -21,7 +21,7 @@ def buildIPXE(conf):
|
||||
ipxe_src = srcdir + '/ipxe'
|
||||
ipxe_git_uri = 'git://git.ipxe.org/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
|
||||
if os.path.isdir(ipxe_src):
|
||||
shutil.rmtree(ipxe_src)
|
||||
|
@ -44,7 +44,7 @@ def downloadTarball(build):
|
||||
if build['mirrorgpgsig'] != '':
|
||||
# we don't want to futz with the user's normal gpg.
|
||||
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.
|
||||
# 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.")
|
||||
@ -102,7 +102,7 @@ def unpackTarball(tarball_path, build):
|
||||
# Make the dir if it doesn't exist
|
||||
shutil.rmtree(chrootdir, ignore_errors = 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
|
||||
for a in build['arch']:
|
||||
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)
|
||||
os.chown(chrootdir + '/root.' + a + '/' + file, 0, 0)
|
||||
|
||||
def prepChroot(build, bdisk):
|
||||
def prepChroot(build, bdisk, user):
|
||||
chrootdir = build['chrootdir']
|
||||
tempdir = build['tempdir']
|
||||
arch = build['arch']
|
||||
bdisk_repo_dir = build['basedir']
|
||||
dlpath = build['dlpath']
|
||||
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
|
||||
## 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.
|
||||
build['name'] = bdisk['name']
|
||||
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']
|
||||
if 'SUDO_USER' in os.environ:
|
||||
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.
|
||||
loader = jinja2.FileSystemLoader(templates_dir)
|
||||
env = jinja2.Environment(loader = loader)
|
||||
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:
|
||||
with open('{0}/root.{1}/root/VERSION_INFO.txt'.format(chrootdir, a), 'w+') as f:
|
||||
f.write(tpl_out)
|
||||
with open(tempdir + '/VERSION_INFO.txt', 'w+') as f:
|
||||
f.write(tpl_out)
|
||||
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:
|
||||
with open('{0}/root.{1}/root/VARS.txt'.format(chrootdir, a), 'w+') as f:
|
||||
f.write(tpl_out)
|
||||
|
@ -1,5 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
source /etc/bashrc
|
||||
source /root/.bashrc
|
||||
|
||||
# we need this fix before anything.
|
||||
dirmngr </dev/null > /dev/null 2>&1
|
||||
|
||||
|
@ -4,5 +4,5 @@ export PNAME='{{ bdisk['name'] }}'
|
||||
export DISTPUB='{{ bdisk['dev'] }}'
|
||||
export DISTDESC='{{ bdisk['desc'] }}'
|
||||
export REGUSR='{{ bdisk['name']|lower }}'
|
||||
export REGUSR_PASS='{{ bdisk['usr_pass'] }}'
|
||||
export ROOT_PASS='{{ bdisk['root_pass'] }}'
|
||||
export REGUSR_PASS='{{ user['password'] }}'
|
||||
export ROOT_PASS='{{ bdisk['root_password'] }}'
|
||||
|
@ -1,6 +1,6 @@
|
||||
Version: {{ bdisk['ver'] }}
|
||||
Build: {{ build['name'] }}
|
||||
Build: {{ build['buildnum'] }}
|
||||
Time: {{ build['time'] }}
|
||||
Machine: {{ hostname }}
|
||||
Machine: {{ hostname }} ({{ distro }})
|
||||
User: {{ build['user'] }}{% if build['realuser'] is defined and build['realuser'] > 0 %} ({{ build['realuser'] }}){% endif %}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user