Compare commits

..

15 Commits

17 changed files with 172 additions and 25 deletions

View File

@@ -19,7 +19,7 @@ def genGPG(conf):
distkey = conf['src'][a]['gpgkey']
if keysrv and (keysrv not in gpgkeyserver):
gpgkeyserver.append(keysrv)
if distkey not in distkeys:
if distkey and(distkey not in distkeys):
distkeys.append(distkey)
templates_dir = '{0}/extra/templates'.format(build['basedir'])
mykey = False
@@ -35,6 +35,7 @@ def genGPG(conf):
if gpghome == '':
# We'll generate a key if we can't find one here.
gpghome = build['dlpath'] + '/.gnupg'
killStaleAgent(conf)
os.environ['GNUPGHOME'] = gpghome
gpg = gpgme.Context()
# do we need to add a keyserver?
@@ -116,13 +117,13 @@ def killStaleAgent(conf):
# Kill off any stale GPG agents running.
# Probably not even needed, but good to have.
chrootdir = conf['build']['chrootdir']
dlpath = conf['build']['dlpath']
gpgpath = conf['gpg']['mygpghome']
procs = psutil.process_iter()
plst = []
for p in procs:
if (p.name() in ('gpg-agent', 'dirmngr') and p.uids()[0] == os.getuid()):
pd = psutil.Process(p.pid).as_dict()
for d in (chrootdir, dlpath):
for d in (chrootdir, gpgpath):
if pd['cwd'].startswith('{0}'.format(d)):
plst.append(p.pid)
if len(plst) >= 1:

View File

