2 # Copyright 2014 OpenStack Foundation.
3 # Copyright 2014 Hewlett-Packard Development Company, L.P.
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
17 MODULE_PATH=`puppet config print modulepath | cut -d ':' -f 1`
18 SCRIPT_NAME=$(basename $0)
19 SCRIPT_DIR=$(readlink -f "$(dirname $0)")
22 function remove_module {
23 local SHORT_MODULE_NAME=$1
24 if [ -n "$SHORT_MODULE_NAME" ]; then
25 rm -Rf "$MODULE_PATH/$SHORT_MODULE_NAME"
27 echo "ERROR: remove_module requires a SHORT_MODULE_NAME."
36 for attempt in $(seq 0 3); do
38 git clone $MOD $DEST && break || true
45 # Array of modules to be installed key:value is module:version.
48 # Array of modues to be installed from source and without dependency resolution.
49 # key:value is source location, revision to checkout
50 declare -A SOURCE_MODULES
52 # Array of modues to be installed from source and without dependency resolution from openstack git
53 # key:value is source location, revision to checkout
54 declare -A INTEGRATION_MODULES
56 # load modules.env to populate MODULES[*] and SOURCE_MODULES[*]
58 MODULE_ENV_FILE=${MODULE_FILE:-modules.env}
59 MODULE_ENV_PATH=${MODULE_ENV_PATH:-${SCRIPT_DIR}}
60 if [ -f "${MODULE_ENV_PATH}/${MODULE_ENV_FILE}" ] ; then
61 . "${MODULE_ENV_PATH}/${MODULE_ENV_FILE}"
64 if [ -z "${!MODULES[*]}" ] && [ -z "${!SOURCE_MODULES[*]}" ] ; then
66 echo "WARNING: nothing to do, unable to find MODULES or SOURCE_MODULES"
67 echo " export options, try setting MODULE_ENV_PATH or MODULE_ENV_FILE"
68 echo " export to the proper location of modules.env file."
73 MODULE_LIST=`puppet module list --color=false`
75 # Install modules from source
76 for MOD in ${!SOURCE_MODULES[*]} ; do
78 # get the name of the module directory
79 if [ `echo $MOD | awk -F. '{print $NF}'` = 'git' ]; then
80 echo "Remote repos of the form repo.git are not supported: ${MOD}"
84 MODULE_NAME=`echo $MOD | awk -F- '{print $NF}'`
86 # set up git base command to use the correct path
87 GIT_CMD_BASE="git --git-dir=${MODULE_PATH}/${MODULE_NAME}/.git --work-tree ${MODULE_PATH}/${MODULE_NAME}"
88 # treat any occurrence of the module as a match
89 if ! echo $MODULE_LIST | grep "${MODULE_NAME}" >/dev/null 2>&1; then
90 # clone modules that are not installed
91 git_clone $MOD "${MODULE_PATH}/${MODULE_NAME}"
93 if [ ! -d ${MODULE_PATH}/${MODULE_NAME}/.git ]; then
94 echo "Found directory ${MODULE_PATH}/${MODULE_NAME} that is not a git repo, deleting it and reinstalling from source"
95 remove_module $MODULE_NAME
96 git_clone $MOD "${MODULE_PATH}/${MODULE_NAME}"
97 elif [ `${GIT_CMD_BASE} remote show origin | grep 'Fetch URL' | awk -F'URL: ' '{print $2}'` != $MOD ]; then
98 echo "Found remote in ${MODULE_PATH}/${MODULE_NAME} that does not match desired remote ${MOD}, deleting dir and re-cloning"
99 remove_module $MODULE_NAME
100 git_clone $MOD "${MODULE_PATH}/${MODULE_NAME}"
104 # fetch the latest refs from the repo
105 if [[ $JUST_CLONED -eq 0 ]] ; then
106 # If we just cloned the repo, we do not need to remote update
107 for attempt in $(seq 0 3); do
109 $GIT_CMD_BASE remote update && break || true
112 if [[ $clone_error -ne 0 ]] ; then
116 # make sure the correct revision is installed, I have to use rev-list b/c rev-parse does not work with tags
117 if [ `${GIT_CMD_BASE} rev-list HEAD --max-count=1` != `${GIT_CMD_BASE} rev-list ${SOURCE_MODULES[$MOD]} --max-count=1` ]; then
118 # checkout correct revision
119 $GIT_CMD_BASE checkout ${SOURCE_MODULES[$MOD]}