From e42066d68512fb4c74c54b34699aa6cd2a6fb5eb Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 29 May 2015 10:24:15 +1000 Subject: [PATCH] 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 --- .../pre-install.d/15-remove-grub | 38 +++------ elements/yum/bin/install-packages | 80 +++++++++++++------ 2 files changed, 67 insertions(+), 51 deletions(-) diff --git a/elements/redhat-common/pre-install.d/15-remove-grub b/elements/redhat-common/pre-install.d/15-remove-grub index 81c58912..21ab6815 100755 --- a/elements/redhat-common/pre-install.d/15-remove-grub +++ b/elements/redhat-common/pre-install.d/15-remove-grub @@ -5,35 +5,17 @@ fi set -eu set -o pipefail -GRUBNAME=$(which grub-install) || echo "trying grub2-install" -if [ -z "$GRUBNAME" ]; then - GRUBNAME=$(which grub2-install) -fi -if [ -z "$GRUBNAME" ] || [ $($GRUBNAME --version | grep -c "0.97") -ne 0 ]; then - echo "No GRUB2 found. No need to remove" +# grub2 isn't available on rhel6/centos6; they are setup to use +# extlinux. skip this +# you would think we could match on $DISTRO or something else; but +# we can't because the rhel/centos elements are a bit mixed up; +# centos-minimal for example sets distro to "centos". so the best +# check is just for the original "grub-install" script +if [ -f /sbin/grub-install ]; then exit 0 -else -# Must manually remove grub2 here, otherwise the download below does not work. - yum remove -y grub2 fi -# Remove all old versions of grub2 from the yum cache and then ensure the -# latest version is in the cache. -basearch=$(cat /etc/yum/vars/basearch) -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 +# download the latest grub2 package and setup the install script which +# will be called later by vm/finalise.d/51-bootloader +install-packages -d /tmp/grub grub2 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 diff --git a/elements/yum/bin/install-packages b/elements/yum/bin/install-packages index 25c77aef..90b28f86 100755 --- a/elements/yum/bin/install-packages +++ b/elements/yum/bin/install-packages @@ -33,27 +33,37 @@ function show_options () { echo echo "Options:" 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 " -m -- use custom element package map (Example: -m nova)" + echo " -m map -- use custom element package map (Example: -m nova)" exit 0 } -TEMP=$(getopt -o hudem: -n $SCRIPTNAME -- "$@") -if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi -eval set -- "$TEMP" - -while true ; do - case "$1" in - -u) ${YUM} -y update; exit 0;; - -d) EXTRA_ARGS="--downloadonly"; shift;; - -e) ACTION="erase"; shift;; - -m) MAP_ELEMENT=$2; shift 2;; - -h) show_options;; - --) shift; break ;; - *) echo "Error: unsupported option $1."; exit 1;; +while getopts "hud:em:" opt; do + case "$opt" in + u) + ${YUM} -y update; + exit 0 + ;; + d) + ACTION="download" + DOWNLOAD_PATH=$OPTARG + ;; + e) + ACTION="erase" + ;; + m) + MAP_ELEMENT=$OPTARG + ;; + h) + show_options + ;; + *) + exit 1 + ;; esac done +shift $((OPTIND-1)) # Packages that aren't available in the distro but requested for installation @@ -87,15 +97,39 @@ if [ -n "$WHITELIST" ]; then else PKGS=$(map-packages $WHITELIST) fi + if [ -z "${PKGS}" ]; then echo "Not running install-packages $ACTION with empty packages list" - else - 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 + exit 0 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