@@ -138,11 +138,12 @@ def chrootTrim(build):
humanize.naturalsize(
os.path.getsize(tarball)),
dbdir))
for d in ('etc/pacman.d/gnupg', 'var/empty/.gnupg'):
if os.path.isdir('{0}/root.{1}/{2}'.format(chrootdir, a, d)):
shutil.rmtree('{0}/root.{1}/{2}'.format(chrootdir, a, d))
#for d in ('etc/pacman.d/gnupg', 'var/empty/.gnupg'): # actually, we should probably keep these.
# they don't take much space, and it's a PITA to pacman-key --init && pacman-key --populate again on boot.
# if os.path.isdir('{0}/root.{1}/{2}'.format(chrootdir, a, d)):
# shutil.rmtree('{0}/root.{1}/{2}'.format(chrootdir, a, d))
# TODO: move the self-cleanup in pre-build.sh to here.
delme = ['/root/.gnupg',
delme = [#'/root/.gnupg', # see above
'/root/.bash_history',
#'/var/log/chroot_install.log', # disable for now. maybe always disable if debug is enabled? TODO.
'/.git',

View File

@@ -8,12 +8,15 @@ import bSSL
import ipxe
import bsync
import bGPG
import os
# we need to:
# 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.
# still on the todo: iPXE
if __name__ == '__main__':
if os.getuid() != 0:
exit('{0}: ERROR: BDisk *must* be run as the root user or with sudo!'.format(datetime.datetime.now()))
print('{0}: Starting.'.format(datetime.datetime.now()))
conf = host.parseConfig(host.getConfig())[1]
prep.dirChk(conf)

View File

@@ -28,6 +28,9 @@ def getConfig(conf_file='/etc/bdisk/build.ini'):
conf = False
# define some defailt conf paths in case we're installed by
# a package manager. in order of the paths we should search.
currentdir = os.path.dirname(os.path.realpath(__file__))
currentdir_user = os.path.abspath('{0}/../build.ini'.format(currentdir))
currentdir_def = os.path.abspath('{0}/../extra/dist.build.ini'.format(currentdir))
default_conf_paths = ['/etc/bdisk/build.ini',
'/usr/share/bdisk/build.ini',
'/usr/share/bdisk/extra/build.ini',
@@ -36,7 +39,8 @@ def getConfig(conf_file='/etc/bdisk/build.ini'):
'/usr/local/share/docs/bdisk/build.ini',
'/opt/dev/bdisk/build.ini',
'/opt/dev/bdisk/extra/build.ini',
'/opt/dev/bdisk/extra/dist.build.ini']
'/opt/dev/bdisk/extra/dist.build.ini',
currentdir_user]
# if we weren't given one/using the default...
if conf_file == '/etc/bdisk/build.ini':
if not os.path.isfile(conf_file):
@@ -46,7 +50,9 @@ def getConfig(conf_file='/etc/bdisk/build.ini'):
break
else:
conf = conf_file
defconf = '{0}/../extra/dist.build.ini'.format(os.path.dirname(os.path.realpath(__file__)))
else:
conf = conf_file
defconf = os.path.abspath('{0}/../extra/dist.build.ini'.format(os.path.dirname(os.path.realpath(__file__))))
if not conf:
# okay, so let's check for distributed/"blank" ini's
# since we can't seem to find one.
@@ -91,12 +97,17 @@ def parseConfig(confs):
# commits on top of a new tagged release). e.g. for build Y:
# v#.##-Y or v#.##rX-Y
if config_dict['bdisk']['ver'] == '':
try:
repo = git.Repo(config_dict['build']['basedir'])
refs = repo.git.describe(repo.head.commit).split('-')
if len(refs) >= 2:
config_dict['bdisk']['ver'] = refs[0] + 'r' + refs[1]
else:
config_dict['bdisk']['ver'] = refs[0]
except:
exit(('{0}: ERROR: {1} is NOT a valid git repository, and you did not specify bdisk:ver in your build.ini! ' +
'Did you perhaps install from a package manager? Please refer to the documentation.').format(datetime.datetime.now(),
config_dict['build']['basedir']))
# And the build number.
# TODO: support tracking builds per version. i.e. in buildnum:
# v2.51r13:0

View File

@@ -1,5 +1,6 @@
## Missing v2.x functionality ##
-i_am_a_racecar optimizations
- different distro guests (debian, etc.)- https://stackoverflow.com/questions/2349991/python-how-to-import-other-python-files/20749411#20749411
-incorporate this into the manual?
-TFTP configs generated for pxelinux
-fix the branding, etc. on ipxe. :(

View File

@@ -16,6 +16,7 @@ If you want to use your own `build.ini` file (and you should!), the following pa
* `/opt/dev/bdisk/build.ini`
* `/opt/dev/bdisk/extra/build.ini`
* `/opt/dev/bdisk/extra/dist.build.ini`
* `<bdisk.py directory>/../build.ini`
We'll go into more detail for each section below.
@@ -64,7 +65,7 @@ We'll go into more detail for each section below.
prepdir = ${dlpath}/temp
archboot = ${prepdir}/${bdisk:name}
mountpt = /mnt/${bdisk:uxname}
multiarch = yes
multiarch = x86_64
sign = yes
ipxe = no
i_am_a_racecar = no
@@ -126,7 +127,7 @@ This string is used for "pretty-printing" of the project name; it should be a mo
. ASCII only
==== `ver`
The version string. If this isn't specified, we'll try to guess based on the current git commit and tags in `<<code_basedir_code,build:basedir>>`.
The version string. If this isn't specified, we'll try to guess based on the current git commit and tags in `<<code_basedir_code,build:basedir>>`. If `<<code_basedir_code,build:basedir>>` is *not* a git repository (i.e. you installed BDisk from a package manager), you MUST specify a version number.
. No whitespace

View File

@@ -60,14 +60,15 @@ srcdir = ${dlpath}/src
prepdir = ${dlpath}/temp
archboot = ${prepdir}/${bdisk:name}
mountpt = /mnt/${bdisk:uxname}
multiarch = yes
#multiarch = yes
multiarch = x86_64
sign = yes
ipxe =
ipxe = no
i_am_a_racecar = yes
[gpg]
mygpgkey =
mygpghome =
mygpghome = ${build:dlpath}/.gnupg
[sync]
http = no

View File

@@ -0,0 +1,48 @@
# The modules found in here are for distro-specific differences in the builds.
# For instance, if you want to build a Debian-based BDisk, you'd specify pkg['install'] = ['apt-get', '-y', 'install', '%PKG%'],
# name this file as "debian.py", and set bdisk:distro as 'debian'.
# Note that the guest will need python installed. If distro is set as "NOCHECK", a distro check of the tarball won't be performed
# (as the distro check requires python be installed first).
# Special variables to be used in strings:
# %PKG% = the name of a package would be inserted here.
# This template uses Debian as an example.
# The name of the distro. Must match the output from platform.linux_distribution()[0].lower()
# Regex is supported.
distro = 'debian'
# The path to python. Can be either python 2.x (2.6 or higher) or 3.x.
pybin = '/usr/bin/python'
guestenv = {}
# The following environment variables will be set for the guest.
guestenv['DEBIAN_FRONTEND'] = 'noninteractive'
scripts = {}
# This variable can be used to perform some additional system tweaks and such. This is run before package installation.
# It must be formatted as a complete script- i.e. include a shebang etc.
script['pre'] = """#!/bin/bash
touch /root/BDISK
"""
# This variable can be used to perform some additional system tweaks and such. This is run after package installation.
script['post'] = """#!/bin/bash
rm -f /root/BDISK
"""
pkg = {}
# The command, with arguments, in list format that should be run before we install software in the guest.
# For instance, if your guest distro requires a local package listing cache (nearly all of them do) to be
# updated first, this is where it would be run.
pkg['pre'] = ['apt-get', '-y', 'update']
# The command, with arguments, in a list format to install a package.
# Note that the command must be constructed in a way that does not require user interaction.
pkg['install'] = ['apt-get', '-y', 'install', '%PKG%']
# The command, with arguments, in list format to use to check if a package is installed.
# It should return 0 on exist status if it's installed. Any other exit status assumes the package is not installed.
pkg['check'] = ['dpkg-query', '-f', '${binary:Package}\n', '-W', '%PKG']

View File

@@ -0,0 +1,11 @@
distro = 'arch'
pybin = '/usr/bin/python'
script['pre'] = """#!/bin/bash
touch /root/BDISK
"""
script['post'] = """#!/bin/bash
rm -f /root/BDISK
"""
pkg['pre'] = ['pacman', '-Syyy']
pkg['install'] = ['apacman', '-S', '%PKG%']
pkg['check'] = ['pacman', '-Q', '%PKG']

View File

@@ -0,0 +1,11 @@
distro = 'centos linux'
pybin = '/usr/bin/python'
script['pre'] = """#!/bin/bash
touch /root/BDISK
"""
script['post'] = """#!/bin/bash
rm -f /root/BDISK
"""
pkg['pre'] = ['yum', 'makecache']
pkg['install'] = ['yum', '-y', 'install', '%PKG%']
pkg['check'] = ['rpm', '-qi', '%PKG']

View File

@@ -0,0 +1,12 @@
distro = 'debian'
pybin = '/usr/bin/python'
guestenv['DEBIAN_FRONTEND'] = 'noninteractive'
script['pre'] = """#!/bin/bash
touch /root/BDISK
"""
script['post'] = """#!/bin/bash
rm -f /root/BDISK
"""
pkg['pre'] = ['apt-get', '-q', '-y', 'update']
pkg['install'] = ['apt-get', '-q', '-y', '-o Dpkg::Options::="--force-confdef"', '-o Dpkg::Options::="--force-confold"', 'install', '%PKG%']
pkg['check'] = ['dpkg-query', '-f', "'${binary:Package}\n'", '-W', '%PKG']

View File

@@ -0,0 +1,11 @@
distro = 'fedora'
pybin = '/usr/bin/python3'
script['pre'] = """#!/bin/bash
touch /root/BDISK
"""
script['post'] = """#!/bin/bash
rm -f /root/BDISK
"""
pkg['pre'] = ['yum', 'makecache']
pkg['install'] = ['yum', '-y', 'install', '%PKG%']
pkg['check'] = ['rpm', '-qi', '%PKG']

View File

@@ -0,0 +1,11 @@
distro = 'red hat enterprise linux (server|desktop)'
pybin = '/usr/bin/python'
script['pre'] = """#!/bin/bash
touch /root/BDISK
"""
script['post'] = """#!/bin/bash
rm -f /root/BDISK
"""
pkg['pre'] = ['yum', 'makecache']
pkg['install'] = ['yum', '-y', 'install', '%PKG%']
pkg['check'] = ['rpm', '-qi', '%PKG']

View File

@@ -0,0 +1,11 @@
distro = 'suse linux enterprise server'
pybin = '/usr/bin/python'
script['pre'] = """#!/bin/bash
touch /root/BDISK
"""
script['post'] = """#!/bin/bash
rm -f /root/BDISK
"""
pkg['pre'] = ['zypper', 'refresh']
pkg['install'] = ['zypper', 'install', '--no-confirm', '-l', '%PKG%']
pkg['check'] = ['rpm', '-qi', '%PKG']

View File

@@ -0,0 +1,12 @@
distro = 'ubuntu'
pybin = '/usr/bin/python'
guestenv['DEBIAN_FRONTEND'] = 'noninteractive'
script['pre'] = """#!/bin/bash
touch /root/BDISK
"""
script['post'] = """#!/bin/bash
rm -f /root/BDISK
"""
pkg['pre'] = ['apt-get', '-q', '-y', 'update']
pkg['install'] = ['apt-get', '-q', '-y', '-o Dpkg::Options::="--force-confdef"', '-o Dpkg::Options::="--force-confold"', 'install', '%PKG%']
pkg['check'] = ['dpkg-query', '-f', "'${binary:Package}\n'", '-W', '%PKG']

View File

@@ -60,13 +60,14 @@ srcdir = ${dlpath}/src
prepdir = ${dlpath}/temp
archboot = ${prepdir}/${bdisk:name}
mountpt = /mnt/${bdisk:uxname}
multiarch = yes
#multiarch = yes
multiarch = x86_64
ipxe = no
i_am_a_racecar = no
[gpg]
mygpgkey =
mygpghome =
mygpghome = ${build:dlpath}/.gnupg
[sync]
http = no

View File

@@ -2,5 +2,5 @@ Version: {{ bdisk['ver'] }}
Build: {{ build['buildnum'] }}
Time: {{ build['time'] }}
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']|length > 0 %} ({{ build['realuser'] }}){% endif %}