Fuel plugin for NSX-T integration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

update_modules.sh 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/bin/bash -e
  2. ###############################################################################
  3. #
  4. # Copyright 2015 Mirantis, Inc.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  7. # not use this file except in compliance with the License. You may obtain
  8. # a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. # License for the specific language governing permissions and limitations
  16. # under the License.
  17. #
  18. ###############################################################################
  19. #
  20. # update_modules.sh
  21. #
  22. # This script uses librarian-puppet-simple to populate the puppet folder with
  23. # upstream puppet modules. By default, it assumes librarian-puppet-simple is
  24. # already available to the environment or it will fail. You can provide command
  25. # line options to have the script use bundler to install librarian-puppet-simple
  26. # if neccessary.
  27. #
  28. # Parameters:
  29. # -b - Use bundler to install librarian-puppet (optional)
  30. # -r - Hard git reset of librarian managed modules back to specified version (optional)
  31. # -p <puppet_version> - Puppet version to use with bundler (optional)
  32. # -h <bundle_dir> - Folder to be used as the home directory for bundler (optional)
  33. # -g <gem_home> - Folder to be used as the gem directory (optional)
  34. # -u - Run librarian update (optional)
  35. # -v - Verbose printing, turns on set -x (optional)
  36. # -? - This usage information
  37. #
  38. # Variables:
  39. # PUPPET_GEM_VERSION - the version of puppet to be pulled down by bundler
  40. # Defaults to '3.4.3'
  41. # BUNDLE_DIR - The folder to store the bundle gems in.
  42. # Defaults to '/var/tmp/.bundle_home'
  43. # GEM_HOME - The folder to store the gems in to not require root.
  44. # Defaults to '/var/tmp/.gem_home'
  45. #
  46. # NOTE: These variables can be overriden via bash environment variable with the
  47. # same name or via the command line paramters.
  48. #
  49. # Author: Alex Schultz <aschultz@mirantis.com>
  50. #
  51. ###############################################################################
  52. set -e
  53. usage() {
  54. cat <<EOF
  55. Usage: $(basename $0) [-b] [-r] [-p <puppet_version>] [-h <bundle_dir>] [-g <gem_home>] [-u] [-?]
  56. Options:
  57. -b - Use bundler instead of assuming librarian-puppet is available
  58. -r - Hard git reset of librarian managed modules back to specified version
  59. -p <puppet_version> - Puppet version to use with bundler
  60. -h <bundle_dir> - Folder to be used as the home directory for bundler
  61. -g <gem_home> - Folder to be used as the gem directory
  62. -u - Run librarian update
  63. -v - Verbose printing of commands
  64. -d - Patch where modules to install
  65. -? - This usage information
  66. EOF
  67. exit 1
  68. }
  69. while getopts ":bp:g:h:vru:d:" opt; do
  70. case $opt in
  71. b)
  72. USE_BUNDLER=true
  73. BUNDLER_EXEC="bundle exec"
  74. ;;
  75. p)
  76. PUPPET_GEM_VERSION=$OPTARG
  77. ;;
  78. h)
  79. BUNDLE_DIR=$OPTARG
  80. ;;
  81. g)
  82. GEM_HOME=$OPTARG
  83. ;;
  84. r)
  85. RESET_HARD=true
  86. ;;
  87. u)
  88. UPDATE=true
  89. ;;
  90. v)
  91. VERBOSE='--verbose'
  92. set -x
  93. ;;
  94. d)
  95. PLUGIN_MOD_DIR=$OPTARG
  96. ;;
  97. \?)
  98. usage
  99. ;;
  100. :)
  101. echo "Option -$OPTARG requires an argument." >&2
  102. usage
  103. ;;
  104. esac
  105. done
  106. shift "$((OPTIND-1))"
  107. DEPLOYMENT_DIR=$(cd $(dirname $0) && pwd -P)
  108. # Timeout in seconds for running puppet librarian
  109. TIMEOUT=600
  110. export PUPPET_GEM_VERSION=${PUPPET_GEM_VERSION:-'~>3.8'}
  111. export BUNDLE_DIR=${BUNDLE_DIR:-'/var/tmp/.bundle_home'}
  112. export GEM_HOME=${GEM_HOME:-'/var/tmp/.gem_home'}
  113. # We need to be in the deployment directory to run librarian-puppet-simple
  114. cd $DEPLOYMENT_DIR
  115. if [ "$USE_BUNDLER" = true ]; then
  116. # ensure bundler is installed
  117. bundle --version
  118. # update bundler modules
  119. bundle update
  120. fi
  121. # if no timeout command, return true so we don't fail this script (LP#1510665)
  122. TIMEOUT_CMD=$(type -P timeout || true)
  123. if [ -n "$TIMEOUT_CMD" ]; then
  124. TIMEOUT_CMD="$TIMEOUT_CMD $TIMEOUT"
  125. fi
  126. # Check to make sure if the folder already exists, it has a .git so we can
  127. # use git on it. If the mod folder exists, but .git doesn't then remove the mod
  128. # folder so it can be properly installed via librarian.
  129. for MOD in $(grep "^mod" Puppetfile | tr -d '[:punct:]' | awk '{ print $2 }'); do
  130. MOD_DIR="${PLUGIN_MOD_DIR}/${MOD}"
  131. if [ -d $MOD_DIR ] && [ ! -d "${MOD_DIR}/.git" ];
  132. then
  133. rm -rf "${MOD_DIR}"
  134. fi
  135. done
  136. # run librarian-puppet install to populate the modules if they do not already
  137. # exist
  138. $TIMEOUT_CMD $BUNDLER_EXEC librarian-puppet install $VERBOSE --path=${PLUGIN_MOD_DIR}
  139. # run librarian-puppet update to ensure the modules are checked out to the
  140. # correct version
  141. if [ "$UPDATE" = true ]; then
  142. $TIMEOUT_CMD $BUNDLER_EXEC librarian-puppet update $VERBOSE --path=${PLUGIN_MOD_DIR}
  143. fi
  144. # do a hard reset on the librarian managed modules LP#1489542
  145. if [ "$RESET_HARD" = true ]; then
  146. for MOD in $(grep "^mod " Puppetfile | tr -d '[:punct:]' | awk '{ print $2 }'); do
  147. cd "${PLUGIN_MOD_DIR}/${MOD}"
  148. git reset --hard
  149. done
  150. cd $DEPLOYMENT_DIR
  151. fi