From eec74f16e6963294498eb7159bb9685c3172c83e Mon Sep 17 00:00:00 2001 From: r00t Date: Tue, 11 Apr 2017 08:09:50 -0400 Subject: [PATCH 1/6] config update, oops --- extra/dist.build.ini | 2 +- extra/modules/distro/TEMPLATE | 48 ++++++++++++++++++++++++++++++++++ extra/modules/distro/arch.py | 11 ++++++++ extra/modules/distro/centos.py | 11 ++++++++ extra/modules/distro/debian.py | 12 +++++++++ extra/modules/distro/fedora.py | 11 ++++++++ extra/modules/distro/rhel.py | 11 ++++++++ extra/modules/distro/sles.py | 11 ++++++++ extra/modules/distro/ubuntu.py | 12 +++++++++ 9 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 extra/modules/distro/TEMPLATE create mode 100644 extra/modules/distro/arch.py create mode 100644 extra/modules/distro/centos.py create mode 100644 extra/modules/distro/debian.py create mode 100644 extra/modules/distro/fedora.py create mode 100644 extra/modules/distro/rhel.py create mode 100644 extra/modules/distro/sles.py create mode 100644 extra/modules/distro/ubuntu.py diff --git a/extra/dist.build.ini b/extra/dist.build.ini index 15f5fa1..1668576 100644 --- a/extra/dist.build.ini +++ b/extra/dist.build.ini @@ -62,7 +62,7 @@ archboot = ${prepdir}/${bdisk:name} mountpt = /mnt/${bdisk:uxname} multiarch = yes sign = yes -ipxe = +ipxe = no i_am_a_racecar = yes [gpg] diff --git a/extra/modules/distro/TEMPLATE b/extra/modules/distro/TEMPLATE new file mode 100644 index 0000000..dd82e26 --- /dev/null +++ b/extra/modules/distro/TEMPLATE @@ -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'] diff --git a/extra/modules/distro/arch.py b/extra/modules/distro/arch.py new file mode 100644 index 0000000..e3266a0 --- /dev/null +++ b/extra/modules/distro/arch.py @@ -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'] diff --git a/extra/modules/distro/centos.py b/extra/modules/distro/centos.py new file mode 100644 index 0000000..5db749a --- /dev/null +++ b/extra/modules/distro/centos.py @@ -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'] diff --git a/extra/modules/distro/debian.py b/extra/modules/distro/debian.py new file mode 100644 index 0000000..5069f85 --- /dev/null +++ b/extra/modules/distro/debian.py @@ -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'] diff --git a/extra/modules/distro/fedora.py b/extra/modules/distro/fedora.py new file mode 100644 index 0000000..66d8bf6 --- /dev/null +++ b/extra/modules/distro/fedora.py @@ -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'] diff --git a/extra/modules/distro/rhel.py b/extra/modules/distro/rhel.py new file mode 100644 index 0000000..7d20b62 --- /dev/null +++ b/extra/modules/distro/rhel.py @@ -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'] diff --git a/extra/modules/distro/sles.py b/extra/modules/distro/sles.py new file mode 100644 index 0000000..c021edf --- /dev/null +++ b/extra/modules/distro/sles.py @@ -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'] diff --git a/extra/modules/distro/ubuntu.py b/extra/modules/distro/ubuntu.py new file mode 100644 index 0000000..d95179d --- /dev/null +++ b/extra/modules/distro/ubuntu.py @@ -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'] From f37221c8333d91be0d350880d0c50537b9b18b18 Mon Sep 17 00:00:00 2001 From: r00t Date: Tue, 11 Apr 2017 08:19:24 -0400 Subject: [PATCH 2/6] some further tweaking of conf paths --- bdisk/host.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bdisk/host.py b/bdisk/host.py index f282c16..aa0b216 100755 --- a/bdisk/host.py +++ b/bdisk/host.py @@ -28,7 +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.abspath('{0}/../extra/dist.build.ini'.format(os.path.dirname(os.path.realpath(__file__)))) + currentdir = os.path.dirname(os.path.realpath(__file__)) + currentdir_user = os.path.abspath('{0}/../dist.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', @@ -38,7 +40,8 @@ def getConfig(conf_file='/etc/bdisk/build.ini'): '/opt/dev/bdisk/build.ini', '/opt/dev/bdisk/extra/build.ini', '/opt/dev/bdisk/extra/dist.build.ini', - currentdir] + currentdir_user, + currentdir_def] # if we weren't given one/using the default... if conf_file == '/etc/bdisk/build.ini': if not os.path.isfile(conf_file): From 60791f159623138cb57a6f7f18024ede56d3ce88 Mon Sep 17 00:00:00 2001 From: r00t Date: Tue, 11 Apr 2017 08:27:18 -0400 Subject: [PATCH 3/6] okay. FINALLY fixed the weird issue with arbitrary paths --- bdisk/host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bdisk/host.py b/bdisk/host.py index aa0b216..5334f85 100755 --- a/bdisk/host.py +++ b/bdisk/host.py @@ -29,7 +29,7 @@ def getConfig(conf_file='/etc/bdisk/build.ini'): # 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}/../dist.build.ini'.format(currentdir)) + 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', From e3236eb0d6368a2ea4f7ea7cf6e391054c6a3630 Mon Sep 17 00:00:00 2001 From: r00t Date: Tue, 11 Apr 2017 08:30:09 -0400 Subject: [PATCH 4/6] whoops! one oversight --- bdisk/host.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bdisk/host.py b/bdisk/host.py index 5334f85..ac1042b 100755 --- a/bdisk/host.py +++ b/bdisk/host.py @@ -40,8 +40,7 @@ def getConfig(conf_file='/etc/bdisk/build.ini'): '/opt/dev/bdisk/build.ini', '/opt/dev/bdisk/extra/build.ini', '/opt/dev/bdisk/extra/dist.build.ini', - currentdir_user, - currentdir_def] + 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): @@ -51,7 +50,7 @@ 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__))) + 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. From 6ff5a96d76d795947c6944caa28fafb4cf6f9e68 Mon Sep 17 00:00:00 2001 From: r00t Date: Tue, 11 Apr 2017 09:06:19 -0400 Subject: [PATCH 5/6] some more tweaks --- bdisk/bGPG.py | 7 ++++--- extra/dist.build.ini | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bdisk/bGPG.py b/bdisk/bGPG.py index f123e68..34d39bf 100755 --- a/bdisk/bGPG.py +++ b/bdisk/bGPG.py @@ -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: diff --git a/extra/dist.build.ini b/extra/dist.build.ini index 1668576..2a8536d 100644 --- a/extra/dist.build.ini +++ b/extra/dist.build.ini @@ -67,7 +67,7 @@ i_am_a_racecar = yes [gpg] mygpgkey = -mygpghome = +mygpghome = ${build:dlpath}/.gnupg [sync] http = no From c9ccb3aa178e5ff2c7d9df548c68701128d5644c Mon Sep 17 00:00:00 2001 From: r00t Date: Tue, 11 Apr 2017 09:17:38 -0400 Subject: [PATCH 6/6] think we have something better here --- extra/dist.build.ini | 3 ++- extra/pkg.build.ini | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/extra/dist.build.ini b/extra/dist.build.ini index 2a8536d..62220da 100644 --- a/extra/dist.build.ini +++ b/extra/dist.build.ini @@ -60,7 +60,8 @@ srcdir = ${dlpath}/src prepdir = ${dlpath}/temp archboot = ${prepdir}/${bdisk:name} mountpt = /mnt/${bdisk:uxname} -multiarch = yes +#multiarch = yes +multiarch = x86_64 sign = yes ipxe = no i_am_a_racecar = yes diff --git a/extra/pkg.build.ini b/extra/pkg.build.ini index 5a14829..04f686a 100644 --- a/extra/pkg.build.ini +++ b/extra/pkg.build.ini @@ -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