From d7857bc19ce652e6062c42fc4447a55409c1bbe4 Mon Sep 17 00:00:00 2001 From: Maciej Kisielewski Date: Wed, 16 Oct 2024 15:28:30 +0200 Subject: [PATCH] fix and simplify install-rpms The install-rpms accepted two non-optional "options" that ended up being used the same way. There was some logic in that bash script that checked and processed those options, and as it's typical of bash code, it had a bug, where if the script was supplied with only one of the two "options", the value of non-existent $extra_rpms_file, because it was enclosed in double quotes, would be treated as an actual object (an empty string), thus making the following code: ``` for file in "$common_rpms_file" "$extra_rpms_file"; do (...) mapfile -t tmp_array < <(awk '!/^#/' "$file") ``` iterate over an empty "$file" blocking awk. Because the only thing that this script did was to install RPMs specified by text files, this patch changes it to do exactly that without any error-prone bash logic. --- barney.yaml | 12 ++--- bootstrap/README.md | 3 +- bootstrap/install-rpms/install-rpms.bash | 67 +++--------------------- 3 files changed, 15 insertions(+), 67 deletions(-) diff --git a/barney.yaml b/barney.yaml index 33673e5..d3ccb69 100644 --- a/barney.yaml +++ b/barney.yaml @@ -177,8 +177,8 @@ images: build: | echo "install rpms" bash /bootstrap/install-rpms/install-rpms.bash \ - --common-rpms-file /bootstrap/install-rpms/rpms-common \ - --extra-rpms-file /bootstrap/install-rpms/rpms-build + /bootstrap/install-rpms/rpms-common \ + /bootstrap/install-rpms/rpms-build base-image-devel: units: @@ -186,8 +186,8 @@ images: sources: [] build: | bash /bootstrap/install-rpms/install-rpms.bash \ - --common-rpms-file /bootstrap/install-rpms/rpms-common \ - --extra-rpms-file /bootstrap/install-rpms/rpms-devel + /bootstrap/install-rpms/rpms-common \ + /bootstrap/install-rpms/rpms-devel go-buildfloor: description: | @@ -309,8 +309,8 @@ images: sources: [] build: | bash /bootstrap/install-rpms/install-rpms.bash \ - --common-rpms-file /bootstrap/install-rpms/rpms-common \ - --extra-rpms-file /bootstrap/install-rpms/rpms-devel + /bootstrap/install-rpms/rpms-common \ + /bootstrap/install-rpms/rpms-devel touch $DESTDIR/etc/resolv.conf entry: diff --git a/bootstrap/README.md b/bootstrap/README.md index 01a83c1..ee2e469 100644 --- a/bootstrap/README.md +++ b/bootstrap/README.md @@ -56,5 +56,4 @@ The developer just uses these repos to further install further packages in his b ### Base Image Contents Once the bootstrap image and repo configuration is ready, we run the `install-rpms/install-rpms.bash` script to build the base image. The set of rpms to be installed is specified in the text files: `install-rpms/rpms-common`, `install-rpms/rpms-build` and `install-rpms/rpms-devel`. -The `install-rpms` script takes two arguments, `--common-rpms-file rpms-common` and `--extra-rpms-file (rpms-build | rpms-devel)`. - +The `install-rpms` script accepts one or more paths as its positional arguments, the files supplied this way should provide a list of packages to be installed. diff --git a/bootstrap/install-rpms/install-rpms.bash b/bootstrap/install-rpms/install-rpms.bash index 20af5e1..0d5f314 100755 --- a/bootstrap/install-rpms/install-rpms.bash +++ b/bootstrap/install-rpms/install-rpms.bash @@ -1,59 +1,8 @@ -#!/bin/bash - -set -e -set -x - -dnf_install() { - dnf --assumeyes --installroot=/dest --noplugins \ - --config=/etc/dnf/dnf.conf \ - --setopt=cachedir=/var/cache/dnf \ - --setopt=reposdir=/etc/yum.repos.d \ - --setopt=varsdir=/etc/dnf \ - install "$@" -} - -usage() { - echo "Usage: $0 --common-rpms-file FILE --extra-rpms-file FILE" - exit 1 -} - -# Parse command-line options -while [[ "$#" -gt 0 ]]; do - case $1 in - --common-rpms-file) - common_rpms_file="$2" - shift 2 - ;; - --extra-rpms-file) - extra_rpms_file="$2" - shift 2 - ;; - *) - usage - ;; - esac -done - -if [[ -z "$common_rpms_file" && -z "$extra_rpms_file" ]]; then - echo "Error: At least one of the options must be specified." - usage -fi - -rpms=() -for file in "$common_rpms_file" "$extra_rpms_file"; do - if [[ -n "$file" && ! -f "$file" ]]; then - echo "Error: File '$file' does not exist." - exit 1 - fi - - mapfile -t tmp_array < <(awk '!/^#/' "$file") - rpms+=("${tmp_array[@]}") -done - -if [[ ${#rpms[@]} -eq 0 ]]; then - echo "Error: No RPMs specified" - exit 1 -fi - -dnf_install "${rpms[@]}" - +#!/usr/bin/env bash + +cat "$@" | xargs dnf --assumeyes --installroot=/dest --noplugins \ +--config=/etc/dnf/dnf.conf \ +--setopt=cachedir=/var/cache/dnf \ +--setopt=reposdir=/etc/yum.repos.d \ +--setopt=varsdir=/etc/dnf \ +install