From f298a937cd9061486b73b20178a627fee45ad932 Mon Sep 17 00:00:00 2001 From: Andrew Grimberg Date: Fri, 13 May 2016 12:27:04 -0700 Subject: [PATCH] Determine the system_type based upon hostname Use the slave host name to determine the system_type that should be used for the final spin-up control script. If a slave name should map to a different one, then a spin-up script of the correct name should be created which then calls the appropriate script. Change-Id: I511362d3f762970c2ea6c3b2ee457b01833723fd Signed-off-by: Andrew Grimberg --- jenkins-scripts/system_type.sh | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 jenkins-scripts/system_type.sh diff --git a/jenkins-scripts/system_type.sh b/jenkins-scripts/system_type.sh new file mode 100755 index 000000000..201f34f9a --- /dev/null +++ b/jenkins-scripts/system_type.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# @License EPL-1.0 +############################################################################## +# Copyright (c) 2016 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## + +HOST=$(/usr/bin/hostname) +SYSTEM_TYPE='' + +# We use a separator character of - for the slave parts +IFS='-' read -r -a HOSTPARTS <<< "${HOST}" + +# slurp in the control scripts +FILES=($(find . -maxdepth 1 -type f -iname '*.sh' -exec basename -s '.sh' {} \;)) +# remap into an associative array +declare -A A_FILES +for key in "${!FILES[@]}" +do + A_FILES[${FILES[$key]}]="${key}" +done + +# Find our system_type control script if possible +for i in "${HOSTPARTS[@]}" +do + if [ "${A_FILES[${i}]}" != "" ] + then + SYSTEM_TYPE=${i} + break + fi +done + +# Write out the system type to an environment file to then be sourced +echo "SYSTEM_TYPE=${SYSTEM_TYPE}" > /tmp/system_type.sh + +# vim: sw=4 ts=4 sts=4 et : -- 2.36.6