From 82e1dd1bacf36300e25ded1bca0cc3bd7081f371 Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Thu, 23 Nov 2023 18:07:50 +0100 Subject: [PATCH 1/9] pre-commit --- .github/dependabot.yml | 1 - .pre-commit-config.yaml | 26 ++ COPYING | 10 +- README.md | 11 +- docs/development.md | 6 +- mtps-get-task | 4 +- mtps-mutils | 92 ++++--- mtps-prepare-system | 2 +- mtps-run-tests | 2 +- mtps-setup | 1 - mtps-tag | 4 +- profiles/rhel/prepare-system | 2 +- profiles/rhel/repos/rhel-9.5.0.repo | 1 - viewer/generate-result-json | 24 +- viewer/viewer.html | 371 ++++++++++++++++------------ 15 files changed, 321 insertions(+), 236 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 6b1f6de..fd89895 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,5 +1,4 @@ --- - version: 2 updates: - package-ecosystem: github-actions diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..55948e7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,26 @@ +# HOWTO: https://pre-commit.com/#usage +# dnf install pre-commit +# pre-commit install -t pre-commit -t pre-push + +repos: + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.1.0 + hooks: + - id: prettier + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: end-of-file-fixer + - id: mixed-line-ending + - id: trailing-whitespace + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.6 + hooks: + - id: ruff-format + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + +ci: + autoupdate_schedule: quarterly diff --git a/COPYING b/COPYING index b8dec3e..af5214d 100644 --- a/COPYING +++ b/COPYING @@ -55,7 +55,7 @@ patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION @@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions: License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) - + These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in @@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. - + 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is @@ -225,7 +225,7 @@ impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - + 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License @@ -278,7 +278,7 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS - + How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest diff --git a/README.md b/README.md index 41f96b2..c47f1e1 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,11 @@ This is a lightweight version of the TPS. Installability test checks that given RPMs can be: -* installed -* removed -* updated -* downgraded + +- installed +- removed +- updated +- downgraded mini-tps has no external dependencies. The original TPS runs on Red Hat products, mini-tps was designed to be triggered early in the development process. It runs on Koji/Brew builds. @@ -46,4 +47,4 @@ See `mtps-prepare-system --list` for the list of available profiles. ``` 5. If you wish to test another package, remove `/etc/yum.repos.d/brew-${TASK_ID}.repo` -and the files in `/var/lib/brew-repo` and repeat from the step 3. + and the files in `/var/lib/brew-repo` and repeat from the step 3. diff --git a/docs/development.md b/docs/development.md index 6a12172..768793f 100644 --- a/docs/development.md +++ b/docs/development.md @@ -11,10 +11,10 @@ rpmbuild --define="_sourcedir $PWD" --define="%_srcrpmdir $PWD" -bs mini-tps.spe ``` xmllint --xpath 'string(//member[name="build_id"]/value/int/text())' list.xml curl -k --data @xml-list-rpms "${BREWHUB}" > listg -brewbuild echo 'ls //member[value/string="src"]/../member[name="nvr"]/value/string/text()' | xmllint --shell list.xml -echo 'ls //member[value/string="noarch"]/../member[name="nvr"]/value/string/text()' | xmllint --shell listg | sed -n -e 's/^.*[[:space:]]//p' +brewbuild echo 'ls //member[value/string="src"]/../member[name="nvr"]/value/string/text()' | xmllint --shell list.xml +echo 'ls //member[value/string="noarch"]/../member[name="nvr"]/value/string/text()' | xmllint --shell listg | sed -n -e 's/^.*[[:space:]]//p' curl -k --data @xmldownloadTaskOutput.xml "${BREWHUB}" -brew -d --debug-xmlrpc taskinfo 18326749 +brew -d --debug-xmlrpc taskinfo 18326749 koji list-api git archive --format=tar.gz --prefix mini-tps/ -o mini-tps.tar.gz -v master rpmdev-bumpspec --comment='Build with the latest merged PRs.' --userstring='Andrei Stepanov ' mini-tps.spec diff --git a/mtps-get-task b/mtps-get-task index b869ec8..dcceca1 100755 --- a/mtps-get-task +++ b/mtps-get-task @@ -28,7 +28,7 @@ rpms_from_answer() { local xml="$1" && shift local tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" - local cmd="cat //member[name='rpms']//value/string/text()" + local cmd="cat //member[name='rpms']//value/string/text()" local rpm="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p' | sed -n -e "/\.$arch\.rpm/p")" debug "Arch $arch has next rpms:" debug "$rpm" @@ -40,7 +40,7 @@ srpms_from_answer() { local xml="$1" && shift local tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" - local cmd="cat //member[name='srpms']//value/string/text()" + local cmd="cat //member[name='srpms']//value/string/text()" local srpm="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p' | sed -n -e "/\.rpm/p")" debug "Has next srpms:" debug "$srpm" diff --git a/mtps-mutils b/mtps-mutils index 8030d0b..0d2b87e 100755 --- a/mtps-mutils +++ b/mtps-mutils @@ -22,69 +22,81 @@ # # https://github.com/fedora-modularity/libmodulemd -import os -import sys +import argparse +import gi import gzip import logging -import argparse +import sys logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) -import gi + md1 = None md2 = None # gi doesn't allow load two Modulemd at the same time try: - gi.require_version('Modulemd', '2.0') # noqa + gi.require_version("Modulemd", "2.0") # noqa from gi.repository import Modulemd as md2 -except: +except Exception: pass try: - gi.require_version('Modulemd', '1.0') # noqa + gi.require_version("Modulemd", "1.0") # noqa from gi.repository import Modulemd as md1 -except: +except Exception: pass if not md1 and not md2: logger.debug("Cannot load modulemd library.") sys.exit(1) -parser = argparse.ArgumentParser( - description='A set of utils for mtps..') +parser = argparse.ArgumentParser(description="A set of utils for mtps..") group = parser.add_mutually_exclusive_group(required=True) -parser.add_argument("-m", "--modulemd", help="Modulemd file path. Can be .gz", - default="modulemd.txt", metavar='FILE') -group.add_argument("-f", "--getfiltered", action="store_true", - help="Print filtered packages from module.") -group.add_argument("-a", "--getfartifacts", action="store_true", - help="Print artifacts from module.") -group.add_argument("--getprofiles", action="store_true", - help="Print profiles from module.") -group.add_argument("--getstream", action="store_true", - help="Print stream from module.") -group.add_argument("--getcontext", action="store_true", - help="Print context from module.") -group.add_argument("--getversion", action="store_true", - help="Print version from module.") -group.add_argument("--getnsvc", action="store_true", - help="Print n:s:v:c from module.") -group.add_argument("--getrequires", action="store_true", - help="Print list n:s required modules.") +parser.add_argument( + "-m", + "--modulemd", + help="Modulemd file path. Can be .gz", + default="modulemd.txt", + metavar="FILE", +) +group.add_argument( + "-f", + "--getfiltered", + action="store_true", + help="Print filtered packages from module.", +) +group.add_argument( + "-a", "--getfartifacts", action="store_true", help="Print artifacts from module." +) +group.add_argument( + "--getprofiles", action="store_true", help="Print profiles from module." +) +group.add_argument("--getstream", action="store_true", help="Print stream from module.") +group.add_argument( + "--getcontext", action="store_true", help="Print context from module." +) +group.add_argument( + "--getversion", action="store_true", help="Print version from module." +) +group.add_argument("--getnsvc", action="store_true", help="Print n:s:v:c from module.") +group.add_argument( + "--getrequires", action="store_true", help="Print list n:s required modules." +) args = parser.parse_args() mmds = [] if args.modulemd: if args.modulemd.endswith(".gz"): - f = gzip.open(args.modulemd, 'rb') + f = gzip.open(args.modulemd, "rb") else: - f = open(args.modulemd, 'rb') - md = f.read().decode(encoding='utf-8') + f = open(args.modulemd, "rb") + md = f.read().decode(encoding="utf-8") f.close() if md2: + def get_nsvc(module): nsvc = "%s:%s:%s:%s" % ( module.get_module_name(), @@ -93,6 +105,7 @@ if md2: module.get_all_streams()[0].get_context(), ) return nsvc + # 1 brew build == 1 stream index = md2.ModuleIndex.new() ret, failures = index.update_from_string(md, True) @@ -146,9 +159,9 @@ if md2: for stream in module.get_all_streams(): deps = stream.get_dependencies() for dep in deps: - req_modules = dep.get_runtime_modules() + req_modules = dep.get_runtime_modules() for req_module in req_modules: - if req_module == 'platform': + if req_module == "platform": continue req_streams = dep.get_runtime_streams(req_module) line = "" @@ -157,10 +170,11 @@ if md2: line = line.strip() if line: print(line) - #[expression(i) for i in old_list if filter(i)] - #[print("md_st") for req_stream in req_streams + # [expression(i) for i in old_list if filter(i)] + # [print("md_st") for req_stream in req_streams if md1 and not md2: + def get_nsvc(mmd): nsvc = "%s:%s:%s:%s" % ( mmd.peek_name(), @@ -169,6 +183,7 @@ if md1 and not md2: mmd.peek_context(), ) return nsvc + mmds = md1.objects_from_string(md) logger.debug("Found modules in {}: {}".format(args.modulemd, len(mmds))) if args.getfiltered: @@ -209,7 +224,7 @@ if md1 and not md2: for dep in deps: req_modules = dep.peek_requires() for req_module in req_modules: - if req_module == 'platform': + if req_module == "platform": continue req_streams = req_modules[req_module].get() line = "" @@ -218,6 +233,5 @@ if md1 and not md2: line = line.strip() if line: print(line) - #[expression(i) for i in old_list if filter(i)] - #[print("md_st") for req_stream in req_streams - + # [expression(i) for i in old_list if filter(i)] + # [print("md_st") for req_stream in req_streams diff --git a/mtps-prepare-system b/mtps-prepare-system index 976de6e..e128ba4 100755 --- a/mtps-prepare-system +++ b/mtps-prepare-system @@ -37,7 +37,7 @@ Options: -h, --help display this help and exit -v, --verbose turn on debug -p, --profile=PROFILE use profile --f, --fixrepo fix repo to specific compose ID. Resolve the latest to +-f, --fixrepo fix repo to specific compose ID. Resolve the latest to -l, --list list available profiles --optrepo=REPO1 --optrepo=REPO2 use optional repos --optlist list available profiles diff --git a/mtps-run-tests b/mtps-run-tests index c496f2d..261c2fc 100755 --- a/mtps-run-tests +++ b/mtps-run-tests @@ -176,7 +176,7 @@ if [ -z "${nevras_in_repo// /}" ]; then exit 1 fi -# Prefixe all files with common suffix +# Prefix all files with common suffix ret=0 for nevra in $nevras_in_repo; do # Make 1 sec between audit entries diff --git a/mtps-setup b/mtps-setup index a2b010e..e0fc046 100755 --- a/mtps-setup +++ b/mtps-setup @@ -63,4 +63,3 @@ debug() { echo "$*" >&2 fi } - diff --git a/mtps-tag b/mtps-tag index ee199e7..9611b8b 100755 --- a/mtps-tag +++ b/mtps-tag @@ -25,7 +25,7 @@ tasks_id_from_answer() { local xml="$1" && shift local tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" - local cmd="cat //member[name='task_id']//value/int/text()" + local cmd="cat //member[name='task_id']//value/int/text()" local tasks="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:digit:]]/p')" debug "Tag has next tasks:" debug "$tasks" @@ -37,7 +37,7 @@ nvrs_from_answer() { local xml="$1" && shift local tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" - local cmd="cat //member[name='nvr']//value/string/text()" + local cmd="cat //member[name='nvr']//value/string/text()" local nvrs="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" debug "Tag has next tasks:" debug "$nvrs" diff --git a/profiles/rhel/prepare-system b/profiles/rhel/prepare-system index acf8777..e248934 100644 --- a/profiles/rhel/prepare-system +++ b/profiles/rhel/prepare-system @@ -59,4 +59,4 @@ yum install -y createrepo_c yum update -y yum clean all -yum makecache \ No newline at end of file +yum makecache diff --git a/profiles/rhel/repos/rhel-9.5.0.repo b/profiles/rhel/repos/rhel-9.5.0.repo index 6d481ce..772f592 100644 --- a/profiles/rhel/repos/rhel-9.5.0.repo +++ b/profiles/rhel/repos/rhel-9.5.0.repo @@ -215,4 +215,3 @@ gpgcheck=0 skip_if_unavailable=True # Enable module_hotfixes to fix https://issues.redhat.com/browse/OSCI-2620 module_hotfixes=1 - diff --git a/viewer/generate-result-json b/viewer/generate-result-json index a687fdb..16a9043 100755 --- a/viewer/generate-result-json +++ b/viewer/generate-result-json @@ -4,11 +4,7 @@ import os import sys import json -RESULTS_MAPPING = { - "PASS": "OK", - "WARN": "INFO", - "FAIL": "BAD" -} +RESULTS_MAPPING = {"PASS": "OK", "WARN": "INFO", "FAIL": "BAD"} mtps_log_dir = sys.argv[1] @@ -16,7 +12,7 @@ results = {} for log_file in os.listdir(mtps_log_dir): # For example: # FAIL-045051-install-systemd-standalone-sysusers-0:252-2.el9.x86_64.log - result, test_run_id, test_name, test_object = log_file[:-len(".log")].split("-", 3) + result, test_run_id, test_name, test_object = log_file[: -len(".log")].split("-", 3) if result not in RESULTS_MAPPING: # This is probably some file we do not want to handle. continue @@ -24,7 +20,9 @@ for log_file in os.listdir(mtps_log_dir): # Selinux test has the "selinux" infix, for example: # FAIL-selinux-045051-install-systemd-container-0:252-2.el9.x86_64.log if test_run_id == "selinux": - result, _, test_run_id, test_name, test_object = log_file[:-len(".log")].split("-", 4) + result, _, test_run_id, test_name, test_object = log_file[: -len(".log")].split( + "-", 4 + ) test_object += " (selinux AVCs)" # The mtps log file with mtps-get-task object contains information about @@ -46,10 +44,12 @@ for log_file in os.listdir(mtps_log_dir): if test_object: message += ": " + test_object - results[test_name].append({ - "result": RESULTS_MAPPING[result], - "message": message, - "details": details, - }) + results[test_name].append( + { + "result": RESULTS_MAPPING[result], + "message": message, + "details": details, + } + ) print(json.dumps(results)) diff --git a/viewer/viewer.html b/viewer/viewer.html index b84a77f..7d49dbd 100644 --- a/viewer/viewer.html +++ b/viewer/viewer.html @@ -1,33 +1,36 @@ - + - - installability report viewer - + + installability report viewer + - - - - -
-

