fuel-library/deployment/update_modules.sh

115 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
###############################################################################
#
# Copyright 2015 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
###############################################################################
#
# update_modules.sh
#
# This script uses librarian-puppet-simple to populate the puppet folder with
# upstream puppet modules. By default, it assumes librarian-puppet-simple is
# already available to the environment or it will fail. You can provide command
# line options to have the script use bundler to install librarian-puppet-simple
# if neccessary.
#
# Parameters:
# -b - Use bundler to install librarian-puppet (optional)
# -p <puppet_version> - Puppet version to use with bundler (optional)
# -h <bundle_dir> - Folder to be used as the home directory for bundler (optional)
# -g <gem_home> - Folder to be used as the gem directory (optional)
# -v - Verbose printing, turns on set -x (optional)
# -? - This usage information
#
# Variables:
# PUPPET_GEM_VERSION - the version of puppet to be pulled down by bundler
# Defaults to '3.4.3'
# BUNDLE_DIR - The folder to store the bundle gems in.
# Defaults to '/var/tmp/.bundle_home'
# GEM_HOME - The folder to store the gems in to not require root.
# Defaults to '/var/tmp/.gem_home'
#
# NOTE: These variables can be overriden via bash environment variable with the
# same name or via the command line paramters.
#
# Author: Alex Schultz <aschultz@mirantis.com>
#
###############################################################################
set -e
usage() {
cat <<EOF
Usage: $(basename $0) [-b] [-p <puppet_version>] [-h <bundle_dir>] [-g <gem_home>] [-?]
Options:
-b - Use bundler instead of assuming librarian-puppet is available
-p <puppet_version> - Puppet version to use with bundler
-h <bundle_dir> - Folder to be used as the home directory for bundler
-g <gem_home> - Folder to be used as the gem directory
-v - Verbose printing of commands
-? - This usage information
EOF
exit 1
}
while getopts ":bp:l:h:v" opt; do
case $opt in
b)
USE_BUNDLER=true
BUNDLER_EXEC="bundle exec"
;;
p)
PUPPET_GEM_VERSION=$OPTARG
;;
h)
BUNDLE_DIR=$OPTARG
;;
g)
GEM_HOME=$OPTARG
;;
v)
set -x
;;
\?)
usage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
shift "$((OPTIND-1))"
DEPLOYMENT_DIR=$(cd `dirname $0` && pwd -P)
export PUPPET_GEM_VERSION=${PUPPET_GEM_VERSION:-'3.4.3'}
export BUNDLE_DIR=${BUNDLE_DIR:-'/var/tmp/.bundle_home'}
export GEM_HOME=${GEM_HOME:-'/var/tmp/.gem_home'}
# We need to be in the deployment directory to run librarian-puppet-simple
cd $DEPLOYMENT_DIR
if [ "$USE_BUNDLER" = true ]; then
# ensure bundler is installed
bundle --version
# update bundler modules
bundle update
fi
# run librarian-puppet install to populate the modules
$BUNDLER_EXEC librarian-puppet install --path=puppet