Skip to content

Commit

Permalink
Fix #385: Support for perl rpm rollbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
schellj committed Sep 15, 2023
1 parent a426f98 commit 18e1ffa
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions rsconf/package_data/rsconf/rsconf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,16 @@ rsconf_install_perl_rpm() {
# both fresh install and update, which install does, but
# it doesn't return an error if the update isn't done.
# You just have to check so this way is more robust
declare reinstall=
declare install_cmd=
if [[ $rpm_version == $prev_version ]]; then
if rpm --verify "$rpm_base"; then
return
fi
install_info "$rpm_version: rpm is modified, reinstalling"
reinstall=1
install_cmd=reinstall
elif rsconf_is_perl_rpm_rollback "$rpm_base" "$prev_version" "$rpm_version"; then
install_info "$rpm_version older than $prev_version, downgrading"
install_cmd=downgrade
fi
declare tmp=$rpm_file
install_download "$rpm_file" > "$tmp"
Expand All @@ -279,7 +282,7 @@ rsconf_install_perl_rpm() {
# "error: open of <html> failed: No such file or directory"
install_err "$rpm_file: not found or not a valid RPM"
fi
rsconf_yum_reinstall=$reinstall rsconf_yum_install "$tmp"
rsconf_yum_install_cmd=$install_cmd rsconf_yum_install "$tmp"
rm -f "$tmp"
declare curr_rpm=$(rpm -q "$rpm_base")
if [[ $curr_rpm != $rpm_version ]]; then
Expand Down Expand Up @@ -309,6 +312,24 @@ rsconf_install_symlink() {
rsconf_service_file_changed "$new"
}

rsconf_is_perl_rpm_rollback() {
declare base_rpm=$1
declare previous_rpm=$2
declare this_rpm=$3
declare versions=()
for v in $previous_rpm $this_rpm; do
if [[ $v =~ "$base_rpm"\-([[:digit:]]{8}\.[[:digit:]]{6}-[[:digit:]])\. ]]; then
versions+=( ${BASH_REMATCH[1]} )
else
return 1
fi
done
if [[ ${versions[0]} > ${versions[1]} ]]; then
return 0
fi
return 1
}

rsconf_main() {
# POSIT: radiasoft/download/bin/install.sh: skip repo arg
if [[ ${1+$1} == rsconf.sh ]]; then
Expand Down Expand Up @@ -587,9 +608,9 @@ rsconf_yum_install() {
todo+=( "$x" )
fi
done
declare cmd=install
if [[ ${rsconf_yum_reinstall:-} ]]; then
cmd=reinstall
declare cmd="${rsconf_yum_install_cmd:-install}"
if [[ ! $cmd =~ ^((re)?install|downgrade)$ ]]; then
install_err "$cmd: unexpected yum command"
fi
if (( ${#todo[@]} > 0 )); then
yum "$cmd" --color=never -y -q "${todo[@]}"
Expand Down

0 comments on commit 18e1ffa

Please sign in to comment.