From ffc1769d2e9ab6057d44660e2ef4430a70652836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Sat, 7 Apr 2018 11:13:41 +0200 Subject: [PATCH] Improve portability - Fix shebang: `bash` is not always in `/bin/`, and since the script does not have bashism, rely on `sh` which is always in `/bin/`; - Use `/opt/puppetlabs/puppet/bin/ruby` if this file exist and is executable, otherwise use `ruby` from $PATH; - Use `code_manager_config_version.rb` if `.r10k-deploy.json` is found, and `config_version.rb` in all other cases. --- scripts/config_version.sh | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/scripts/config_version.sh b/scripts/config_version.sh index 8dd8086..0378952 100755 --- a/scripts/config_version.sh +++ b/scripts/config_version.sh @@ -1,12 +1,14 @@ -#!/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 -else - /usr/bin/git --version > /dev/null 2>&1 && - /usr/bin/git --git-dir $1/$2/.git rev-parse HEAD || - date +%s +#!/bin/sh + +ruby=ruby +script="$1/$2/scripts/config_version.rb" + +if [ -x /opt/puppetlabs/puppet/bin/ruby ]; then + ruby=/opt/puppetlabs/puppet/bin/ruby fi + +if [ -e $1/$2/.r10k-deploy.json ]; then + script="$1/$2/scripts/code_manager_config_version.rb" +fi + +"${ruby}" "${script}" "$1" "$2"