Cleanup yum downloading

Using "yum --downloadonly" breaks the abstraction of
"install-packages" because it downloads to the yum cache.  It also
acts funny if the package is already there.

Add an argument to "-d" which is the directory to download to.  dnf
has "download" built in, and for the old case use yumdownloader which
acts about the same.  Ensure it is installed, since it comes in
yum-utils.

Also a slight cleanup of the getopt parsing so it's easier to have the
required argument for -d

Thus we can remove most of the stuff in 15-remove-grub.  The check for
centos6 and it's lack of grub2 is clarified.  All the stuff about
having to remove the package, purging the cache etc so yum gets the
right thing is no longer relevant.  The long section of commented out
code at the end is also removed for clarity.

I tested this with an F21, F22 & centos (6) build

Change-Id: Id1e430e7d050a0b99ac449e2ea435e06cda1c4e6
This commit is contained in:
Ian Wienand 2015-05-29 10:24:15 +10:00
parent d748aa17d2
commit e42066d685
2 changed files with 67 additions and 51 deletions

View File

@ -5,35 +5,17 @@ fi
set -eu set -eu
set -o pipefail set -o pipefail
GRUBNAME=$(which grub-install) || echo "trying grub2-install" # grub2 isn't available on rhel6/centos6; they are setup to use
if [ -z "$GRUBNAME" ]; then # extlinux. skip this
GRUBNAME=$(which grub2-install) # you would think we could match on $DISTRO or something else; but
fi # we can't because the rhel/centos elements are a bit mixed up;
if [ -z "$GRUBNAME" ] || [ $($GRUBNAME --version | grep -c "0.97") -ne 0 ]; then # centos-minimal for example sets distro to "centos". so the best
echo "No GRUB2 found. No need to remove" # check is just for the original "grub-install" script
if [ -f /sbin/grub-install ]; then
exit 0 exit 0
else
# Must manually remove grub2 here, otherwise the download below does not work.
yum remove -y grub2
fi fi
# Remove all old versions of grub2 from the yum cache and then ensure the # download the latest grub2 package and setup the install script which
# latest version is in the cache. # will be called later by vm/finalise.d/51-bootloader
basearch=$(cat /etc/yum/vars/basearch) install-packages -d /tmp/grub grub2
find /tmp/yum/$basearch -regex ".*/grub2-[0-9].*\.rpm" -exec rm -f {} +
install-packages -d grub2
# Copy grub2 rpm out of mounted yum cache for install during finalise
mkdir -p /tmp/grub
cp $(find /tmp/yum/$basearch -regex ".*/grub2-[0-9].*\.rpm") /tmp/grub
echo "rpm -i /tmp/grub/*.rpm" > /tmp/grub/install echo "rpm -i /tmp/grub/*.rpm" > /tmp/grub/install
#GRUB_CFG=/boot/grub2/grub.cfg
#[ -f "$GRUB_CFG" ]
# Update the config to have the search UUID of the image being built.
# When partition staging is moved to a separate stage, this will need to happen
# there. This generates a non-UUID config, which is irrelevant for booting with
# hypervisor kernel + ramdisk, and fixed up by 51-grub for vm images.
#GRUB_DISABLE_LINUX_UUID=true grub2-mkconfig -o $GRUB_CFG

View File

@ -33,27 +33,37 @@ function show_options () {
echo echo
echo "Options:" echo "Options:"
echo " -u -- update all packages" echo " -u -- update all packages"
echo " -d -- download the packages only" echo " -d dir -- download the packages to directory"
echo " -e -- erase/remove packages" echo " -e -- erase/remove packages"
echo " -m -- use custom element package map (Example: -m nova)" echo " -m map -- use custom element package map (Example: -m nova)"
exit 0 exit 0
} }
TEMP=$(getopt -o hudem: -n $SCRIPTNAME -- "$@") while getopts "hud:em:" opt; do
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi case "$opt" in
eval set -- "$TEMP" u)
${YUM} -y update;
while true ; do exit 0
case "$1" in ;;
-u) ${YUM} -y update; exit 0;; d)
-d) EXTRA_ARGS="--downloadonly"; shift;; ACTION="download"
-e) ACTION="erase"; shift;; DOWNLOAD_PATH=$OPTARG
-m) MAP_ELEMENT=$2; shift 2;; ;;
-h) show_options;; e)
--) shift; break ;; ACTION="erase"
*) echo "Error: unsupported option $1."; exit 1;; ;;
m)
MAP_ELEMENT=$OPTARG
;;
h)
show_options
;;
*)
exit 1
;;
esac esac
done done
shift $((OPTIND-1))
# Packages that aren't available in the distro but requested for installation # Packages that aren't available in the distro but requested for installation
@ -87,15 +97,39 @@ if [ -n "$WHITELIST" ]; then
else else
PKGS=$(map-packages $WHITELIST) PKGS=$(map-packages $WHITELIST)
fi fi
if [ -z "${PKGS}" ]; then if [ -z "${PKGS}" ]; then
echo "Not running install-packages $ACTION with empty packages list" echo "Not running install-packages $ACTION with empty packages list"
else exit 0
echo "Running install-packages ${ACTION}. Package list: $PKGS"
${YUM} -v -y $ACTION $EXTRA_ARGS $PKGS
for pkg in "$@"; do
if [ "$pkg" = "python-pip" ] ; then
alternatives --install /usr/bin/pip pip /usr/bin/pip-python 10
fi
done
fi fi
echo "Running install-packages ${ACTION}. Package list: $PKGS"
if [ "$ACTION" == "download" ]; then
mkdir -p $DOWNLOAD_PATH
if [ ${YUM} == "dnf" ]; then
dnf download --destdir=$DOWNLOAD_PATH $PKGS
else
# note; you don't want to use yum --download only here.
# Firstly that only puts things in the yum cache
# directory, and secondly it acts funny if old versions
# are already in the cache.
if [ ! -f /usr/bin/yumdownloader ]; then
yum install -y yum-utils
fi
yumdownloader --destdir=$DOWNLOAD_PATH $PKGS
fi
exit 0
fi
${YUM} -v -y $ACTION $EXTRA_ARGS $PKGS
# probably not the right place for this; but python-pip package on
# fedora/rh calls pip "pip-python" while the rest of the work
# expects it to be just called "pip"
for pkg in "$@"; do
if [ "$pkg" = "python-pip" ] ; then
alternatives --install /usr/bin/pip pip /usr/bin/pip-python 10
fi
done
fi fi