From 022cb2c1c2ff7cc86ce20f72e3e9d8bd6037b219 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Mon, 27 Oct 2014 12:49:30 -0400 Subject: [PATCH] Support installing packages by default Adds new disk-image-create --install-type option which can be used to enable alternate install types. The default install type is 'source'. The motivation is to eliminate elements like enable-package-installs which require coupling and also don't work with elements in multiple element repositories. This patch does not prevent you from using the previous DIB_INSTALLTYPE_ variables to customize the install type, rather it just changes the default so you don't have to set it so often when using things like packages. Change-Id: Icee98440fc2251728f2dca30e7c4789a0fd89b93 --- README.md | 9 ++++++++- bin/disk-image-create | 7 ++++++- .../base/extra-data.d/99-enable-install-types | 18 +++++++++--------- .../extra-data.d/98-source-repositories | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c0a33fd4..5864899b 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,14 @@ Install Types ------------- Install types permit elements to be installed from different sources, such as -git repositories, distribution packages, or pip. +git repositories, distribution packages, or pip. The default install type +is 'source' but it can be modified on the disk-image-create command line +via the --install-type option. For example you can set: + + --install-type=package + +to enable package installs by default. Alternately, you can also +set DIB\_DEFAULT\_INSTALLTYPE. Many elements expose different install types. The different implementations live under `--install` directories under an diff --git a/bin/disk-image-create b/bin/disk-image-create index 687842df..b3d98bfc 100755 --- a/bin/disk-image-create +++ b/bin/disk-image-create @@ -65,6 +65,7 @@ function show_options () { echo " Options need to be comma separated, and follow the key=value pattern." echo " --root-label label -- label for the root filesystem. Defaults to 'cloudimg-rootfs'." echo " --ramdisk-element -- specify the main element to be used for building ramdisks." + echo " --install-type -- specify the default installation type. Defaults to 'source'. Set to 'package' to use package based installations by default." if [ "$IS_RAMDISK" == "0" ]; then echo " -n skip the default inclusion of the 'base' element" echo " -p package[,package,package] -- list of packages to install in the image" @@ -90,7 +91,8 @@ INSTALL_PACKAGES="" IMAGE_TYPES=("qcow2") COMPRESS_IMAGE="true" export DIB_ROOT_LABEL="" -TEMP=`getopt -o a:ho:t:xucnp: -l no-tmpfs,offline,help,min-tmpfs:,image-size:,image-cache:,max-online-resize:,qemu-img-options:,ramdisk-element:,root-label: -n $SCRIPTNAME -- "$@"` +DIB_DEFAULT_INSTALLTYPE=${DIB_DEFAULT_INSTALLTYPE:-"source"} +TEMP=`getopt -o a:ho:t:xucnp: -l no-tmpfs,offline,help,min-tmpfs:,image-size:,image-cache:,max-online-resize:,qemu-img-options:,ramdisk-element:,root-label:,install-type: -n $SCRIPTNAME -- "$@"` if [ $? -ne 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi # Note the quotes around `$TEMP': they are essential! @@ -116,6 +118,7 @@ while true ; do --qemu-img-options) QEMU_IMG_OPTIONS=$2; shift 2;; --root-label) export DIB_ROOT_LABEL=$2; shift 2;; --ramdisk-element) RAMDISK_ELEMENT=$2; shift 2;; + --install-type) DIB_DEFAULT_INSTALLTYPE=$2; shift 2;; --) shift ; break ;; *) echo "Internal error!" ; exit 1 ;; esac @@ -162,6 +165,8 @@ fi mk_build_dir create_base +# This variable needs to be propagated into the chroot +echo "export DIB_DEFAULT_INSTALLTYPE=\"${DIB_DEFAULT_INSTALLTYPE}\"" > $TMP_HOOKS_PATH/environment.d/11-dib-install-type.bash run_d extra-data # Run pre-install scripts. These do things that prepare the chroot for package installs run_d_in_target pre-install diff --git a/elements/base/extra-data.d/99-enable-install-types b/elements/base/extra-data.d/99-enable-install-types index 8fdae7ed..71b91674 100755 --- a/elements/base/extra-data.d/99-enable-install-types +++ b/elements/base/extra-data.d/99-enable-install-types @@ -45,14 +45,14 @@ for _install_type_var in $INSTALL_TYPE_VARS; do done -# For any existing *-source-install directory under install.d, if an -# environment variable setting a different install type was not seen, enable -# the source install type. -source_install_dirs=$(ls -d $TMP_HOOKS_PATH/install.d/*-source-install || true) -for _source_install_dir in $source_install_dirs; do - SUFFIX="-source-install" - _source_install_dir=$(basename $_source_install_dir) - INSTALLDIRPREFIX=${_source_install_dir%$SUFFIX} +# For any existing *--install directory under install.d, +# if an environment variable setting a different install type was not seen, +# enable the default (set via --install-type). +default_install_type_dirs=$(ls -d $TMP_HOOKS_PATH/install.d/*-${DIB_DEFAULT_INSTALLTYPE}-install || true) +for _install_dir in $default_install_type_dirs; do + SUFFIX="-${DIB_DEFAULT_INSTALLTYPE}-install" + _install_dir=$(basename $_install_dir) + INSTALLDIRPREFIX=${_install_dir%$SUFFIX} found=0 for specified in ${SPECIFIED_ELEMS[@]}; do @@ -65,7 +65,7 @@ for _source_install_dir in $source_install_dirs; do # install type not specified, assume source if [ "$found" = "0" ]; then pushd $TMP_HOOKS_PATH/install.d - ln -sf $_source_install_dir/* . + ln -sf $_install_dir/* . popd fi done diff --git a/elements/source-repositories/extra-data.d/98-source-repositories b/elements/source-repositories/extra-data.d/98-source-repositories index 0a0e9336..35d46a68 100755 --- a/elements/source-repositories/extra-data.d/98-source-repositories +++ b/elements/source-repositories/extra-data.d/98-source-repositories @@ -89,7 +89,7 @@ function get_repos_for_element(){ # Return if install type is not source local INSTALL_TYPE_VAR=DIB_INSTALLTYPE_${REPONAME//[^A-Za-z0-9]/_} - local INSTALL_TYPE=${!INSTALL_TYPE_VAR:-source} + local INSTALL_TYPE=${!INSTALL_TYPE_VAR:-$DIB_DEFAULT_INSTALLTYPE} if [ ! $INSTALL_TYPE = "source" ]; then echo "$REPONAME install type not set to source" continue