git.lirion.de

Of git, get, and gud

summaryrefslogtreecommitdiffstats
path: root/scripts/config_version.sh
diff options
context:
space:
mode:
authormail_redacted_for_web 2019-10-18 15:22:36 -0700
committermail_redacted_for_web 2019-10-18 15:22:36 -0700
commit458877f386123363234baf29b704a306bbcc0c02 (patch)
treec63198bd3aded9fbb1ef9f178bd9b92bad73cb28 /scripts/config_version.sh
parentbee4fc2740bf6b72675775815901165964676133 (diff)
parente46d209f19ad94c89652bec8064a8b6ce880a752 (diff)
downloadcontrol-repo-template-458877f386123363234baf29b704a306bbcc0c02.tar.bz2
Merge pull request #65 from smortex/portability-fixes
Improve portability
Diffstat (limited to 'scripts/config_version.sh')
-rwxr-xr-xscripts/config_version.sh41
1 files changed, 32 insertions, 9 deletions
diff --git a/scripts/config_version.sh b/scripts/config_version.sh
index 8dd8086..bdbc511 100755
--- a/scripts/config_version.sh
+++ b/scripts/config_version.sh
@@ -1,12 +1,35 @@
-#!/bin/bash
-if [ -e $1/$2/.r10k-deploy.json ]
-then
- /opt/puppetlabs/puppet/bin/ruby $1/$2/scripts/code_manager_config_version.rb $1 $2
-elif [ -e /opt/puppetlabs/server/pe_version ]
-then
- /opt/puppetlabs/puppet/bin/ruby $1/$2/scripts/config_version.rb $1 $2
+#!/bin/sh
+
+# Usage
+if [ $# -ne 2 -o ! -d "$1" -o ! -d "$1/$2" ]; then
+ echo "usage: $0 <environmentpath> <environment>" >&2
+ exit 1
+fi
+
+# For portability, identify a preferred ruby executable to use
+ruby() {
+ [ -x /opt/puppetlabs/puppet/bin/ruby ] \
+ && /opt/puppetlabs/puppet/bin/ruby "$@" \
+ || /usr/bin/env ruby "$@"
+}
+
+# Determine how best to calculate a config_version
+if [ -e $1/$2/.r10k-deploy.json ]; then
+ # The environment was deployed using r10k. We will calculate the config
+ # version using the r10k data.
+ ruby $1/$2/scripts/config_version-r10k.rb $1 $2
+
+elif [ -e /opt/puppetlabs/server/pe_version ]; then
+ # This is a Puppet Enterprise system and we can rely on the rugged ruby gem
+ # being available.
+ ruby $1/$2/scripts/config_version-rugged.rb $1 $2
+
+elif type git >/dev/null; then
+ # The git command is available.
+ git --git-dir $1/$2/.git rev-parse HEAD
+
else
- /usr/bin/git --version > /dev/null 2>&1 &&
- /usr/bin/git --git-dir $1/$2/.git rev-parse HEAD ||
+ # Nothing else available; just use the date.
date +%s
+
fi