Files
ansible-role-tripleo-modify…/templates/yum_update.sh.j2
David Hill 22374eb422 Add the possibility to update packages from local rpms using yum.
This is needed if we want to only update installed packages and not
hit depenency issues encountered when updating packages with rpm_install.sh

Change-Id: I5095d7b04cb10fde1bd82afd1bc406445b7595fd
Closes-bug: #1858837
2020-01-13 20:38:19 -05:00

62 lines
1.8 KiB
Django/Jinja
Executable File

#!/bin/bash
set -eou pipefail
PKG={{ pkg_mgr }}
PKG_MGR="$(echo ${PKG:(-3)})"
{% if rpms_path is defined %}
$PKG -y localupdate /tmp/*.rpm
rm -f /tmp/*.rpm
{% else %}
if [ $PKG_MGR == "dnf" ]; then
REPOQUERY_CMD="$PKG repoquery"
else
REPOQUERY_CMD="$(command -v repoquery)"
fi
packages_for_update=
if [ -n "$1" ] && [[ -n $REPOQUERY_CMD ]]; then
installed_versions=$(rpm -qa --qf "%{NAME} = %{VERSION}-%{RELEASE}\n" | sort)
# dnf repoquery return 1 when repo does not exists, but standalone does not
available_versions=$($REPOQUERY_CMD --quiet --provides --disablerepo='*' --enablerepo=$1 -a | sort || true)
uptodate_versions=$(comm -12 <(printf "%s\n" "$installed_versions") <(printf "%s\n" "$available_versions"))
installed=$(printf "%s\n" "$installed_versions" | cut -d= -f1 | sort)
available=$(printf "%s\n" "$available_versions" | cut -d= -f1 | sort)
uptodate=$(printf "%s\n" "$uptodate_versions" | cut -d= -f1 | sort)
installed_for_update=$(comm -23 <(printf "%s\n" $installed) <(printf "%s\n" $uptodate))
packages_for_update=$(comm -12 <(printf "%s\n" $installed_for_update) <(printf "%s\n" $available))
fi
if [ -z "$packages_for_update" ]; then
echo "No packages were found for update..."
exit
fi
if [ $PKG_MGR == "dnf" ]; then
plugin=dnf-plugins-core
else
plugin=yum-plugin-priorities
fi
if $(! echo $installed | grep -qw $plugin) && $($PKG list available $plugin >/dev/null 2>&1); then
$PKG install -y $plugin
fi
YUM_OPTS="{% if yum_cache is defined and yum_cache %}--setopt=keepcache=1{% endif %}"
$PKG -y update $YUM_OPTS $packages_for_update
{% endif %}
{% if yum_cache is defined and yum_cache %}
sync
{% else %}
rm -rf /var/cache/$PKG_MGR
{% endif %}
{% if container_build_tool is defined and container_build_tool == 'docker' %}
rm -f /tmp/yum_install.sh
{% endif %}