mirror of
https://github.com/clearlinux/bundle-chroot-builder.git
synced 2026-06-16 02:35:51 +00:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b44cd8c2c6 | |||
| 8468405d9a | |||
| 2024792039 | |||
| 4afdbd6c8e | |||
| 2f17b8187e | |||
| df44fd82f0 | |||
| 2b92b2eff2 | |||
| e6e3bab777 | |||
| ff6a30cc43 | |||
| 798b4e8906 | |||
| 6a0cafa617 | |||
| 1bb15ab253 | |||
| 02f5c8fad9 | |||
| 579f606714 | |||
| 537bacec41 | |||
| cd634c88df | |||
| 0e50054fa1 | |||
| 6aa46648d0 | |||
| bcffbb7096 | |||
| 9fc98a03b1 | |||
| c96046001e | |||
| 0d0e64e2a9 | |||
| be05f6b513 | |||
| d07ac01932 | |||
| 82bd4409f8 | |||
| 78e419ee2c | |||
| 9d987f5e3b | |||
| 629f940676 | |||
| 68084ca1b6 |
@@ -1,3 +1,23 @@
|
||||
Building this Project
|
||||
=====================
|
||||
For help using automake see
|
||||
http://www.gnu.org/software/automake/manual/html_node/index.html
|
||||
|
||||
Configure:
|
||||
aclocal
|
||||
autoconf
|
||||
automake --add-missing
|
||||
# Defaults to /usr/local or specific --prefix=/usr
|
||||
# to overwrite the installed version
|
||||
./configure
|
||||
|
||||
Build:
|
||||
make
|
||||
|
||||
Install:
|
||||
make -n install
|
||||
sudo make install
|
||||
|
||||
Configuration File
|
||||
==================
|
||||
Please update the configuration file paths to point to where your
|
||||
|
||||
+13
-6
@@ -1,10 +1,17 @@
|
||||
[Builder]
|
||||
SERVER_STATE_DIR = /var/lib/update
|
||||
BUNDLE_DIR = /home/clr/mix/bundles
|
||||
YUM_CONF = /usr/share/defaults/bundle-chroot-builder/yum.conf
|
||||
SERVER_STATE_DIR=/home/clr/mix/update
|
||||
BUNDLE_DIR=/home/clr/mix/mix-bundles
|
||||
YUM_CONF=/home/clr/mix/.yum-mix.conf
|
||||
CERT=/home/clr/mix/Swupd_Root.pem
|
||||
VERSIONS_PATH=/home/clr/mix
|
||||
|
||||
[swupd]
|
||||
BUNDLE=os-core-update
|
||||
CONTENTURL=https://download.clearlinux.org/update/
|
||||
VERSIONURL=https://download.clearlinux.org/update/
|
||||
FORMAT=3
|
||||
CONTENTURL=<URL where the content will be hosted>
|
||||
VERSIONURL=<URL where the version of the mix will be hosted>
|
||||
FORMAT=1
|
||||
|
||||
[Server]
|
||||
debuginfo_banned=true
|
||||
debuginfo_lib=/usr/lib/debug/
|
||||
debuginfo_src=/usr/src/debug/
|
||||
|
||||
+92
-30
@@ -25,6 +25,7 @@ import argparse
|
||||
import configparser
|
||||
import os
|
||||
import os.path
|
||||
import io
|
||||
import platform
|
||||
import re
|
||||
import shutil
|
||||
@@ -47,15 +48,32 @@ def handle_options():
|
||||
return args
|
||||
|
||||
|
||||
def read_config(args):
|
||||
def get_config(args):
|
||||
buildconf='/usr/share/defaults/bundle-chroot-builder/builder.conf'
|
||||
if os.path.isfile('/etc/bundle-chroot-builder/builder.conf'):
|
||||
buildconf = '/etc/bundle-chroot-builder/builder.conf'
|
||||
if args.config:
|
||||
buildconf = args.config
|
||||
config = configparser.ConfigParser()
|
||||
config.read(buildconf)
|
||||
|
||||
print("Reading from %s" % buildconf)
|
||||
cfg_txt = ""
|
||||
# Check that the environment variables in the config file are valid
|
||||
pattern = re.compile("\$\{?(\w+)\}?")
|
||||
for i, line in enumerate(open(buildconf, 'r')):
|
||||
for match in re.finditer(pattern, line):
|
||||
if not match.group(1) in os.environ:
|
||||
print("ERROR:\nbuilder.conf contains an undefined environment variable: %s on line %s\n"
|
||||
% (i+1, match.group(1)))
|
||||
exit(1)
|
||||
cfg_txt += os.path.expandvars(line)
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.readfp(io.StringIO(cfg_txt))
|
||||
return config
|
||||
|
||||
|
||||
def read_config(args):
|
||||
config = get_config(args)
|
||||
for option in ['SERVER_STATE_DIR', 'BUNDLE_DIR', 'YUM_CONF']:
|
||||
if config.has_option('Builder', option) == False:
|
||||
print("ERROR:\nbuilder.conf is missing:\n[Builder]\n%s\n" % option)
|
||||
@@ -73,9 +91,13 @@ def read_config(args):
|
||||
def install_bundle(out_dir, postfix, bundle, bundles, yum_cmd):
|
||||
"""Helper function to yum install a bundle"""
|
||||
lines = []
|
||||
with subprocess.Popen(["m4", bundles + "/" + bundle], cwd=bundles, stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p:
|
||||
for line in p.stdout:
|
||||
lines.append(line)
|
||||
try:
|
||||
output = subprocess.check_output(["m4", bundles + "/" + bundle], cwd=bundles, bufsize=1, universal_newlines=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print('ERROR {0}: m4 failed on {1}/{2}'.format(e.returncode, bundles, bundle))
|
||||
raise
|
||||
for line in output:
|
||||
lines.append(line)
|
||||
|
||||
pkgs = "".join(lines)
|
||||
to_install = []
|
||||
@@ -146,6 +168,37 @@ def clean_bundle(out_dir, bundle, bundles, yum_cmd):
|
||||
os.chdir(prev_dir)
|
||||
|
||||
|
||||
def write_default_server_ini(state_dir, server_conf):
|
||||
"""
|
||||
Write default server.ini file in the state dir in the following format
|
||||
|
||||
[Server]
|
||||
emptydir={state_dir}/empty/
|
||||
imagebase={state_dir}/image/
|
||||
outputdir={state_dir}/www/
|
||||
|
||||
[Debuginfo]
|
||||
banned=true
|
||||
lib=/usr/lib/debug/
|
||||
src=/usr/src/debug/
|
||||
"""
|
||||
contents = ("[Server]\n"
|
||||
"emptydir={0}/empty/\n"
|
||||
"imagebase={0}/image/\n"
|
||||
"outputdir={0}/www/\n".format(state_dir))
|
||||
if server_conf:
|
||||
contents += ("\n[Debuginfo]\n"
|
||||
"banned={}\n"
|
||||
"lib={}\n"
|
||||
"src={}\n"
|
||||
.format(server_conf.get('debuginfo_banned'),
|
||||
server_conf.get('debuginfo_lib'),
|
||||
server_conf.get('debuginfo_src')))
|
||||
|
||||
with open(state_dir + "/server.ini", "w+") as serverini:
|
||||
serverini.write(contents)
|
||||
|
||||
|
||||
def create_chroots(args, state_dir, bundles, yum_conf):
|
||||
"""The state_dir should always be created if it does not exist"""
|
||||
if os.path.isdir(state_dir) == False:
|
||||
@@ -159,14 +212,15 @@ def create_chroots(args, state_dir, bundles, yum_conf):
|
||||
if os.path.isdir(state_dir + "/www/0") == False:
|
||||
os.makedirs(state_dir + "/www/0")
|
||||
|
||||
"""Create server.ini and groups.ini for create_update later on"""
|
||||
with open(state_dir + "/server.ini", "w+") as serverini:
|
||||
serverini.write("[Server]\nemptydir=" + state_dir + "/empty/\nimagebase=" + state_dir + "/image/\noutputdir=" + state_dir + "/www/\n")
|
||||
# Create server.ini and groups.ini for create_update later on
|
||||
config = get_config(args)
|
||||
config = config['Server'] if 'Server' in config else {}
|
||||
write_default_server_ini(state_dir, config)
|
||||
with open(state_dir + "/groups.ini", "w+") as groupsini:
|
||||
bundle_list = os.listdir(bundles)
|
||||
bundle_list = trim_bundles(bundle_list)
|
||||
for bundle in bundle_list:
|
||||
groupsini.write("[" + bundle + "]\ngroup=" + bundle + "\n\n")
|
||||
groupsini.write("[{0}]\ngroup={0}\n\n".format(bundle))
|
||||
|
||||
"""Setup chroots for bundles"""
|
||||
bversion = ""
|
||||
@@ -177,8 +231,8 @@ def create_chroots(args, state_dir, bundles, yum_conf):
|
||||
out_version = args.version
|
||||
build_version = args.version
|
||||
|
||||
if os.path.exists(state_dir + "/image/latest.version") == False:
|
||||
with open(state_dir + "/image/latest.version", "w") as latestver:
|
||||
if os.path.exists(state_dir + "/image/LAST_VER") == False:
|
||||
with open(state_dir + "/image/LAST_VER", "w") as latestver:
|
||||
latestver.write("0\n")
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
@@ -195,12 +249,21 @@ def create_chroots(args, state_dir, bundles, yum_conf):
|
||||
|
||||
out_dir = state_dir + "/image/" + out_version
|
||||
|
||||
if platform.dist()[0] == "fedora" and int(platform.dist()[1]) >= 22:
|
||||
try:
|
||||
with open("/usr/share/clear/version", "r") as verfile:
|
||||
clrver = int(verfile.read().strip())
|
||||
except Exception:
|
||||
clrver = None
|
||||
|
||||
if clrver and clrver > 20650:
|
||||
print("using dnf on clr")
|
||||
packager = ["dnf"]
|
||||
elif platform.dist()[0] == "fedora" and int(platform.dist()[1]) >= 22:
|
||||
print("using dnf instead of yum")
|
||||
packager = ["dnf"]
|
||||
else:
|
||||
packager = ["yum"]
|
||||
yum_cmd = packager + ["--config={}".format(yum_conf), "-y", "--noplugins", "--releasever={}".format(build_version)]
|
||||
yum_cmd = packager + ["--config={}".format(yum_conf), "-y", "--releasever={}".format(build_version)]
|
||||
if 'local' in config == False:
|
||||
try:
|
||||
urllib.request.urlopen(conf_baseurl)
|
||||
@@ -246,7 +309,7 @@ def create_chroots(args, state_dir, bundles, yum_conf):
|
||||
|
||||
print("Noting os-core package list")
|
||||
with open(out_dir + "/versions", "w") as file:
|
||||
subprocess.Popen(yum_cmd + ["--installroot={}/os-core".format(out_dir), "list"], stdout=file).wait()
|
||||
subprocess.Popen(yum_cmd + ["--quiet", "--installroot={}/os-core".format(out_dir), "list"], stdout=file).wait()
|
||||
with open(out_dir + "/packages-os-core", "w") as file:
|
||||
subprocess.Popen(['rpm', '--root={}/os-core'.format(out_dir),
|
||||
'-qa', '--queryformat', '%{NAME}\t%{SOURCERPM}\n'], stdout=file).wait()
|
||||
@@ -283,13 +346,7 @@ def create_chroots(args, state_dir, bundles, yum_conf):
|
||||
r.get()
|
||||
|
||||
"""Read the URL values from builder.conf and insert them into os-core-update to swupd knows where to pull content from"""
|
||||
buildconf='/usr/share/defaults/bundle-chroot-builder/builder.conf'
|
||||
if os.path.isfile('/etc/bundle-chroot-builder/builder.conf'):
|
||||
buildconf = '/etc/bundle-chroot-builder/builder.conf'
|
||||
if args.config:
|
||||
buildconf = args.config
|
||||
config = configparser.ConfigParser()
|
||||
config.read(buildconf)
|
||||
config = get_config(args)
|
||||
|
||||
"""Read the configuration file for our script values"""
|
||||
for option in ['BUNDLE', 'CONTENTURL', 'VERSIONURL', 'FORMAT']:
|
||||
@@ -330,6 +387,10 @@ def create_chroots(args, state_dir, bundles, yum_conf):
|
||||
if package_name not in package_mapping:
|
||||
package_mapping[package_name] = set()
|
||||
for path in path_list:
|
||||
# RPM prints out a specific string for subpackages that contain no
|
||||
# files. It should be excluded from the SRPM file list.
|
||||
if re.match(br"\(contains no files\)\n", path):
|
||||
continue
|
||||
package_mapping[package_name].add(path)
|
||||
for package_name, paths in package_mapping.items():
|
||||
with open(out_dir + "/files-{}".format(package_name), "wb") as file:
|
||||
@@ -342,16 +403,17 @@ def create_chroots(args, state_dir, bundles, yum_conf):
|
||||
|
||||
print("Cleaning package list")
|
||||
web_dir = state_dir + "/www/" + out_version + "/"
|
||||
image_dir = state_dir + "/image/" + out_version + "/"
|
||||
if os.path.isdir(web_dir):
|
||||
print(" removing pre-existing {} before setting version file" .format(web_dir))
|
||||
os.system('rm -rf '+web_dir)
|
||||
# FIXME: Figure out problems with the below to replace the above.
|
||||
# Consider all uses of os.system("rm -fr") as FIXMEs of the same variety.
|
||||
# if os.path.isdir(web_dir):
|
||||
# if os.path.isdir(image_dir):
|
||||
# print(" removing pre-existing {} before setting version file"
|
||||
# .format(web_dir))
|
||||
# shutil.rmtree(web_dir)
|
||||
os.makedirs(web_dir + '/noship')
|
||||
# .format(imagedir())
|
||||
# shutil.rmtree(image_dir)
|
||||
os.makedirs(image_dir + '/noship')
|
||||
versions_output = []
|
||||
with open(out_dir + "/versions", "r") as file:
|
||||
versions = set()
|
||||
@@ -369,17 +431,17 @@ def create_chroots(args, state_dir, bundles, yum_conf):
|
||||
versions_output.append("{0: <50}{1}\n".format("Available", "Packages"))
|
||||
for name, pver in [line.split(":") for line in versions]:
|
||||
versions_output.append("{0: <50}{1}\n".format(name, pver))
|
||||
with open(web_dir + "versions", "w") as file:
|
||||
with open(image_dir + "versions", "w") as file:
|
||||
file.writelines(versions_output)
|
||||
bundle_list = os.listdir(bundles)
|
||||
bundle_list = trim_bundles(bundle_list)
|
||||
for bundle in bundle_list:
|
||||
shutil.copyfile(out_dir + "/packages-{}".format(bundle), web_dir + "/noship/packages-{}".format(bundle))
|
||||
shutil.copyfile(out_dir + "/packages-{}".format(bundle), image_dir + "/noship/packages-{}".format(bundle))
|
||||
if os.path.isfile(out_dir + "/{}-includes".format(bundle)):
|
||||
shutil.copyfile(out_dir + "/{}-includes".format(bundle), web_dir + "/noship/{}-includes".format(bundle))
|
||||
shutil.copyfile(out_dir + "/{}-includes".format(bundle), image_dir + "/noship/{}-includes".format(bundle))
|
||||
for package_name in package_mapping.keys():
|
||||
shutil.copyfile(out_dir + "/files-{}".format(package_name),
|
||||
web_dir + "/noship/files-{}".format(package_name))
|
||||
image_dir + "/noship/files-{}".format(package_name))
|
||||
|
||||
# Remove bundles with blacklisted characters, such as dot files
|
||||
def trim_bundles(bundles):
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
AC_PREREQ([2.68])
|
||||
AC_INIT([bundle-chroot-builder],[1.05],[tudor.marcu@intel.com],[bundle-chroot-builder])
|
||||
AC_INIT([bundle-chroot-builder],[1.15],[tudor.marcu@intel.com],[bundle-chroot-builder])
|
||||
AM_INIT_AUTOMAKE([foreign silent-rules color-tests no-dist-gzip dist-xz])
|
||||
AC_CONFIG_FILES(Makefile)
|
||||
AC_PREFIX_DEFAULT(/usr/local)
|
||||
|
||||
Reference in New Issue
Block a user