|
1 |
| -#!/bin/bash |
2 |
| -if [ -e $1/$2/.r10k-deploy.json ] |
3 |
| -then |
4 |
| - /opt/puppetlabs/puppet/bin/ruby $1/$2/scripts/code_manager_config_version.rb $1 $2 |
5 |
| -elif [ -e /opt/puppetlabs/server/pe_version ] |
6 |
| -then |
7 |
| - /opt/puppetlabs/puppet/bin/ruby $1/$2/scripts/config_version.rb $1 $2 |
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# Usage |
| 4 | +if [ $# -ne 2 -o ! -d "$1" -o ! -d "$1/$2" ]; then |
| 5 | + echo "usage: $0 <environmentpath> <environment>" >&2 |
| 6 | + exit 1 |
| 7 | +fi |
| 8 | + |
| 9 | +# For portability, identify a preferred ruby executable to use |
| 10 | +ruby() { |
| 11 | + [ -x /opt/puppetlabs/puppet/bin/ruby ] \ |
| 12 | + && /opt/puppetlabs/puppet/bin/ruby "$@" \ |
| 13 | + || /usr/bin/env ruby "$@" |
| 14 | +} |
| 15 | + |
| 16 | +# Determine how best to calculate a config_version |
| 17 | +if [ -e $1/$2/.r10k-deploy.json ]; then |
| 18 | + # The environment was deployed using r10k. We will calculate the config |
| 19 | + # version using the r10k data. |
| 20 | + ruby $1/$2/scripts/config_version-r10k.rb $1 $2 |
| 21 | + |
| 22 | +elif [ -e /opt/puppetlabs/server/pe_version ]; then |
| 23 | + # This is a Puppet Enterprise system and we can rely on the rugged ruby gem |
| 24 | + # being available. |
| 25 | + ruby $1/$2/scripts/config_version-rugged.rb $1 $2 |
| 26 | + |
| 27 | +elif type git >/dev/null; then |
| 28 | + # The git command is available. |
| 29 | + git --git-dir $1/$2/.git rev-parse HEAD |
| 30 | + |
8 | 31 | else
|
9 |
| - /usr/bin/git --version > /dev/null 2>&1 && |
10 |
| - /usr/bin/git --git-dir $1/$2/.git rev-parse HEAD || |
| 32 | + # Nothing else available; just use the date. |
11 | 33 | date +%s
|
| 34 | + |
12 | 35 | fi
|
0 commit comments