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
This commit is contained in:
Michael McCune 2015-01-28 00:54:28 -05:00
parent e315186c93
commit 4bf342a48c
3 changed files with 59 additions and 19 deletions

View File

@ -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] 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: 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. 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.

View File

@ -27,12 +27,14 @@ usage() {
echo " [-r 3.1.1|4.0.1]" echo " [-r 3.1.1|4.0.1]"
echo " [-d]" echo " [-d]"
echo " [-m]" echo " [-m]"
echo " [-u]"
echo " '-p' is plugin version (default: all plugins)" echo " '-p' is plugin version (default: all plugins)"
echo " '-i' is operating system of the base image (default: all supported by plugin)" 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 " '-v' is hadoop version (default: all supported by plugin)"
echo " '-r' is MapR Version (default: ${DIB_DEFAULT_MAPR_VERSION})" echo " '-r' is MapR Version (default: ${DIB_DEFAULT_MAPR_VERSION})"
echo " '-d' enable debug mode, root account will have password 'hadoop'" 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 " '-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
echo "You shouldn't specify hadoop version and image type for spark plugin" echo "You shouldn't specify hadoop version and image type for spark plugin"
echo "You shouldn't specify image type for hdp plugin" echo "You shouldn't specify image type for hdp plugin"
@ -43,7 +45,7 @@ usage() {
exit 1 exit 1
} }
while getopts "p:i:v:dmr:" opt; do while getopts "p:i:v:dmur:" opt; do
case $opt in case $opt in
p) p)
PLUGIN=$OPTARG PLUGIN=$OPTARG
@ -68,6 +70,9 @@ while getopts "p:i:v:dmr:" opt; do
r) r)
DIB_MAPR_VERSION=$OPTARG DIB_MAPR_VERSION=$OPTARG
;; ;;
u)
DIB_UPDATE_REQUESTED=true
;;
*) *)
usage usage
;; ;;
@ -153,23 +158,56 @@ fi
################# #################
if [ "$platform" = 'NAME="Ubuntu"' ]; then is_installed() {
apt-get update -y if [ "$platform" = 'NAME="Ubuntu"' ]; then
apt-get install qemu kpartx git -y dpkg -s "$1" &> /dev/null
elif [ "$platform" = 'NAME=Fedora' ]; then else
yum update -y # centos, fedora, opensuse, or rhel
yum install qemu kpartx git -y rpm -q "$1" &> /dev/null
elif [ "$platform" = 'NAME=openSUSE' ]; then fi
zypper --non-interactive --gpg-auto-import-keys in kpartx qemu git-core }
else
# centos or rhel need_required_packages() {
yum update -y if [[ "$platform" == 'NAME="Ubuntu"' || "$platform" == 'NAME=Fedora' ]]; then
yum install qemu-kvm qemu-img kpartx git -y package_list="qemu kpartx git"
if [ ${platform:0:6} = "CentOS" ]; then elif [ "$platform" = 'NAME=openSUSE' ]; then
# install EPEL repo, in order to install argparse package_list="qemu kpartx git-core"
sudo rpm -Uvh --force http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm else
# CentOS requires the python-argparse package be installed separately # centos or rhel
yum install python-argparse -y 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
fi fi

View File

@ -3,4 +3,4 @@
PLUGIN=$1 PLUGIN=$1
export SIM_REPO_PATH=$(pwd) export SIM_REPO_PATH=$(pwd)
sudo -E ./diskimage-create/diskimage-create.sh -p $PLUGIN sudo -E ./diskimage-create/diskimage-create.sh -u -p $PLUGIN