2016-11-26 22:05:53 -05:00
#!/bin/env python3
2017-09-30 05:15:52 -04:00
import argparse
2016-11-21 03:41:22 -05:00
import host
import prep
import bchroot
2016-11-26 22:05:53 -05:00
import build
2016-12-01 12:47:23 -05:00
import datetime
2016-12-09 12:41:17 -05:00
import bSSL
import ipxe
2016-12-09 22:16:50 -05:00
import bsync
2016-12-16 04:28:53 -05:00
import bGPG
2017-04-11 01:34:14 -04:00
import os
2016-11-21 03:41:22 -05:00
2017-09-30 05:15:52 -04:00
def bdisk ( args ) :
# 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.
2017-04-11 01:34:14 -04:00
if os . getuid ( ) != 0 :
exit ( ' {0} : ERROR: BDisk *must* be run as the root user or with sudo! ' . format ( datetime . datetime . now ( ) ) )
2016-12-03 06:07:41 -05:00
print ( ' {0} : Starting. ' . format ( datetime . datetime . now ( ) ) )
2017-09-30 05:15:52 -04:00
conf = host . parseConfig ( host . getConfig ( conf_file = args [ ' buildini ' ] ) ) [ 1 ]
2016-11-21 03:41:22 -05:00
prep . dirChk ( conf )
2016-12-16 04:28:53 -05:00
conf [ ' gpgobj ' ] = bGPG . genGPG ( conf )
2016-12-17 01:07:50 -05:00
prep . buildChroot ( conf , keep = False )
prep . prepChroot ( conf )
2016-11-26 22:05:53 -05:00
arch = conf [ ' build ' ] [ ' arch ' ]
2016-12-20 16:57:31 -05:00
bGPG . killStaleAgent ( conf )
2016-11-26 22:05:53 -05:00
for a in arch :
bchroot . chroot ( conf [ ' build ' ] [ ' chrootdir ' ] + ' /root. ' + a , ' bdisk.square-r00t.net ' )
bchroot . chrootUnmount ( conf [ ' build ' ] [ ' chrootdir ' ] + ' /root. ' + a )
2016-12-26 13:34:34 -05:00
prep . postChroot ( conf )
2016-12-04 02:43:49 -05:00
bchroot . chrootTrim ( conf [ ' build ' ] )
2016-12-13 23:43:53 -05:00
build . genImg ( conf )
2016-12-01 07:13:24 -05:00
build . genUEFI ( conf [ ' build ' ] , conf [ ' bdisk ' ] )
2016-12-02 04:10:38 -05:00
fulliso = build . genISO ( conf )
2016-12-17 01:07:50 -05:00
bGPG . signIMG ( fulliso [ ' Main ' ] [ ' file ' ] , conf )
2016-12-01 23:42:27 -05:00
build . displayStats ( fulliso )
2016-12-06 17:51:36 -05:00
if conf [ ' build ' ] [ ' ipxe ' ] :
bSSL . sslPKI ( conf )
2016-12-15 01:53:15 -05:00
ipxe . buildIPXE ( conf )
iso = ipxe . genISO ( conf )
2016-12-13 23:43:53 -05:00
if iso :
for x in iso . keys ( ) :
if x != ' name ' :
path = iso [ x ] [ ' file ' ]
2016-12-17 01:07:50 -05:00
bGPG . signIMG ( path , conf )
2016-12-13 23:43:53 -05:00
build . displayStats ( iso )
2016-12-09 22:16:50 -05:00
bsync . http ( conf )
bsync . tftp ( conf )
bsync . git ( conf )
bsync . rsync ( conf )
2016-12-03 06:07:41 -05:00
print ( ' {0} : Finish. ' . format ( datetime . datetime . now ( ) ) )
2017-09-30 05:15:52 -04:00
def parseArgs ( ) :
args = argparse . ArgumentParser ( description = ' BDisk - a tool for building live/rescue media. ' ,
epilog = ' brent s. || 2017 || https://bdisk.square-r00t.net ' )
args . add_argument ( ' buildini ' ,
metavar = ' /path/to/build.ini ' ,
default = ' /etc/bdisk/build.ini ' ,
nargs = ' ? ' ,
help = ' The full/absolute path to the build.ini to use for this run. The default is /etc/bdisk/build.ini, but see https://bdisk.square-r00t.net/#the_code_build_ini_code_file. ' )
return ( args )
def main ( ) :
args = vars ( parseArgs ( ) . parse_args ( ) )
bdisk ( args )
if __name__ == ' __main__ ' :
main ( )