Installability

-
+ } + + + + +
+

Installability

+
SKIP OK INFO VERIFY BAD -
-
- -
-
-
-
- - - + selectedResultTypes = inspection.results; + }); + render(summary, document.getElementById("summary")); + + if (selectedInspection) + render( + renderInspection( + selectedInspection, + report[selectedInspection], + selectedResultTypes, + ), + document.getElementById("details"), + ); + } + const renderError = (error) => + render(error, document.getElementById("details")); + + /* + * main + */ + + const url = + new URLSearchParams(window.location.search).get("url") ?? "./result.json"; + try { + const response = await fetch(url); + if (response.ok) renderResults(await response.json()); + else + renderError( + `Failed to fetch ${url}: ${response.status} ${response.statusText}`, + ); + } catch (error) { + renderError(`Failed to fetch ${url}: ${error}`); + } + From 48b23471cefbb685bc44713b0216d67f7e3a7db4 Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Thu, 23 Nov 2023 18:20:39 +0100 Subject: [PATCH 2/9] Fix shellcheck errors https://github.com/koalaman/shellcheck/wiki/SC2068 https://github.com/koalaman/shellcheck/wiki/SC2152 --- .pre-commit-config.yaml | 7 +++++++ mtps-get-task | 2 +- mtps-pkg-test | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 55948e7..fe15462 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,6 +21,13 @@ repos: - id: ruff-format - id: ruff args: [--fix, --exit-non-zero-on-fix] + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.9.0.6 + hooks: + - id: shellcheck + args: [--severity=error] + # unused ? + exclude: (ver_cmp.sh|mtps*-xunit|mtps-tag|mtps-run-mtests|mtps-module-test) ci: autoupdate_schedule: quarterly diff --git a/mtps-get-task b/mtps-get-task index dcceca1..fa10fc2 100755 --- a/mtps-get-task +++ b/mtps-get-task @@ -746,7 +746,7 @@ if [ ${#urls[@]} -eq 0 ]; then fi # Download RPMs -for url in ${urls[@]}; do +for url in "${urls[@]}"; do echo "$url" download_rpm "$url" done diff --git a/mtps-pkg-test b/mtps-pkg-test index 4d1694f..9643a5a 100755 --- a/mtps-pkg-test +++ b/mtps-pkg-test @@ -96,7 +96,7 @@ nevra_older_then() { return 0 fi # False - return -1 + return 1 } run_with_scriptlet_check() { From 6c569b05b31ec7dc0ebb8ec543b5c6c11e516b00 Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Fri, 24 Nov 2023 11:22:46 +0100 Subject: [PATCH 3/9] Use packit to build in copr https://packit.dev/docs/configuration Building from main are enabled in https://copr.fedorainfracloud.org/coprs/g/osci/mini-tps but commented out here because we don't want it until we have a good CI. --- .packit.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .packit.yaml diff --git a/.packit.yaml b/.packit.yaml new file mode 100644 index 0000000..ae01a7f --- /dev/null +++ b/.packit.yaml @@ -0,0 +1,19 @@ +--- +jobs: + - job: copr_build + trigger: pull_request + targets: + - fedora-all + - epel-7 + - epel-8 + - epel-9 +# - job: copr_build +# trigger: commit +# branch: main +# targets: +# - fedora-all +# - epel-7 +# - epel-8 +# - epel-9 +# owner: "@osci" +# project: mini-tps From 85f9094959ea2008260709ea046183f0aa283072 Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Fri, 24 Nov 2023 11:54:24 +0100 Subject: [PATCH 4/9] Spec: URL update --- mini-tps.spec | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mini-tps.spec b/mini-tps.spec index 09d5bed..33ca8d3 100644 --- a/mini-tps.spec +++ b/mini-tps.spec @@ -1,10 +1,10 @@ Name: mini-tps Version: 0.1 -Release: 161%{?dist} +Release: 162%{?dist} Summary: Mini TPS - Test Package Sanity License: GPLv2 -URL: https://gitlab.cee.redhat.com/osci/mini-tps +URL: https://github.com/fedora-ci/mini-tps Source0: %{name}.tar.gz Requires: yum-utils # List of packages for wich do not run 'remove' test. @@ -22,7 +22,7 @@ Requires: libselinux-utils Light version of TPS %prep -%setup -n %{name} +%autosetup -n %{name} %build @@ -63,6 +63,9 @@ cp -pf profiles/fedora/prepare-system %{buildroot}%{_libexecdir}/mini-tps/fedora %{_libexecdir}/mini-tps/* %changelog +* Fri Nov 24 2023 Jiri Popelka - 0.1-162 +- URL update + * Mon Jul 31 2023 Andrei Stepanov - 0.1-161 - new build From 25bd82a157b3e305c410027290753fff1aedb45b Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Fri, 24 Nov 2023 12:46:17 +0100 Subject: [PATCH 5/9] /bin/bash -> /usr/bin/bash --- mtps-enable-mod-reqs | 2 +- mtps-gen-xunit | 2 +- mtps-get-builds | 2 +- mtps-get-module | 2 +- mtps-get-task | 2 +- mtps-module-test | 2 +- mtps-pkg-test | 2 +- mtps-prepare-system | 2 +- mtps-run-mtests | 2 +- mtps-run-tests | 2 +- mtps-setup | 2 +- mtps-tag | 2 +- mtps-xunit | 2 +- profiles/centos-stream/prepare-system | 2 +- profiles/fedora/prepare-system | 2 +- ver_cmp.sh | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/mtps-enable-mod-reqs b/mtps-enable-mod-reqs index 202d89a..ec7ce12 100755 --- a/mtps-enable-mod-reqs +++ b/mtps-enable-mod-reqs @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/mtps-gen-xunit b/mtps-gen-xunit index ecb6f2c..4629cd5 100755 --- a/mtps-gen-xunit +++ b/mtps-gen-xunit @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/mtps-get-builds b/mtps-get-builds index 3f95e93..4b5ed62 100755 --- a/mtps-get-builds +++ b/mtps-get-builds @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/mtps-get-module b/mtps-get-module index 3b38b7e..705ff11 100755 --- a/mtps-get-module +++ b/mtps-get-module @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/mtps-get-task b/mtps-get-task index fa10fc2..f7c3201 100755 --- a/mtps-get-task +++ b/mtps-get-task @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu shopt -s extglob diff --git a/mtps-module-test b/mtps-module-test index 3420bc4..120e16f 100755 --- a/mtps-module-test +++ b/mtps-module-test @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/mtps-pkg-test b/mtps-pkg-test index 9643a5a..609364b 100755 --- a/mtps-pkg-test +++ b/mtps-pkg-test @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/mtps-prepare-system b/mtps-prepare-system index e128ba4..c95c614 100755 --- a/mtps-prepare-system +++ b/mtps-prepare-system @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/mtps-run-mtests b/mtps-run-mtests index c88affd..67e8996 100755 --- a/mtps-run-mtests +++ b/mtps-run-mtests @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/mtps-run-tests b/mtps-run-tests index 261c2fc..8016a58 100755 --- a/mtps-run-tests +++ b/mtps-run-tests @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/mtps-setup b/mtps-setup index e0fc046..cf4f9cb 100755 --- a/mtps-setup +++ b/mtps-setup @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/mtps-tag b/mtps-tag index 9611b8b..9aba5dd 100755 --- a/mtps-tag +++ b/mtps-tag @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/mtps-xunit b/mtps-xunit index 110f656..ecc6245 100755 --- a/mtps-xunit +++ b/mtps-xunit @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/profiles/centos-stream/prepare-system b/profiles/centos-stream/prepare-system index b06ee56..a1c3f60 100644 --- a/profiles/centos-stream/prepare-system +++ b/profiles/centos-stream/prepare-system @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/profiles/fedora/prepare-system b/profiles/fedora/prepare-system index c59a75c..98391b2 100755 --- a/profiles/fedora/prepare-system +++ b/profiles/fedora/prepare-system @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/ver_cmp.sh b/ver_cmp.sh index 6ca6aea..96377b3 100755 --- a/ver_cmp.sh +++ b/ver_cmp.sh @@ -1,4 +1,4 @@ -#!/bin/bash -efu +#!/usr/bin/bash -efu DEBUG="${DEBUG:-}" From bc49e3acd30dcc441f030e466231bcabe26e5213 Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Tue, 28 Nov 2023 15:32:14 +0100 Subject: [PATCH 6/9] move mtps-* executables from /usr/local/bin/ to /usr/sbin/ Per rpmlint it's not permitted for packages to install files there. E: dir-or-file-in-usr-local Also use install instead of mkdir & cp. --- mini-tps.spec | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/mini-tps.spec b/mini-tps.spec index 33ca8d3..ca3f55c 100644 --- a/mini-tps.spec +++ b/mini-tps.spec @@ -27,44 +27,36 @@ Light version of TPS %build %install -mkdir -p %{buildroot}%{_prefix}/local/bin/ -cp -rfp mtps* %{buildroot}%{_prefix}/local/bin/ -mkdir -p %{buildroot}%{_sysconfdir}/dnf/protected.d -cp -pf mini-tps.conf %{buildroot}%{_sysconfdir}/dnf/protected.d/ - +mkdir -p %{buildroot}%{_sbindir} # epel7 +install -pD -m 0755 --target-directory=%{buildroot}%{_sbindir} mtps-* +install -pD -m 0644 mini-tps.conf %{buildroot}%{_sysconfdir}/dnf/protected.d/mini-tps.conf # viewer -mkdir -p %{buildroot}%{_datarootdir}/mini-tps/viewer/ -cp -pf viewer/viewer.html %{buildroot}%{_datarootdir}/mini-tps/viewer/ -mkdir -p %{buildroot}%{_libexecdir}/mini-tps/viewer/ -cp -pf viewer/generate-result-json %{buildroot}%{_libexecdir}/mini-tps/viewer/ +install -pD -m 0755 viewer/generate-result-json %{buildroot}%{_libexecdir}/mini-tps/viewer/generate-result-json +install -pD -m 0644 viewer/viewer.html %{buildroot}%{_datarootdir}/mini-tps/viewer/viewer.html # profiles mkdir -p %{buildroot}%{_datarootdir}/mini-tps/profiles/{rhel,centos-stream,fedora}/ -# rhel cp -rfp profiles/rhel/{repos,optrepos}/ %{buildroot}%{_datarootdir}/mini-tps/profiles/rhel/ -# centos-stream cp -rfp profiles/centos-stream/{repos,optrepos}/ %{buildroot}%{_datarootdir}/mini-tps/profiles/centos-stream/ -# fedora cp -rfp profiles/fedora/repos/ %{buildroot}%{_datarootdir}/mini-tps/profiles/fedora/ # prepare scripts -mkdir -p %{buildroot}%{_libexecdir}/mini-tps/{rhel,centos-stream,fedora}/ -# rhel -cp -pf profiles/rhel/prepare-system %{buildroot}%{_libexecdir}/mini-tps/rhel/ -# centos-stream -cp -pf profiles/centos-stream/prepare-system %{buildroot}%{_libexecdir}/mini-tps/centos-stream/ -# fedora -cp -pf profiles/fedora/prepare-system %{buildroot}%{_libexecdir}/mini-tps/fedora/ +install -pD -m 0755 profiles/rhel/prepare-system %{buildroot}%{_libexecdir}/mini-tps/rhel/prepare-system +install -pD -m 0755 profiles/centos-stream/prepare-system %{buildroot}%{_libexecdir}/mini-tps/centos-stream/prepare-system +install -pD -m 0755 profiles/fedora/prepare-system %{buildroot}%{_libexecdir}/mini-tps/fedora/prepare-system %files -%{_prefix}/local/bin/mtps* -%{_sysconfdir}/dnf/protected.d/mini-tps.conf +%{_sbindir}/mtps-* +%config %{_sysconfdir}/dnf/protected.d/mini-tps.conf %{_datarootdir}/mini-tps/* %{_libexecdir}/mini-tps/* + %changelog * Fri Nov 24 2023 Jiri Popelka - 0.1-162 - URL update +- move mtps-* executables from /usr/local/bin/ to /usr/sbin/ +- use install instead of mkdir & cp * Mon Jul 31 2023 Andrei Stepanov - 0.1-161 - new build From af98a9e402f4f62812f991f658798513f85bf8e0 Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Fri, 24 Nov 2023 19:42:59 +0100 Subject: [PATCH 7/9] Fix some shellcheck warnings Also use : "${VARIABLE:=default}" to define a default value for a variable. It's more simple than VARIABLE="${VARIABLE:-default}" and less typo-prone (this change fixes some typos). Also fixes /usr/local/bin/mtps-setup: line 62: DEBUG: unbound variable when running the pipeline on module build. --- mtps-enable-mod-reqs | 18 +++--- mtps-get-builds | 11 ++-- mtps-get-module | 112 ++++++++++++++++++--------------- mtps-get-task | 118 ++++++++++++++++++++--------------- mtps-module-test | 2 +- mtps-mutils | 48 +++++--------- mtps-pkg-test | 35 +++++------ mtps-prepare-system | 44 +++++++------ mtps-run-mtests | 4 +- mtps-run-tests | 34 +++++----- mtps-setup | 2 +- mtps-tag | 2 +- mtps-xunit | 8 +-- profiles/rhel/prepare-system | 8 +-- ver_cmp.sh | 2 +- 15 files changed, 228 insertions(+), 220 deletions(-) diff --git a/mtps-enable-mod-reqs b/mtps-enable-mod-reqs index ec7ce12..c736351 100755 --- a/mtps-enable-mod-reqs +++ b/mtps-enable-mod-reqs @@ -15,7 +15,7 @@ # Author: Andrei Stepanov -PROG="${PROG:-${0##*/}}" +: "${PROG:=${0##*/}}" # Source `mtps-setup' from $PATH if command -v "mtps-setup" >/dev/null; then source "mtps-setup"; fi @@ -48,7 +48,6 @@ box_out() { echo -e "| ${b//?/ } |\n-${b//?/-}-" } -# http://wiki.bash-hackers.org/howto/getopts_tutorial opt_str="$@" opt=$(getopt -n "$0" --options "hvt:s:m:" --longoptions "help,verbose,mmd:,test:,selinux:" -- "$@") eval set -- "$opt" @@ -78,12 +77,9 @@ done # Entry -DEBUG="${DEBUG:-}" -MMD="${MMD:-}" -# Put logs by default at CDIR/mtps-logs -LOGS_DIR="${LOGS_DIR:-mtps-logs}" +: "${DEBUG:=}" -debug "MMD: $MMD" +debug "MMD: ${MMD:=}" debug "Use ${YUMDNFCMD}" # Test correct invocation @@ -107,7 +103,9 @@ box_out "# DEPENDENCY" "" "Modules to be enabled:" "" "${requires_list[@]:-}" # Prefix all files with common suffix TESTRUN_ID="$(date +%H%M%S)" -mkdir -p "$LOGS_DIR" + +# Put logs by default at CWD/mtps-logs +mkdir -p "${LOGS_DIR:=mtps-logs}" for require in "${requires[@]}"; do ret=1 @@ -127,7 +125,7 @@ for require in "${requires[@]}"; do "" \ " Name: $name" \ " Stream: $stream" - logfname="${LOGS_DIR%%/}/$TESTRUN_ID-enable-$name-$stream.log" + logfname="${LOGS_DIR%%/}/${TESTRUN_ID}-enable-${name}-${stream}.log" echo "Reset module: $name" | tee -a "$logfname" "${YUMDNFCMD}" -y module reset "$name" 2>&1 | tee -a "$logfname" test_status="${PIPESTATUS[0]}" @@ -150,7 +148,7 @@ for require in "${requires[@]}"; do fi done if [ "$ret" -ne "0" ]; then - echo "Fail to meet module dependecy. No one can be enabled from: ${require// / or }" + echo "Fail to meet module dependency. No one can be enabled from: ${require// / or }" exit 1 fi done diff --git a/mtps-get-builds b/mtps-get-builds index 4b5ed62..00394e3 100755 --- a/mtps-get-builds +++ b/mtps-get-builds @@ -205,7 +205,6 @@ GB_CREATEREPO="${GB_CREATEREPO:-}" GB_CREATEREPO_BIN="${GB_CREATEREPO_BIN:-}" GB_ONLYINREPO="${GB_ONLYINREPO:-}" GB_INSTALLREPOFILE="${GB_INSTALLREPOFILE:-}" -LOGS_DIR="${LOGS_DIR:-mtps-logs}" # http://wiki.bash-hackers.org/howto/getopts_tutorial opt_str="$@" @@ -261,14 +260,14 @@ if [ -z "$GB_BUILD" ]; then exit fi -mkdir -p "$LOGS_DIR" +mkdir -p "${LOGS_DIR:=mtps-logs}" LOGS_DIR="$(realpath "$LOGS_DIR")" while true; do TESTRUN_ID="$(date +%H%M%S)" logfname="${LOGS_DIR%%/}/${TESTRUN_ID}-${GB_BUILD}-mtps-get-builds.log" logfname_pass="$(dirname "$logfname")/PASS-$(basename "$logfname")" logfname_fail="$(dirname "$logfname")/FAIL-$(basename "$logfname")" - if [ -e "$logfname" -o -e "$logfname_pass" -o -e "$logfname_fail" ]; then + if [[ -e "$logfname" || -e "$logfname_pass" || -e "$logfname_fail" ]]; then sleep 1 continue fi @@ -281,7 +280,7 @@ do_clean_exit() { rc=$? trap - SIGINT SIGTERM SIGABRT EXIT # clear the trap new_logfname="$logfname_fail" - if [ "$rc" = "0" -o "$rc" = "111" ]; then + if [[ "$rc" -eq 0 || "$rc" -eq 111 ]]; then new_logfname="$logfname_pass" fi # Close tee pipes @@ -355,7 +354,7 @@ for pkg in $rpms_from_build_noarch; do download_rpm "$url" done -if [ -z "$GB_CREATEREPO" -o ! -d "$GB_REPODIR" ]; then +if [[ -z "$GB_CREATEREPO" || ! -d "$GB_REPODIR" ]]; then exit 0 fi @@ -373,7 +372,7 @@ echo "Repo file:" echo "$repo_file_text" id="$(id -u)" -if [ -n "$GB_INSTALLREPOFILE" -a "$id" = "0" ]; then +if [[ -n "$GB_INSTALLREPOFILE" && "$id" -eq 0 ]]; then repofile="/etc/yum.repos.d/brew-${brew_build_id}.repo" echo "Create repo file: $repofile" echo "$repo_file_text" > "$repofile" diff --git a/mtps-get-module b/mtps-get-module index 705ff11..eb222f9 100755 --- a/mtps-get-module +++ b/mtps-get-module @@ -21,7 +21,8 @@ if [ -z "${YUMDNFCMD:-}" ]; then source "$(dirname "${BASH_SOURCE[0]}")/mtps-set builds_from_answer() { local xml="$1" && shift - local tmpfile="$(mktemp)" + local tmpfile + tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" local cmd="cat //member[name='build_id']/value/int/text()" builds="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" @@ -33,7 +34,7 @@ builds_from_answer() { build_from_answer() { local xml="$1" && shift - local build_id= + local build_id build_id="$(echo "$xml" | xmllint --xpath 'string(//member[name="build_id"]/value/int/text())' -)" debug "Brew build id: $build_id" echo "$build_id" @@ -41,7 +42,7 @@ build_from_answer() { tag_from_answer() { local xml="$1" && shift - local brew_tag= + local brew_tag brew_tag="$(echo "$xml" | xmllint --xpath 'string(//member[name="content_koji_tag"]/value/string/text())' -)" debug "Brew tag: $brew_tag" echo "$brew_tag" @@ -49,10 +50,12 @@ tag_from_answer() { owner_from_answer() { local xml="$1" && shift - local tmpfile="$(mktemp)" + local tmpfile + tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" local cmd="cat //member[name='owner_name']/value/string/text()" - local owner="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" + local owner + owner="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" debug "Context generated build in Brew has owner name:" debug "$owner" debug "---" @@ -61,10 +64,12 @@ owner_from_answer() { mname_from_answer() { local xml="$1" && shift - local tmpfile="$(mktemp)" + local tmpfile + tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" local cmd="cat //member[name='package_name']/value/string/text()" - local name="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" + local name + name="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" debug "Module name:" debug "$name" debug "---" @@ -73,10 +78,12 @@ mname_from_answer() { nvr_from_answer() { local xml="$1" && shift - local tmpfile="$(mktemp)" + local tmpfile + tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" local cmd="cat //member[name='nvr']/value/string/text()" - local nvr="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" + local nvr + nvr="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" debug "Module NVR for context build in Brew:" debug "$nvr" debug "---" @@ -85,7 +92,8 @@ nvr_from_answer() { send_query() { local query="$1" && shift - local answer="$(curl --silent -k --data "$query" "$BREWHUB")" + local answer + answer="$(curl --silent -k --data "$query" "$BREWHUB")" #debug "Brew answer: ${answer:0:200}...(truncated)" debug "Brew answer: ${answer}" echo "$answer" @@ -186,48 +194,55 @@ mbsid2minfo() { local mbs_id="$1" && shift local url="$MBS/module-build-service/1/module-builds/$mbs_id" debug "URL to MBS: $url" - local minfo="$(curl --silent --retry 5 --insecure --location --fail --show-error "$url")" + local minfo + minfo="$(curl --silent --retry 5 --insecure --location --fail --show-error "$url")" echo "$minfo" } minfo2tag() { local minfo="$1" && shift - local tag="$(echo $minfo | sed -n -e '/component_builds/,/"koji_tag"/ s/^.\+"koji_tag":[[:space:]]\+"\(.\+\)"[\,[:space:]]*$/\1/p')" + local tag + tag="$(echo "$minfo" | sed -n -e '/component_builds/,/"koji_tag"/ s/^.\+"koji_tag":[[:space:]]\+"\(.\+\)"[\,[:space:]]*$/\1/p')" debug "MBS build has tag: $tag" echo "$tag" } minfo2name() { local minfo="$1" && shift - local name="$(echo "$minfo" | sed -n -e '/component_builds/,/"name"/ s/^.\+"name":[[:space:]]\+"\(.\+\)"[\,[:space:]]*$/\1/p')" + local name + name="$(echo "$minfo" | sed -n -e '/component_builds/,/"name"/ s/^.\+"name":[[:space:]]\+"\(.\+\)"[\,[:space:]]*$/\1/p')" debug "MBS build has name: $name" echo "$name" } minfo2stream() { local minfo="$1" && shift - local stream="$(echo "$minfo" | sed -n -e '/component_builds/,/"stream"/ s/^.\+"stream":[[:space:]]\+"\(.\+\)"[\,[:space:]]*$/\1/p')" + local stream + stream="$(echo "$minfo" | sed -n -e '/component_builds/,/"stream"/ s/^.\+"stream":[[:space:]]\+"\(.\+\)"[\,[:space:]]*$/\1/p')" debug "MBS build has stream: $stream" echo "$stream" } minfo2version() { local minfo="$1" && shift - local version="$(echo "$minfo" | sed -n -e '/component_builds/,/"version"/ s/^.\+"version":[[:space:]]\+"\(.\+\)"[\,[:space:]]*$/\1/p')" + local version + version="$(echo "$minfo" | sed -n -e '/component_builds/,/"version"/ s/^.\+"version":[[:space:]]\+"\(.\+\)"[\,[:space:]]*$/\1/p')" debug "MBS build has version: $version" echo "$version" } minfo2context() { local minfo="$1" && shift - local context="$(echo "$minfo" | sed -n -e '/component_builds/,/"context"/ s/^.\+"context":[[:space:]]\+"\(.\+\)"[\,[:space:]]*$/\1/p')" + local context + context="$(echo "$minfo" | sed -n -e '/component_builds/,/"context"/ s/^.\+"context":[[:space:]]\+"\(.\+\)"[\,[:space:]]*$/\1/p')" debug "MBS build has context: $context" echo "$context" } minfo2platformtag() { local minfo="$1" && shift - local koji_tag="$(echo "$minfo" | sed -n -e '/"platform"/,/koji_tag/ s/^.\+"koji_tag":[[:space:]]\+"\(.\+\)"[\,[:space:]]*$/\1/p')" + local koji_tag + koji_tag="$(echo "$minfo" | sed -n -e '/"platform"/,/koji_tag/ s/^.\+"koji_tag":[[:space:]]\+"\(.\+\)"[\,[:space:]]*$/\1/p')" debug "MBS build has platform module koji_tag: $koji_tag" echo "$koji_tag" } @@ -235,7 +250,8 @@ minfo2platformtag() { # https://docs.fedoraproject.org/en-US/modularity/making-modules/updating-modules/ tag2nvr() { local tag="$1" && shift - local nvr="$(echo "$tag" | sed -n -e "s/-\([[:alnum:]]\+\)$/\.\1/; s/^module-//p")" + local nvr + nvr="$(echo "$tag" | sed -n -e "s/-\([[:alnum:]]\+\)$/\.\1/; s/^module-//p")" debug "Brew '$tag' tag has module content build id: $nvr" echo "$nvr" } @@ -282,29 +298,27 @@ EOF # Entry -PROG="${PROG:-${0##*/}}" -DEBUG="${DEBUG:-}" -BREWHUB="${BREWHUB:-https://brewhub.engineering.redhat.com/brewhub}" -BREWPKGS="${BREWPKGS:-http://download.eng.bos.redhat.com/brewroot/packages}" -MBS="${MBS:-https://mbs.engineering.redhat.com}" -TAG="${TAG:-}" -GETINFO="${GETINFO:-}" -BREWINFO="${BREWINFO:-https://brewweb.engineering.redhat.com/brew/buildinfo?buildID=}" -BUILD="${BUILD:-}" -MBSID="${MBSID:-}" -PLATFORM_TAG="${PLATFORM_TAG:-}" -RHEL_XYZ="${RHEL_XYZ:-}" -ARCH="${ARCH:-$(uname -m)}" -REPODIR="${REPODIR:-repodir}" -DOWNLOAD="${DOWNLOAD:-}" -CREATEREPO="${CREATEREPO:-}" -CREATEREPO_BIN="${CREATEREPO_BIN:-}" -MODIFYREPO_BIN="${MODIFYREPO_BIN:-}" -ONLYINREPO="${ONLYINREPO:-}" -INSTALLREPOFILE="${INSTALLREPOFILE:-}" -LOGS_DIR="${LOGS_DIR:-mtps-logs}" - -# http://wiki.bash-hackers.org/howto/getopts_tutorial +: "${PROG:=${0##*/}}" +: "${DEBUG:=}" +: "${BREWHUB:=https://brewhub.engineering.redhat.com/brewhub}" +: "${BREWPKGS:=http://download.eng.bos.redhat.com/brewroot/packages}" +: "${MBS:=https://mbs.engineering.redhat.com}" +: "${TAG:=}" +: "${GETINFO:=}" +: "${BREWINFO:=https://brewweb.engineering.redhat.com/brew/buildinfo?buildID=}" +: "${BUILD:=}" +: "${MBSID:=}" +: "${PLATFORM_TAG:=}" +: "${RHEL_XYZ:=}" +: "${ARCH:=$(uname -m)}" +: "${REPODIR:=repodir}" +: "${DOWNLOAD:=}" +: "${CREATEREPO:=}" +: "${CREATEREPO_BIN:=}" +: "${MODIFYREPO_BIN:=}" +: "${ONLYINREPO:=}" +: "${INSTALLREPOFILE:=}" + opt_str="$@" opt=$(getopt -n "$0" --options "hvd:b:a:m:t:cio" --longoptions "help,verbose,download:,build:,arch:,mbsid:,tag:,getinfo,createrepo,installrepofile,onlyinrepo" -- "$@") eval set -- "$opt" @@ -364,9 +378,9 @@ while [[ $# -gt 0 ]]; do esac done -mkdir -p "$LOGS_DIR" +mkdir -p "${LOGS_DIR:=mtps-logs}" TESTRUN_ID="$(date +%H%M%S)" -logfname="${LOGS_DIR%%/}/$TESTRUN_ID-mtps-get-module.log" +logfname="${LOGS_DIR%%/}/${TESTRUN_ID}-mtps-get-module.log" exec &> >(tee -a "$logfname") exec 2>&1 @@ -383,7 +397,7 @@ if [ -z "${BUILD}${MBSID}${TAG}" ]; then exit fi MSTREAM="" -if [ -z "$BUILD" -a -n "$MBSID" ]; then +if [[ -z "$BUILD" && -n "$MBSID" ]]; then MINFO="$(mbsid2minfo "$MBSID")" MNAME="$(minfo2name "$MINFO")" MSTREAM="$(minfo2stream "$MINFO")" @@ -409,7 +423,7 @@ m_owner_name="$(owner_from_answer "$answer_m_build")" # It is better to use stream from modulemd file, because the one in the Brew NVR # contains "-" replaced with "_" and it is not possible to guess wheter the stream # contained "-" which were changed to "_" or it really contained "_" characters. -if [ -z "$MSTREAM" ]; then +if [[ -z "$MSTREAM" ]]; then m_stream="$(from_module_name "$m_nvr" "stream")" else m_stream="$MSTREAM" @@ -441,7 +455,7 @@ answer_builds="$(send_query "$query_builds_in_m")" builds_in_m="$(builds_from_answer "$answer_builds")" builds_in_m="${builds_in_m// /}" -if [ -z "$builds_in_m" ]; then +if [[ -z "$builds_in_m" ]]; then echo "This module build doesn't have builds." exit 0 fi @@ -479,7 +493,7 @@ for f in "${PKG_FILES[@]}"; do fi done -if [ -z "$CREATEREPO" -o ! -d "$REPODIR" ]; then +if [[ -z "$CREATEREPO" || ! -d "$REPODIR" ]]; then exit 0 fi @@ -489,7 +503,7 @@ which 'createrepo' >/dev/null 2>&1 && CREATEREPO_BIN="createrepo" || : which 'createrepo_c' >/dev/null 2>&1 && CREATEREPO_BIN="createrepo_c" || : which 'modifyrepo' >/dev/null 2>&1 && MODIFYREPO_BIN="modifyrepo" || : which 'modifyrepo_c' >/dev/null 2>&1 && MODIFYREPO_BIN="modifyrepo_c" || : -if [ -z "$CREATEREPO_BIN" -o -z "$MODIFYREPO_BIN" ]; then +if [[ -z "$CREATEREPO_BIN" || -z "$MODIFYREPO_BIN" ]]; then echo "Install createrepo[_c] to create repositories." exit 0 fi @@ -502,7 +516,7 @@ echo "Repo file:" echo "$repo_file_text" id="$(id -u)" -if [ -n "$INSTALLREPOFILE" -a "$id" = "0" ]; then +if [[ -n "$INSTALLREPOFILE" && "$id" -eq 0 ]]; then repofile="/etc/yum.repos.d/brew-${m_build_id}.repo" echo "Create repo file: $repofile" echo "$repo_file_text" > "$repofile" diff --git a/mtps-get-task b/mtps-get-task index f7c3201..1e61177 100755 --- a/mtps-get-task +++ b/mtps-get-task @@ -26,10 +26,12 @@ RET_NO_PKG=7 rpms_from_answer() { local arch="$1" && shift local xml="$1" && shift - local tmpfile="$(mktemp)" + local tmpfile + tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" local cmd="cat //member[name='rpms']//value/string/text()" - local rpm="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p' | sed -n -e "/\.$arch\.rpm/p")" + local rpm + rpm="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p' | sed -n -e "/\.$arch\.rpm/p")" debug "Arch $arch has next rpms:" debug "$rpm" debug "---" @@ -38,10 +40,12 @@ rpms_from_answer() { srpms_from_answer() { local xml="$1" && shift - local tmpfile="$(mktemp)" + local tmpfile + tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" local cmd="cat //member[name='srpms']//value/string/text()" - local srpm="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p' | sed -n -e "/\.rpm/p")" + local srpm + srpm="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p' | sed -n -e "/\.rpm/p")" debug "Has next srpms:" debug "$srpm" debug "---" @@ -50,7 +54,7 @@ srpms_from_answer() { is_scratch_from_answer() { local xml="$1" && shift - local is_scratch= + local is_scratch is_scratch="$(echo "$xml" | xmllint --xpath 'string(//member[name="scratch"]/value/boolean/text())' -)" [[ "$is_scratch" == '1' ]] && is_scratch="yes" || is_scratch="no" debug "Is scratch: $is_scratch" @@ -59,7 +63,7 @@ is_scratch_from_answer() { volume_name_from_answer() { local xml="$1" && shift - local volume_name= + local volume_name volume_name="$(echo "$xml" | xmllint --xpath 'string(//member[name="volume_name"]/value/string/text())' -)" debug "Volume name: $volume_name" echo "$volume_name" @@ -67,7 +71,7 @@ volume_name_from_answer() { build_source_from_answer() { local xml="$1" && shift - local build_source= + local build_source build_source="$(echo "$xml" | xmllint --xpath 'string(//member[name="source"]/value/string/text())' -)" debug "Build source: $build_source" echo "$build_source" @@ -75,7 +79,7 @@ build_source_from_answer() { nvr_from_answer() { local xml="$1" && shift - local nvr= + local nvr nvr="$(echo "$xml" | xmllint --xpath 'string(//member[name="nvr"]/value/string/text())' -)" debug "NVR: $nvr" echo "$nvr" @@ -83,7 +87,7 @@ nvr_from_answer() { buildid_from_answer() { local xml="$1" && shift - local buildid= + local buildid buildid="$(echo "$xml" | xmllint --xpath 'string(//member[name="build_id"]/value/int/text())' -)" debug "buildid: $buildid" echo "$buildid" @@ -91,10 +95,12 @@ buildid_from_answer() { buildtags_from_answer() { local xml="$1" && shift - local tmpfile="$(mktemp)" + local tmpfile + tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" local cmd="cat //member[name='name']/value/string/text()" - local tags="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" + local tags + tags="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" debug "Build has next tags:" debug "$tags" debug "---" @@ -103,10 +109,12 @@ buildtags_from_answer() { children_from_answer() { local xml="$1" && shift - local tmpfile="$(mktemp)" + local tmpfile + tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" local cmd="cat //member[name='id']/value/int/text()" - local children="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" + local children + children="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" debug "Task has next children:" debug "$children" debug "---" @@ -115,7 +123,8 @@ children_from_answer() { send_query() { local query="$1" && shift - local answer="$(curl --silent -k --data "$query" "$BREWHUB")" + local answer + answer="$(curl --silent -k --data "$query" "$BREWHUB")" debug "Brew answer: ${answer:0:200}...(truncated)" echo "$answer" } @@ -274,10 +283,12 @@ EOF taskinfo2owner() { local xml="$1" && shift - local tmpfile="$(mktemp)" + local tmpfile + tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" local cmd="cat //member[name='owner']/value/int/text()" - local owner="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" + local owner + owner="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" debug "Task has owner id:" debug "$owner" debug "---" @@ -286,10 +297,12 @@ taskinfo2owner() { taskquery2target() { local xml="$1" && shift - local tmpfile="$(mktemp)" + local tmpfile + tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" local cmd="cat //params/param[1]/value/array/data[1]/value[2]/string/text()" - local target="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" + local target + target="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" debug "Task has target:" debug "$target" debug "---" @@ -298,10 +311,12 @@ taskquery2target() { ownerinfo2user() { local xml="$1" && shift - local tmpfile="$(mktemp)" + local tmpfile + tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" local cmd="cat //member[name='name']/value/string/text()" - local owner="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" + local owner + owner="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" debug "Task has owner name:" debug "$owner" debug "---" @@ -310,10 +325,12 @@ ownerinfo2user() { ownerinfo2krb() { local xml="$1" && shift - local tmpfile="$(mktemp)" + local tmpfile + tmpfile="$(mktemp)" echo "$xml" > "$tmpfile" local cmd="cat //member[name='krb_principal']/value/string/text()" - local email="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" + local email + email="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')" debug "Task has owner has email:" debug "$email" debug "---" @@ -491,26 +508,24 @@ mk_url() { # Entry -PROG="${PROG:-${0##*/}}" -ARCH="${ARCH:-$(uname -m)}" -DEBUG="${DEBUG:-}" -TASK="${TASK:-}" -SRPM="${SRPM:-}" -OWNER="${OWNER:-}" -REPOFILENAME="${REPOFILENAME:-}" -REPODIR="${REPODIR:-repodir}" -BREWHUB="${BREWHUB:-https://brewhub.engineering.redhat.com/brewhub}" -DOWNLOAD="${DOWNLOAD:-}" -BREWROOT="${BREWROOT:-http://download.eng.bos.redhat.com/brewroot}" -LOGS_DIR="${LOGS_DIR:-mtps-logs}" -RECURSIVE="${RECURSIVE:-}" -CREATEREPO="${CREATEREPO:-}" -ONLYINREPO="${ONLYINREPO:-}" -CREATEREPO_BIN="${CREATEREPO_BIN:-}" -INSTALLREPOFILE="${INSTALLREPOFILE:-}" - -# http://wiki.bash-hackers.org/howto/getopts_tutorial -opt_str="$@" +: "${PROG:=${0##*/}}" +: "${ARCH:=$(uname -m)}" +: "${DEBUG:=}" +: "${TASK:=}" +: "${SRPM:=}" +: "${OWNER:=}" +: "${REPOFILENAME:=}" +: "${REPODIR:=repodir}" +: "${BREWHUB:=https://brewhub.engineering.redhat.com/brewhub}" +: "${DOWNLOAD:=}" +: "${BREWROOT:=http://download.eng.bos.redhat.com/brewroot}" +: "${RECURSIVE:=}" +: "${CREATEREPO:=}" +: "${ONLYINREPO:=}" +: "${CREATEREPO_BIN:=}" +: "${INSTALLREPOFILE:=}" + +#opt_str="$@" opt=$(getopt -n "$0" --options "hvrd:t:a:cis" --longoptions "help,verbose,repofilename:,download:,task:,arch:,createrepo,installrepofile,onlyinrepo,owner,recursive,srpm" -- "$@") eval set -- "$opt" while [[ $# -gt 0 ]]; do @@ -579,14 +594,14 @@ if [ -z "$TASK" ]; then exit fi -mkdir -p "$LOGS_DIR" +mkdir -p "${LOGS_DIR:=mtps-logs}" LOGS_DIR="$(realpath "$LOGS_DIR")" while true; do TESTRUN_ID="$(date +%H%M%S)" - logfname="${LOGS_DIR%%/}/$TESTRUN_ID-$TASK-mtps-get-task.log" + logfname="${LOGS_DIR%%/}/${TESTRUN_ID}-${TASK}-mtps-get-task.log" logfname_pass="$(dirname "$logfname")/PASS-$(basename "$logfname")" logfname_fail="$(dirname "$logfname")/FAIL-$(basename "$logfname")" - if [ -e "$logfname" -o -e "$logfname_pass" -o -e "$logfname_fail" ]; then + if [[ -e "$logfname" || -e "$logfname_pass" || -e "$logfname_fail" ]]; then sleep 1 continue fi @@ -727,7 +742,7 @@ fi rpms_from_task_all="${rpms_from_task_all%%+( )}" rpms_from_task_noarch_all="${rpms_from_task_noarch_all%%+( )}" if [ -z "${rpms_from_task_all}${rpms_from_task_noarch_all}" ]; then - echo "Brew repo doesn't have rpms for $ARCH and noarch" + echo "Brew repo doesn't have rpms for $ARCH/noarch" echo "Exit with special exit code: $RET_NO_PKG" exit "$RET_NO_PKG" fi @@ -740,8 +755,8 @@ done if [ ${#urls[@]} -eq 0 ]; then echo "This build doesn't have packages for testing." - echo "Brew repo has next rpms for $ARCH and noarch: $rpms_from_task_all $rpms_from_task_noarch_all" - echo "No one of the above packages is present in current repos." + echo "${ARCH}/noarch rpms in the Brew repo: $rpms_from_task_all $rpms_from_task_noarch_all" + echo "None of the above packages is present in current repos." exit 1 fi @@ -751,7 +766,7 @@ for url in "${urls[@]}"; do download_rpm "$url" done -if [ -z "$CREATEREPO" -o ! -d "$REPODIR" ]; then +if [[ -z "$CREATEREPO" || ! -d "$REPODIR" ]]; then exit 0 fi @@ -773,12 +788,13 @@ echo "Repo file:" echo "$repo_file_text" id="$(id -u)" -if [ -n "$INSTALLREPOFILE" -a "$id" = "0" ]; then +if [[ -n "$INSTALLREPOFILE" && "$id" -eq 0 ]]; then if [ -n "$REPOFILENAME" ]; then - repofile="/etc/yum.repos.d/$REPOFILENAME.repo" + repofile="/etc/yum.repos.d/${REPOFILENAME}.repo" else repofile="/etc/yum.repos.d/brew-${TASK}.repo" fi + echo "Create repo file: $repofile" echo "$repo_file_text" > "$repofile" fi diff --git a/mtps-module-test b/mtps-module-test index 120e16f..7557586 100755 --- a/mtps-module-test +++ b/mtps-module-test @@ -110,7 +110,7 @@ debug "NSVC: $NSVC" debug "PROFILE: $PROFILE" # Test correct invocation -if [ -z "$NSVC" ] || ! [ "$TEST" = "install" -o "$TEST" = "remove" ]; then +if [ -z "$NSVC" ] || ! [[ "$TEST" == "install" || "$TEST" == "remove" ]]; then echo "Use: $PROG -h for help." exit fi diff --git a/mtps-mutils b/mtps-mutils index 0d2b87e..bed869c 100755 --- a/mtps-mutils +++ b/mtps-mutils @@ -115,15 +115,13 @@ if md2: for name in module_names: module = index.get_module(name) for stream in module.get_all_streams(): - filtered = stream.get_rpm_filters() - for filtered in filtered: + for filtered in stream.get_rpm_filters(): print(filtered) if args.getfartifacts: for name in module_names: module = index.get_module(name) for stream in module.get_all_streams(): - artifacts = stream.get_rpm_artifacts() - for artifact in artifacts: + for artifact in stream.get_rpm_artifacts(): print(artifact) if args.getprofiles: for name in module_names: @@ -140,32 +138,26 @@ if md2: for name in module_names: module = index.get_module(name) for stream in module.get_all_streams(): - context = stream.get_context() - print(context) + print(stream.get_context()) if args.getversion: for name in module_names: module = index.get_module(name) for stream in module.get_all_streams(): - version = stream.get_version() - print(version) + print(stream.get_version()) if args.getnsvc: for name in module_names: module = index.get_module(name) - nsvc = get_nsvc(module) - print(nsvc) + print(get_nsvc(module)) if args.getrequires: for name in module_names: module = index.get_module(name) for stream in module.get_all_streams(): - deps = stream.get_dependencies() - for dep in deps: - req_modules = dep.get_runtime_modules() - for req_module in req_modules: + for dep in stream.get_dependencies(): + for req_module in dep.get_runtime_modules(): if req_module == "platform": continue - req_streams = dep.get_runtime_streams(req_module) line = "" - for req_stream in req_streams: + for req_stream in dep.get_runtime_streams(req_module): line += " " + req_module + ":" + req_stream line = line.strip() if line: @@ -188,31 +180,25 @@ if md1 and not md2: logger.debug("Found modules in {}: {}".format(args.modulemd, len(mmds))) if args.getfiltered: for mmd in mmds: - filtered = mmd.peek_rpm_filter().get() - for filtered in filtered: + for filtered in mmd.peek_rpm_filter().get(): print(filtered) if args.getfartifacts: for mmd in mmds: - artifacts = mmd.peek_rpm_artifacts().get() - for artifact in artifacts: + for artifact in mmd.peek_rpm_artifacts().get(): print(artifact) if args.getprofiles: for mmd in mmds: - profiles = mmd.peek_profiles().keys() - for profile in profiles: + for profile in mmd.peek_profiles().keys(): print(profile) if args.getstream: for mmd in mmds: - stream = mmd.peek_stream() - print(stream) + print(mmd.peek_stream()) if args.getcontext: for mmd in mmds: - context = mmd.peek_context() - print(context) + print(mmd.peek_context()) if args.getversion: for mmd in mmds: - version = mmd.peek_version() - print(version) + print(mmd.peek_version()) if args.getnsvc: for mmd in mmds: nsvc = get_nsvc(mmd) @@ -220,15 +206,13 @@ if md1 and not md2: print(nsvc) if args.getrequires: for mmd in mmds: - deps = mmd.peek_dependencies() - for dep in deps: + for dep in mmd.peek_dependencies(): req_modules = dep.peek_requires() for req_module in req_modules: if req_module == "platform": continue - req_streams = req_modules[req_module].get() line = "" - for req_stream in req_streams: + for req_stream in req_modules[req_module].get(): line += " " + req_module + ":" + req_stream line = line.strip() if line: diff --git a/mtps-pkg-test b/mtps-pkg-test index 609364b..354eadd 100755 --- a/mtps-pkg-test +++ b/mtps-pkg-test @@ -33,7 +33,7 @@ # * http://download.devel.redhat.com/nightly/latest-RHEL-8/compose/AppStream # -PROG="${PROG:-${0##*/}}" +: "${PROG:=${0##*/}}" # Source `mtps-setup' from $PATH if command -v "mtps-setup" >/dev/null; then source "mtps-setup"; fi @@ -90,7 +90,8 @@ nevra_older_then() { local arch2="$(from_nevra "$nevra2" "arch")" nevra1="${name1}-${epoch1}:${version1}-${release1}" nevra2="${name2}-${epoch2}:${version2}-${release2}" - local rcmp="$(rpm --define "pkg1 $nevra1" --define "pkg2 $nevra2" --eval '%{lua: print(rpm.vercmp(rpm.expand("%pkg1"), rpm.expand("%pkg2")))}')" + local rcmp + rcmp="$(rpm --define "pkg1 $nevra1" --define "pkg2 $nevra2" --eval '%{lua: print(rpm.vercmp(rpm.expand("%pkg1"), rpm.expand("%pkg2")))}')" if [ "x$rcmp" = "x-1" ]; then # True return 0 @@ -116,7 +117,7 @@ run_with_scriptlet_check() { # Preserve return code from the command local ret=${PIPESTATUS[0]} cmd_output_parts_prefix="cmd-output-part" - if [ "$ret" -eq "0" ]; then + if [ "$ret" -eq 0 ]; then # The script is running with globbing off, but it's useful here, so let's enabled it temporarily set +f rm -f "$cmd_output_parts_prefix"* @@ -132,7 +133,7 @@ run_with_scriptlet_check() { # Remove epoch from the NEVRA under test test_nvra=$(echo "$NEVRA" | sed -e 's/-[0-9]\+:/-/') # Check if the NVRA matches the NVRA under test - if [ "$test_nvra" == "$scriptlet_nvra" ]; then + if [[ "$test_nvra" == "$scriptlet_nvra" ]]; then # We found a part of the output that matters, let's look for problematic words here; # However, let's filter out lines with known false positives first: # Ignore warning about a new .rpmsave file (https://access.redhat.com/solutions/60263) @@ -150,7 +151,7 @@ run_with_scriptlet_check() { # the reason is that the keyword ("error" for example) can appear in package names. # See how the regexp works (and play with it!): https://regex101.com/r/Yws0tT/1 grep -P -i -q '(?/dev/null; then source "mtps-setup"; fi @@ -45,26 +45,27 @@ Options: EOF } -DEBUG="${DEBUG:-}" -PROFILE="${RPOFILE:-}" +: "${DEBUG:=}" +: "${PROFILE:=}" +: "${LIST:=}" +: "${OPTLIST:=}" +: "${ENABLE_BUILD_ROOT:=}" +: "${FIXREPO:=}" +: "${PFILE:=}" + declare -a OPTREPOS OPTREPOS=() -LIST="${LIST:-}" -OPTLIST="${OPTLIST:-}" -ENABLE_BUILD_ROOT="${ENABLE_BUILD_ROOT:-}" -FIXREPO="${FIXREPO:-}" -PFILE="${PFILE:-}" + +# shellcheck disable=SC2034 REPOFILE="/etc/yum.repos.d/mini-tps.repo" +# shellcheck disable=SC2034 REPOFILE_OPT_PREFIX="mini-tps-opt" -PROFILES_TOPDIR="${PROFILESTOP_DIR:-$(rpm --eval %_datarootdir)/mini-tps/profiles/}" -if ! [ -d "$PROFILES_TOPDIR" ]; then - PROFILES_TOPDIR="$PWD/profiles/" - debug "Use dir for profiles: $PROFILES_TOPDIR" +if ! [ -d "${PROFILES_TOPDIR:=$(rpm --eval %_datarootdir)/mini-tps/profiles/}" ]; then + debug "Use dir for profiles: ${PROFILES_TOPDIR:="$PWD/profiles/"}" fi -# http://wiki.bash-hackers.org/howto/getopts_tutorial -opt_str="$@" +#opt_str="$@" opt=$(getopt -n "$0" --options "hvfp:l" --longoptions "help,fixrepo,verbose,enablebuildroot,profile:,list,optlist,optrepo:" -- "$@") eval set -- "$opt" while [[ $# -gt 0 ]]; do @@ -117,15 +118,18 @@ if [ -z "${LIST}${PROFILE}${OPTLIST}" ]; then fi if [ -n "$LIST" ]; then + # shellcheck disable=SC2046 find $(find "${PROFILES_TOPDIR}" -maxdepth 1 -mindepth 1 -type d -exec echo {}/repos/ \;) -type f -name "*.repo" | sed -n -e 's/\.repo$//;s/^.*\///p' exit fi if [ -n "$OPTLIST" ]; then + # shellcheck disable=SC2046 find $(find "${PROFILES_TOPDIR}" -maxdepth 1 -mindepth 1 -type d -exec echo {}/optrepos/ \;) -type f -name "*.repo" | sed -n -e 's/\.repo$//;s/^.*\///p' exit fi +# shellcheck disable=SC2046 # Find the repo file for given profile. We assume that repo files have unique names across all supported systems PFILE=$(find $(find "${PROFILES_TOPDIR}" -maxdepth 1 -mindepth 1 -type d -exec echo {}/repos/ \;) -type f -name "${PROFILE}.repo") if ! [ -f "$PFILE" ]; then @@ -138,15 +142,15 @@ fi debug "Profile file: $PFILE" # OS-specific profile directories should have names like: "rhel", "centos-stream", "fedora", etc. -OS_ID="$(basename $(dirname $(dirname "$PFILE")))" -PROFILES_DIR="${PROFILES_DIR:-$(rpm --eval %_datarootdir)/mini-tps/profiles/${OS_ID}/repos/}" -OPTREPOS_DIR="${OPTREPOS_DIR:-$(rpm --eval %_datarootdir)/mini-tps/profiles/${OS_ID}/optrepos/}" -PREPARE_SYSTEM_SCRIPT="${PREPARE_SYSTEM_SCRIPT:-$(rpm --eval %_libexecdir)/mini-tps/${OS_ID}/prepare-system}" +OS_ID="$(basename "$(dirname "$(dirname "${PFILE}")")")" +: "${PROFILES_DIR:=$(rpm --eval %_datarootdir)/mini-tps/profiles/${OS_ID}/repos/}" +: "${OPTREPOS_DIR:=$(rpm --eval %_datarootdir)/mini-tps/profiles/${OS_ID}/optrepos/}" if [ "$(id -u)" != "0" ]; then - echo "Run '$PROG' with root privileges." + echo "Run $PROG with root privileges." exit 1 fi -debug "Running prepare script: $PREPARE_SYSTEM_SCRIPT" +debug "Running prepare script: ${PREPARE_SYSTEM_SCRIPT:=$(rpm --eval %_libexecdir)/mini-tps/${OS_ID}/prepare-system}" +# shellcheck disable=SC1090 source "$PREPARE_SYSTEM_SCRIPT" diff --git a/mtps-run-mtests b/mtps-run-mtests index 67e8996..6d2d1b3 100755 --- a/mtps-run-mtests +++ b/mtps-run-mtests @@ -108,7 +108,7 @@ fi START_DATE="$(date '+%x')" START_TIME="$(date '+%T')" if [ -n "$SELINUX" ]; then - if ! [ "$SELINUX" -eq "0" -o "$SELINUX" -eq "1" ]; then + if ! [[ "$SELINUX" -eq 0 || "$SELINUX" -eq 1 ]]; then echo "Use: $PROG -h for help." exit fi @@ -161,7 +161,7 @@ for profile in $profiles; do " NSVC: $nsvc" \ " PROFILE: $profile" \ " SELINUX: $(getenforce || echo "unknown")" - logfname="${LOGS_DIR%%/}/$TESTRUN_ID-profile-$TEST-$nsvc-$profile.log" + logfname="${LOGS_DIR%%/}/${TESTRUN_ID}-profile-${TEST}-${nsvc}-${profile}.log" mtps-module-test --test="$TEST" --nsvc="$nsvc" --profile="$profile" $DEBUG 2>&1 | tee "$logfname" test_status="${PIPESTATUS[0]}" if [ "$test_status" -ne "0" ]; then diff --git a/mtps-run-tests b/mtps-run-tests index 8016a58..08a2ad3 100755 --- a/mtps-run-tests +++ b/mtps-run-tests @@ -14,7 +14,7 @@ # Copyright: Red Hat Inc. 2018, 2022, 2023 # Author: Andrei Stepanov -PROG="${PROG:-${0##*/}}" +: "${PROG:=${0##*/}}" # Source `mtps-setup' from $PATH if command -v "mtps-setup" >/dev/null; then source "mtps-setup"; fi @@ -54,7 +54,6 @@ box_out() { echo -e "| ${b//?/ } |\n-${b//?/-}-" } -# http://wiki.bash-hackers.org/howto/getopts_tutorial opt_str="$@" opt=$(getopt -n "$0" --options "hvct:r:s:l:x:f" --longoptions "help,verbose,skiplangpack,scriptletcheck,rpmverify,critical,test:,repo:,selinux:" -- "$@") eval set -- "$opt" @@ -108,23 +107,21 @@ done # Entry -DEBUG="${DEBUG:-}" -TEST="${TEST:-}" -REPONAME="${REPONAME:-}" -SELINUX="${SELINUX:-}" -CRITICAL="${CRITICAL:-}" -SKIPLANGPACK="${SKIPLANGPACK:-}" -CHECK_SCRIPTLETS="${CHECK_SCRIPTLETS:-}" -RPM_VERIFY="${RPM_VERIFY:-}" -# Put logs by default at CDIR/mtps-logs -LOGS_DIR="${LOGS_DIR:-mtps-logs}" +: "${DEBUG:=}" +: "${TEST:=}" +: "${REPONAME:=}" +: "${SELINUX:=}" +: "${CRITICAL:=}" +: "${SKIPLANGPACK:=}" +: "${CHECK_SCRIPTLETS:=}" +: "${RPM_VERIFY:=}" debug "TEST: $TEST" debug "REPONAME: $REPONAME" debug "SELINUX: $SELINUX" # Test correct invocation -if [ -z "$TEST" ] || [ -z "$REPONAME" ]; then +if [[ -z "$TEST" || -z "$REPONAME" ]]; then echo "Use: $PROG -h for help." exit fi @@ -132,7 +129,7 @@ fi START_DATE="$(date '+%x')" START_TIME="$(date '+%T')" if [ -n "$SELINUX" ]; then - if ! [ "$SELINUX" -eq "0" -o "$SELINUX" -eq "1" ]; then + if ! [[ "$SELINUX" -eq 0 || "$SELINUX" -eq 1 ]]; then echo "Use: $PROG -h for help." exit fi @@ -166,12 +163,13 @@ for i in $nevras_in_repo; do done box_out "# $(echo $TEST | tr '[:lower:]' '[:upper:]') TEST" "" "Packages:" "" "${pkgs_list[@]}" -mkdir -p "$LOGS_DIR" +# Put logs by default at CDIR/mtps-logs +mkdir -p "${LOGS_DIR:=mtps-logs}" TESTRUN_ID="$(date +%H%M%S)" if [ -z "${nevras_in_repo// /}" ]; then - logfname="${LOGS_DIR%%/}/FAIL-$TESTRUN_ID-$TEST.log" + logfname="${LOGS_DIR%%/}/FAIL-${TESTRUN_ID}-${TEST}.log" echo "Test '$TEST' failed due no packages for testing in repo '$REPONAME:'." | tee -a "$logfname" - echo "Output for: ${YUMDNFCMD} repo-pkgs "$REPONAME" list --showduplicates" | tee -a "$logfname" + echo "Output for: ${YUMDNFCMD} repo-pkgs $REPONAME list --showduplicates" | tee -a "$logfname" "$YUMDNFCMD" repo-pkgs "$REPONAME" list --showduplicates 2>&1 | tee -a "$logfname" exit 1 fi @@ -196,7 +194,7 @@ for nevra in $nevras_in_repo; do " NEVRA: $nevra" \ " SELINUX: $(getenforce || echo "unknown")" \ " ${YUMDNFCMD} HISTORY: $START" - logfname="${LOGS_DIR%%/}/$TESTRUN_ID-$TEST-$nevra.log" + logfname="${LOGS_DIR%%/}/${TESTRUN_ID}-${TEST}-${nevra}.log" mtps-pkg-test --test="$TEST" ${CHECK_SCRIPTLETS:+--scriptletcheck} ${RPM_VERIFY:+--rpmverify} --nevra="$nevra" 2>&1 | tee "$logfname" test_status="${PIPESTATUS[0]}" #box_out \ diff --git a/mtps-setup b/mtps-setup index cf4f9cb..a9749df 100755 --- a/mtps-setup +++ b/mtps-setup @@ -59,7 +59,7 @@ if [ -z "$YUMDNFCMD" ]; then fi debug() { - if [ -n "$DEBUG" ]; then + if [ -n "${DEBUG:-}" ]; then echo "$*" >&2 fi } diff --git a/mtps-tag b/mtps-tag index 9aba5dd..7e9f72a 100755 --- a/mtps-tag +++ b/mtps-tag @@ -185,7 +185,7 @@ fi debug "Tag: $TAG_NAME" -if [ -n "$GET_NVRS" -o -n "$GET_TASKS" ]; then +if [[ -n "$GET_NVRS" || -n "$GET_TASKS" ]]; then query_listTagged="$(mk_query_listTagged "$TAG_NAME")" answer_listTagged="$(send_query "$query_listTagged")" if [ -n "$GET_NVRS" ]; then diff --git a/mtps-xunit b/mtps-xunit index ecc6245..d1894fc 100755 --- a/mtps-xunit +++ b/mtps-xunit @@ -83,7 +83,7 @@ END_COMMENT PROG="${PROG:-${0##*/}}" debug() { - if [ -n "$DEBUG" ]; then + if [ -n "${DEBUG:-}" ]; then echo "$*" >&2 fi } @@ -247,7 +247,7 @@ if [ -n "$TS_TESTS" ]; then xmlstarlet ed -L -s "/testsuites/testsuite[@name='$TS_NAME']" -t attr -n "tests" -v "$TS_TESTS" "$XFILE" fi -if [ -n "$TS_PROP_NAME" -a -n "$TS_PROP_VALUE" ]; then +if [[ -n "$TS_PROP_NAME" && -n "$TS_PROP_VALUE" ]]; then # If no any /testsuites/testsuite/properties create it xmlstarlet ed -L -s "/testsuites/testsuite[@name='$TS_NAME'][not(properties)]" -t elem -n "properties" "$XFILE" # Remove property with requested name @@ -270,7 +270,7 @@ if [ -n "$TC_NAME" ]; then xmlstarlet ed -L -d "/testsuites/testsuite[@name='$TS_NAME']/testcase[@name='$TC_NAME']/@time" "$XFILE" xmlstarlet ed -L -s "/testsuites/testsuite[@name='$TS_NAME']/testcase[@name='$TC_NAME']" -t attr -n "time" -v "$TC_TIME" "$XFILE" fi - if [ -n "$TC_PROP_NAME" -a "$TC_PROP_VALUE" ]; then + if [[ -n "$TC_PROP_NAME" && "$TC_PROP_VALUE" ]]; then # If no any /testsuites/testsuite/properties create it xmlstarlet ed -L -s "/testsuites/testsuite[@name='$TS_NAME']/testcase[@name='$TC_NAME'][not(properties)]" -t elem -n "properties" "$XFILE" # Remove property with requested name @@ -286,7 +286,7 @@ if [ -n "$TC_NAME" ]; then xmlstarlet ed -L -s "/testsuites/testsuite[@name='$TS_NAME']/testcase[@name='$TC_NAME']/parameters" -t elem -n "parameter" "$XFILE" xmlstarlet ed -L -s "/testsuites/testsuite[@name='$TS_NAME']/testcase[@name='$TC_NAME']/parameters/parameter[not(@value)]" -t attr -n "value" -v "$TC_PARAM_VALUE" "$XFILE" fi - if [ -n "$TC_LOG_NAME" -a "$TC_LOG_HREF" ]; then + if [[ -n "$TC_LOG_NAME" && "$TC_LOG_HREF" ]]; then # If no any /testsuites/testsuite/properties create it xmlstarlet ed -L -s "/testsuites/testsuite[@name='$TS_NAME']/testcase[@name='$TC_NAME'][not(logs)]" -t elem -n "logs" "$XFILE" # Remove property with requested name diff --git a/profiles/rhel/prepare-system b/profiles/rhel/prepare-system index e248934..f12742a 100644 --- a/profiles/rhel/prepare-system +++ b/profiles/rhel/prepare-system @@ -1,8 +1,8 @@ -INT_CERTS="${INT_CERTS:-http://download.eng.bos.redhat.com/brewroot/vol/rhel-7/packages/redhat-internal-cert-install/0.1/9.el7.csb/noarch/redhat-internal-cert-install-0.1-9.el7.csb.noarch.rpm}" +#!/usr/bin/bash -efu if ! rpm -q redhat-internal-cert-install >/dev/null 2>&1; then - echo "Deploy internal certs." - yum install -y "$INT_CERTS" + echo "Deploying internal certs" + yum install -y "${INT_CERTS:-https://hdn.corp.redhat.com/rhel8-csb/RPMS/noarch/redhat-internal-cert-install-0.1-31.el7.noarch.rpm}" fi echo "Setting up RHEL internal YUM repos for selected profile" @@ -52,7 +52,7 @@ if [ -n "$ENABLE_BUILD_ROOT" ]; then fi # repoquery util acts not on live system, but rather on set of enabled repos. mini-tps hold personal list of protected packages, such as openssh-server -yum config-manager --set-enabled astepano-mini-tps || : +# yum config-manager --set-enabled astepano-mini-tps || : echo "Installing required packages for testing" yum install -y createrepo_c diff --git a/ver_cmp.sh b/ver_cmp.sh index 96377b3..6801f59 100755 --- a/ver_cmp.sh +++ b/ver_cmp.sh @@ -9,7 +9,7 @@ DEBUG="${DEBUG:-}" # aa < 10 debug() { - if [ -n "$DEBUG" ]; then + if [ -n "${DEBUG:-}" ]; then echo "$*" >&2 fi } From dd0f77b3ca51bb7d3cfa8533ad2b71a22faaa4c2 Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Fri, 1 Dec 2023 11:07:58 +0100 Subject: [PATCH 8/9] Implement the '3. If /usr/bin/yum is present then use yum' --- mtps-setup | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/mtps-setup b/mtps-setup index a9749df..d93619b 100755 --- a/mtps-setup +++ b/mtps-setup @@ -39,16 +39,18 @@ YUMDNFCMD="${MINITPSYUMDNFCMD:-}" PROTECTEDCFG="/etc/dnf/protected.d/mini-tps-old-dnf.conf" if [ -z "$YUMDNFCMD" ]; then - if [ -L "/usr/bin/yum" ]; then + if [ -f "/usr/bin/yum" ]; then YUMDNFCMD="yum" - YUMLINK="$(readlink "/usr/bin/yum")" - if [[ "$YUMLINK" == *dnf5* && -x "/usr/bin/dnf-3" ]]; then - YUMDNFCMD="/usr/bin/dnf-3" - if [ "$EUID" -eq 0 ]; then - if ! rpm -q python3-dnf >/dev/null; then - dnf install -y python3-dnf - if [ ! -e "$PROTECTEDCFG" ]; then - echo "python3-dnf" >> "$PROTECTEDCFG" + if [ -L "/usr/bin/yum" ]; then + YUMLINK="$(readlink "/usr/bin/yum")" + if [[ "$YUMLINK" == *dnf5* && -x "/usr/bin/dnf-3" ]]; then + YUMDNFCMD="/usr/bin/dnf-3" + if [ "$EUID" -eq 0 ]; then + if ! rpm -q python3-dnf >/dev/null; then + dnf install -y python3-dnf + if [ ! -e "$PROTECTEDCFG" ]; then + echo "python3-dnf" >> "$PROTECTEDCFG" + fi fi fi fi From ca787bbdfe70e1af28ed9ad114d621449d35a7cb Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Fri, 1 Dec 2023 11:34:15 +0100 Subject: [PATCH 9/9] mtps-mutils Requires: python-gobject-base & libmodulemd --- mini-tps.spec | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mini-tps.spec b/mini-tps.spec index ca3f55c..8899caf 100644 --- a/mini-tps.spec +++ b/mini-tps.spec @@ -9,6 +9,8 @@ Source0: %{name}.tar.gz Requires: yum-utils # List of packages for wich do not run 'remove' test. Requires: openssh-server yum +# mtps-mutils +Requires: libmodulemd BuildArch: noarch %if 0%{?rhel} > 7 @@ -18,6 +20,13 @@ Requires: dnf-plugins-core Requires: libselinux-utils %endif +# mtps-mutils +%if 0%{?rhel} == 7 +Requires: python2-gobject-base +%else +Requires: python3-gobject-base +%endif + %description Light version of TPS @@ -57,6 +66,7 @@ install -pD -m 0755 profiles/fedora/prepare-system %{buildroot}%{_libexecdir}/mi - URL update - move mtps-* executables from /usr/local/bin/ to /usr/sbin/ - use install instead of mkdir & cp +- mtps-mutils Requires: python-gobject-base * Mon Jul 31 2023 Andrei Stepanov - 0.1-161 - new build