Skip to content

Commit

Permalink
rpm install/upgrade - remove xargs
Browse files Browse the repository at this point in the history
echo $v | sudo xargs ..
is a antipattern, just use bash arrays.

Replace if test condition; then fail
with just; test condition, and let +e handle it.

Rather than set -u /+u give ID_LIKE
a default value so it won't error
or match suse when its blank.
  • Loading branch information
grooverdan committed Nov 27, 2024
1 parent 511c543 commit d3d4318
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
15 changes: 8 additions & 7 deletions scripts/rpm-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ rpm_setup_bb_artifacts_mirror
rpm_pkg_makecache

# install all packages
pkg_list=$(rpm_repoquery) ||
read -ra package_array = <<< "$(rpm_repoquery)"

if [ ${#package_array[@]} -eq 0 ]; then
bb_log_err "Unable to retrieve package list from repository"
fi

# ID_LIKE may not exist
set +u
if [[ $ID_LIKE =~ ^suse* ]]; then
echo "$pkg_list" | xargs sudo "$pkg_cmd" -n install
if [[ "${ID_LIKE:-empty}" =~ ^suse* ]]; then
sudo "$pkg_cmd" -n install "${package_array[@]}"
else
echo "$pkg_list" | xargs sudo "$pkg_cmd" -y install
sudo "$pkg_cmd" -y install "${package_array[@]}"
fi
set -u


sh -c 'g=/usr/lib*/galera*/libgalera_smm.so; echo -e "[galera]\nwsrep_provider=$g"' |
sudo tee /etc/my.cnf.d/galera.cnf
Expand Down
19 changes: 9 additions & 10 deletions scripts/rpm-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ bb_log_info "Package_list: $package_list"
# /etc/zypp/repos.d/SUSE_Linux_Enterprise_Server_12_SP3_x86_64:SLES12-SP3-Updates.repo
# /etc/zypp/repos.d/SUSE_Linux_Enterprise_Server_12_SP3_x86_64:SLES12-SP3-Pool.repo

# ID_LIKE may not exist
set +u
if [[ $ID_LIKE =~ ^suse* ]]; then
if [[ "${ID_LIKE:-empty}" =~ ^suse* ]]; then
sudo "$pkg_cmd" clean --all
pkg_cmd_options="-n"
pkg_cmd_upgrade="update"
Expand All @@ -132,10 +130,11 @@ else
fi
set -u

read -ra package_array <<< "$package_list"

# Install previous release
echo "$package_list" | xargs sudo "$pkg_cmd" "$pkg_cmd_options" install ||
bb_log_err "installation of a previous release failed, see the output above"
#fi
bb_log_info "Install previous release"
sudo "$pkg_cmd" "$pkg_cmd_options" install "${package_array[@]}"

# Start the server, check that it is working and create some structures
#
Expand Down Expand Up @@ -167,8 +166,8 @@ fi
# //TEMP upgrade does not work without this but why? Can't we fix it?
if [[ $test_type == "major" ]]; then
bb_log_info "remove old packages for major upgrade"
packages_to_remove=$(rpm -qa | grep 'MariaDB-' | awk -F'-' '{print $1"-"$2}')
echo "$packages_to_remove" | xargs sudo "$pkg_cmd" "$pkg_cmd_options" remove
readarray -t package_array <<< "$(rpm -qa | grep 'MariaDB-' | awk -F'-' '{print $1"-"$2}')"
sudo "$pkg_cmd" "$pkg_cmd_options" remove "${package_array[@]}"
rpm -qa | grep -iE 'maria|mysql' || true
fi

Expand All @@ -182,10 +181,10 @@ set -e

if [[ $test_type == "major" ]]; then
# major upgrade (remove then install)
echo "$package_list" | xargs sudo "$pkg_cmd" "$pkg_cmd_options" install
sudo "$pkg_cmd" "$pkg_cmd_options" install "${package_array[@]}"
else
# minor upgrade (upgrade works)
echo "$package_list" | xargs sudo "$pkg_cmd" "$pkg_cmd_options" "$pkg_cmd_upgrade"
sudo "$pkg_cmd" "$pkg_cmd_options" "$pkg_cmd_upgrade" "${package_array[@]}"
fi
# set +e

Expand Down

0 comments on commit d3d4318

Please sign in to comment.