aboutsummaryrefslogtreecommitdiffstats
path: root/coin/provisioning/common/unix/common.sourced.sh
diff options
context:
space:
mode:
Diffstat (limited to 'coin/provisioning/common/unix/common.sourced.sh')
-rw-r--r--coin/provisioning/common/unix/common.sourced.sh26
1 files changed, 23 insertions, 3 deletions
diff --git a/coin/provisioning/common/unix/common.sourced.sh b/coin/provisioning/common/unix/common.sourced.sh
index a52880b2..aca5dd04 100644
--- a/coin/provisioning/common/unix/common.sourced.sh
+++ b/coin/provisioning/common/unix/common.sourced.sh
@@ -65,8 +65,10 @@ fatal () {
fi
}
+# Takes one argument which should be the filename of this script. Returns true
+# if the script is being sourced, false if the script is being executed.
is_script_executed () {
- [ x"$(basename "$0")" = x"$1" ]
+ [ x"$(basename $(echo "$0" | sed s/^-//))" = x"$1" ]
}
@@ -74,6 +76,25 @@ is_script_executed common.sourced.sh \
&& fatal "Script common.sourced.sh should always be sourced, not executed"
+_detect_linux_OS_ID () {
+ if [ -f /etc/os-release ]
+ then
+ . /etc/os-release
+ PROVISIONING_OS_ID="$ID"
+ elif [ -f /etc/redhat-release ]
+ then
+ case "$(cat /etc/redhat-release)" in
+ "Red Hat Enterprise Linux"*)
+ PROVISIONING_OS_ID="rhel"
+ ;;
+ "CentOS Linux"*)
+ PROVISIONING_OS_ID="centos"
+ ;;
+ *) fatal "Unknown string in /etc/redhat-release" ;;
+ esac
+ fi
+}
+
set_common_environment () {
# Unfortunately we can't find the provisioning directory from a sourced
# script in a portable way
@@ -86,8 +107,7 @@ set_common_environment () {
case "$uname_s" in
Linux)
PROVISIONING_OS=linux
- . /etc/os-release
- PROVISIONING_OS_ID="$ID"
+ _detect_linux_OS_ID
case "$PROVISIONING_OS_ID" in
suse|sles|opensuse*)
CMD_PKG_INSTALL="sudo zypper -nq install"