From 4bf342a48cf317e23e86ebfceefe421463ad5022 Mon Sep 17 00:00:00 2001 From: Michael McCune Date: Wed, 28 Jan 2015 00:54:28 -0500 Subject: [PATCH] Adding new update option to diskimage-create.sh This change removes the global system updates in favor of only updating the required packages for diskimage creation. Additionally the script will not automatically install the updates but will warn the user if the packages are not installed. A switch is provided to allow the script to install the updates. Changes * adding function to detect an installed package * adding function to check for a list of installed packages * adding command line switch for updating (-u) * removing global update commands * refactoring update logic to fail gracefully or accept switch * adding -u switch to build-images gate tool * adding note in documentation about update command line switch Closes-Bug: 1375843 Change-Id: Iba5e676fa8ef7a852b71acd9e4c19d32f848285a --- diskimage-create/README.rst | 2 + diskimage-create/diskimage-create.sh | 74 +++++++++++++++++++++------- tools/gate/build-images | 2 +- 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/diskimage-create/README.rst b/diskimage-create/README.rst index 07da003e..4530f278 100644 --- a/diskimage-create/README.rst +++ b/diskimage-create/README.rst @@ -41,6 +41,8 @@ NOTE: Do not create all images for all plugins with the same mirrors. Different sudo bash sahara-image-elements/diskimage-create/diskimage-create.sh -i [ubuntu|fedora|centos] +7. If the host system is missing packages required for diskimage-create.sh, the '-u' commandline option will instruct the script to install them without prompt. + NOTE for 4, 5, 6: For Vanilla you can create ubuntu, fedora and centos cloud image with hadoop 1.x.x and 2.x.x versions. Use environment variables 'DIB_HADOOP_VERSION_1' and 'DIB_HADOOP_VERSION_2' to change defaults. diff --git a/diskimage-create/diskimage-create.sh b/diskimage-create/diskimage-create.sh index a79bfd00..7fef434c 100755 --- a/diskimage-create/diskimage-create.sh +++ b/diskimage-create/diskimage-create.sh @@ -27,12 +27,14 @@ usage() { echo " [-r 3.1.1|4.0.1]" echo " [-d]" echo " [-m]" + echo " [-u]" echo " '-p' is plugin version (default: all plugins)" echo " '-i' is operating system of the base image (default: all supported by plugin)" echo " '-v' is hadoop version (default: all supported by plugin)" echo " '-r' is MapR Version (default: ${DIB_DEFAULT_MAPR_VERSION})" echo " '-d' enable debug mode, root account will have password 'hadoop'" echo " '-m' set the diskimage-builder repo to the master branch (default: $DEFAULT_DIB_REPO_BRANCH)" + echo " '-u' install missing packages necessary for building" echo echo "You shouldn't specify hadoop version and image type for spark plugin" echo "You shouldn't specify image type for hdp plugin" @@ -43,7 +45,7 @@ usage() { exit 1 } -while getopts "p:i:v:dmr:" opt; do +while getopts "p:i:v:dmur:" opt; do case $opt in p) PLUGIN=$OPTARG @@ -68,6 +70,9 @@ while getopts "p:i:v:dmr:" opt; do r) DIB_MAPR_VERSION=$OPTARG ;; + u) + DIB_UPDATE_REQUESTED=true + ;; *) usage ;; @@ -153,23 +158,56 @@ fi ################# -if [ "$platform" = 'NAME="Ubuntu"' ]; then - apt-get update -y - apt-get install qemu kpartx git -y -elif [ "$platform" = 'NAME=Fedora' ]; then - yum update -y - yum install qemu kpartx git -y -elif [ "$platform" = 'NAME=openSUSE' ]; then - zypper --non-interactive --gpg-auto-import-keys in kpartx qemu git-core -else - # centos or rhel - yum update -y - yum install qemu-kvm qemu-img kpartx git -y - if [ ${platform:0:6} = "CentOS" ]; then - # install EPEL repo, in order to install argparse - sudo rpm -Uvh --force http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm - # CentOS requires the python-argparse package be installed separately - yum install python-argparse -y +is_installed() { + if [ "$platform" = 'NAME="Ubuntu"' ]; then + dpkg -s "$1" &> /dev/null + else + # centos, fedora, opensuse, or rhel + rpm -q "$1" &> /dev/null + fi +} + +need_required_packages() { + if [[ "$platform" == 'NAME="Ubuntu"' || "$platform" == 'NAME=Fedora' ]]; then + package_list="qemu kpartx git" + elif [ "$platform" = 'NAME=openSUSE' ]; then + package_list="qemu kpartx git-core" + else + # centos or rhel + package_list="qemu-kvm qemu-img kpartx git" + if [ ${platform:0:6} = "CentOS" ]; then + # CentOS requires the python-argparse package be installed separately + package_list="$package_list python-argparse" + fi + fi + + for p in `echo $package_list`; do + if ! is_installed $p; then + return 0 + fi + done + return 1 +} + +if need_required_packages; then + # install required packages if requested + if [ -n "$DIB_UPDATE_REQUESTED" ]; then + if [ "$platform" = 'NAME="Ubuntu"' ]; then + apt-get install $package_list -y + elif [ "$platform" = 'NAME=openSUSE' ]; then + zypper --non-interactive --gpg-auto-import-keys in $package_list + else + # fedora, centos, and rhel share an install command + if [ ${platform:0:6} = "CentOS" ]; then + # install EPEL repo, in order to install argparse + rpm -Uvh --force http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm + fi + yum install $package_list -y + fi + else + echo "Missing one of the following packages: $package_list" + echo "Please install manually or rerun with the update option (-u)." + exit 1 fi fi diff --git a/tools/gate/build-images b/tools/gate/build-images index 83ba8f54..04081bd6 100755 --- a/tools/gate/build-images +++ b/tools/gate/build-images @@ -3,4 +3,4 @@ PLUGIN=$1 export SIM_REPO_PATH=$(pwd) -sudo -E ./diskimage-create/diskimage-create.sh -p $PLUGIN +sudo -E ./diskimage-create/diskimage-create.sh -u -p $PLUGIN