From d927196cad12cb327677646ba7027f6bd8733303 Mon Sep 17 00:00:00 2001 From: Ivan Davidov Date: Sat, 2 Dec 2017 19:49:33 +0200 Subject: [PATCH] Overlay bundles now can have their own '.config' files. --- src/.config | 15 +------- src/minimal_overlay/bundles/bosh_cli/.config | 5 +++ .../bundles/bosh_cli/01_get.sh | 8 ++-- .../bundles/bosh_cli/02_install.sh | 2 + .../bundles/bosh_cli/bundle.sh | 2 - src/minimal_overlay/bundles/cf_cli/.config | 5 +++ src/minimal_overlay/bundles/cf_cli/01_get.sh | 8 ++-- .../bundles/cf_cli/02_install.sh | 2 + src/minimal_overlay/bundles/cf_cli/bundle.sh | 2 - src/minimal_overlay/common.sh | 37 ++++++++++++++++++- 10 files changed, 60 insertions(+), 26 deletions(-) create mode 100644 src/minimal_overlay/bundles/bosh_cli/.config create mode 100644 src/minimal_overlay/bundles/cf_cli/.config diff --git a/src/.config b/src/.config index 4c55b044a..0d07eb2ae 100644 --- a/src/.config +++ b/src/.config @@ -41,18 +41,6 @@ SYSLINUX_SOURCE_URL=http://kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.0 # # ##################################################################### -# You can find the latest Cloud Foundry CLI binary here: -# -# http://github.com/cloudfoundry/cli -# -BOSH_CLI_URL=https://s3.amazonaws.com/bosh-cli-artifacts/bosh-cli-2.0.45-linux-amd64 - -# You can find the latest Cloud Foundry CLI binary here: -# -# http://github.com/cloudfoundry/cli -# -CLOUD_FOUNDRY_CLI_URL=http://cli.run.pivotal.io/stable?release=linux64-binary - # You can find the latest coreutils source bundles here: # # http://ftp.gnu.org/gnu/coreutils/ @@ -273,7 +261,8 @@ OVERLAY_TYPE=folder # # The default overlay bundles are 'dhcp' and 'mll_source'. # -OVERLAY_BUNDLES=dhcp,mll_source +#OVERLAY_BUNDLES=dhcp,mll_source +OVERLAY_BUNDLES=cf_tools # The location where the overlay bundle software will be stored. # diff --git a/src/minimal_overlay/bundles/bosh_cli/.config b/src/minimal_overlay/bundles/bosh_cli/.config new file mode 100644 index 000000000..c394e452a --- /dev/null +++ b/src/minimal_overlay/bundles/bosh_cli/.config @@ -0,0 +1,5 @@ +# You can find the latest BOSH CLI binary here: +# +# https://bosh.io/docs/cli-v2.html +# +BOSH_CLI_URL=https://s3.amazonaws.com/bosh-cli-artifacts/bosh-cli-2.0.45-linux-amd64 diff --git a/src/minimal_overlay/bundles/bosh_cli/01_get.sh b/src/minimal_overlay/bundles/bosh_cli/01_get.sh index 7dbf4950f..72a49b1ae 100755 --- a/src/minimal_overlay/bundles/bosh_cli/01_get.sh +++ b/src/minimal_overlay/bundles/bosh_cli/01_get.sh @@ -2,11 +2,11 @@ set -e -# Grab everything after the '=' character. -DOWNLOAD_URL=`grep -i ^BOSH_CLI_URL= $CONFIG | cut -f2- -d'=' | xargs` +. ../../common.sh -# Read the 'USE_LOCAL_SOURCE' property from '.config' -USE_LOCAL_SOURCE="$(grep -i USE_LOCAL_SOURCE $MAIN_SRC_DIR/.config | cut -f2 -d'=')" +# Read the common configuration properties. +DOWNLOAD_URL=`read_property BOSH_CLI_URL` +USE_LOCAL_SOURCE=`read_property USE_LOCAL_SOURCE` if [ "$USE_LOCAL_SOURCE" = "true" -a ! -f $MAIN_SRC_DIR/source/overlay/bosh-cli ] ; then echo "Shell script '$MAIN_SRC_DIR/source/overlay/bosh-cli' is missing and will be downloaded." diff --git a/src/minimal_overlay/bundles/bosh_cli/02_install.sh b/src/minimal_overlay/bundles/bosh_cli/02_install.sh index e6caa7751..266a9a767 100755 --- a/src/minimal_overlay/bundles/bosh_cli/02_install.sh +++ b/src/minimal_overlay/bundles/bosh_cli/02_install.sh @@ -2,6 +2,8 @@ set -e +. ../../common.sh + echo "Removing old 'BOSH CLI' artifacts. This may take a while." rm -rf $DEST_DIR mkdir -p $DEST_DIR/opt/$BUNDLE_NAME diff --git a/src/minimal_overlay/bundles/bosh_cli/bundle.sh b/src/minimal_overlay/bundles/bosh_cli/bundle.sh index 0be2a10d3..45a36c73c 100755 --- a/src/minimal_overlay/bundles/bosh_cli/bundle.sh +++ b/src/minimal_overlay/bundles/bosh_cli/bundle.sh @@ -2,8 +2,6 @@ set -e -. ../../common.sh - ./01_get.sh ./02_install.sh diff --git a/src/minimal_overlay/bundles/cf_cli/.config b/src/minimal_overlay/bundles/cf_cli/.config new file mode 100644 index 000000000..a3c62758c --- /dev/null +++ b/src/minimal_overlay/bundles/cf_cli/.config @@ -0,0 +1,5 @@ +# You can find the latest Cloud Foundry CLI binary here: +# +# http://github.com/cloudfoundry/cli +# +CLOUD_FOUNDRY_CLI_URL=http://cli.run.pivotal.io/stable?release=linux64-binary diff --git a/src/minimal_overlay/bundles/cf_cli/01_get.sh b/src/minimal_overlay/bundles/cf_cli/01_get.sh index 5ff387da0..222cce182 100755 --- a/src/minimal_overlay/bundles/cf_cli/01_get.sh +++ b/src/minimal_overlay/bundles/cf_cli/01_get.sh @@ -2,11 +2,11 @@ set -e -# Grab everything after the '=' character. -DOWNLOAD_URL=`grep -i ^CLOUD_FOUNDRY_CLI_URL= $CONFIG | cut -f2- -d'=' | xargs` +. ../../common.sh -# Read the 'USE_LOCAL_SOURCE' property from '.config' -USE_LOCAL_SOURCE="$(grep -i USE_LOCAL_SOURCE $MAIN_SRC_DIR/.config | cut -f2 -d'=')" +# Read the common configuration properties. +DOWNLOAD_URL=`read_property CLOUD_FOUNDRY_CLI_URL` +USE_LOCAL_SOURCE=`read_property USE_LOCAL_SOURCE` if [ "$USE_LOCAL_SOURCE" = "true" -a ! -f $MAIN_SRC_DIR/source/overlay/cf-cli.tgz ] ; then echo "Shell script $MAIN_SRC_DIR/source/overlay/cf-cli.tgz is missing and will be downloaded." diff --git a/src/minimal_overlay/bundles/cf_cli/02_install.sh b/src/minimal_overlay/bundles/cf_cli/02_install.sh index a6a1505af..c308658d2 100755 --- a/src/minimal_overlay/bundles/cf_cli/02_install.sh +++ b/src/minimal_overlay/bundles/cf_cli/02_install.sh @@ -2,6 +2,8 @@ set -e +. ../../common.sh + echo "Removing old 'Cloud Foundry CLI' artifacts. This may take a while." rm -rf $DEST_DIR mkdir -p $DEST_DIR/opt/$BUNDLE_NAME diff --git a/src/minimal_overlay/bundles/cf_cli/bundle.sh b/src/minimal_overlay/bundles/cf_cli/bundle.sh index 0be2a10d3..45a36c73c 100755 --- a/src/minimal_overlay/bundles/cf_cli/bundle.sh +++ b/src/minimal_overlay/bundles/cf_cli/bundle.sh @@ -2,8 +2,6 @@ set -e -. ../../common.sh - ./01_get.sh ./02_install.sh diff --git a/src/minimal_overlay/common.sh b/src/minimal_overlay/common.sh index e7eae9d98..c95aa933a 100755 --- a/src/minimal_overlay/common.sh +++ b/src/minimal_overlay/common.sh @@ -7,7 +7,7 @@ set -e export MAIN_SRC_DIR=`realpath --no-symlinks $PWD/../../../` export WORK_DIR=$MAIN_SRC_DIR/work -export SRC_DIR=`pwd` +export SRC_DIR=`realpath --no-symlinks $PWD` export OVERLAY_ROOTFS=$WORK_DIR/overlay_rootfs export BUNDLE_NAME=`basename $SRC_DIR` export DEST_DIR=$WORK_DIR/overlay/$BUNDLE_NAME/${BUNDLE_NAME}_installed @@ -15,6 +15,41 @@ export CONFIG=$MAIN_SRC_DIR/.config export SYSROOT=$WORK_DIR/sysroot #export SYSROOT_SPECS=$WORK_DIR/sysroot.specs +# This function reads property from the main '.config' file. +# If there is local '.config' file in the current directory +# the property value is overridden with the value found in +# the local '.config' file, if the property is present there. +# +# Using () instead of {} for the function body is a POSIX +# compliant way to execute subshell and as consequence all +# variables in the function will become effectively in local +# scope. Note that the 'local' keyword is supported by most +# shells but it is not POSIX compliant. +read_property() ( + # The property we are looking for. + prop_name=$1 + + # The value of the property set initially to empty string. + prop_value= + + if [ ! "$prop_name" = "" ] ; then + # Search in the main '.config' file. + prop_value=`grep -i ^${prop_name}= $CONFIG | cut -f2- -d'=' | xargs` + + if [ -f $SRC_DIR/.config ] ; then + # Search in the local '.config' file. + prop_value_local=`grep -i ^${prop_name}= $SRC_DIR/.config | cut -f2- -d'=' | xargs` + + if [ ! "$prop_value_local" = "" ] ; then + # Override the original value with the local value. + prop_value=$prop_value_local + fi + fi + fi + + echo $prop_value +) + # Read the 'JOB_FACTOR' property from $CONFIG export JOB_FACTOR="$(grep -i ^JOB_FACTOR $CONFIG | cut -f2 -d'=')"