Skip to content

Commit 458877f

Browse files
authored
Merge pull request #65 from smortex/portability-fixes
Improve portability
2 parents bee4fc2 + e46d209 commit 458877f

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed
File renamed without changes.

scripts/config_version.sh

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
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+
831
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.
1133
date +%s
34+
1235
fi

0 commit comments

Comments
 (0)