refcodes-batch.0.3.0.source-code.validate-ssh-minimal-config.job Maven / Gradle / Ivy
#!/bin/bash
# ------------------------------------------------------------------------------
# Shows the according config:
# ------------------------------------------------------------------------------
function showSshMinimalConfiguration {
echo "The switch \"-j $JOB\" validates all \"SSH_MINIMAL\" minimal specific " >&2
echo "settings in the CONFIG file. Supported properties in the CONFIG file are: " >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
echo "SSH_MINIMAL= (set to 'y' if we can (want to) use SSH_MINIMAL, else 'n') " >&2
echo "SSH_SERVER_USER_NAME = (the user on the SSH server for providing SSH access) " >&2
echo "SSH_SERVER_HOSTNAME = (the SSH server host to which to connect with the client via SSH)" >&2
echo "SSH_CLIENT_KEY_DIR = (the key path for the keys on the client for SSH access with the server)" >&2
echo "SSH_KEY_FILE_NAME = (the base key file name for SSH access from the client with the server)" >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
if [[ $# -eq 1 ]] ; then
showError "$1"
fi
}
# ------------------------------------------------------------------------------
# Missing property:
# $1: The missing property's name (without prepended "$").
# ------------------------------------------------------------------------------
function exitOnMissingSshMinimalProperty {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingSshMinimalProperty\" expects an argument !!!" >&2
exit $EXIT_BUG
fi
# $VALUE is the value of the variable passed as $1:
eval "VALUE=\$$1"
if [ -z "$VALUE" ] ; then
showSshMinimalConfiguration "Missing or empty property \"$1\" !!!"
exit $EXIT_ERROR
fi
}
# ------------------------------------------------------------------------------
# File defined in $CONFIG_FILE non exisiting:
# $1 The property name (without prepended "$") with the (non exisitent) path.
# ------------------------------------------------------------------------------
function exitOnMissingSshMinimalPropertyPath {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingSshMinimalPropertyPath\" expects an argument !!!" >&2
exit $EXIT_BUG
fi
# $VALUE is the value of the variable passed as $1:
eval "VALUE=\$$1"
if [ ! -e "$VALUE" ] && [ ! -L "$VALUE" ] ; then
showSshMinimalConfiguration "Path or file \"$VALUE\" not found defined in property \"$1\" of the \"$CONFIG\" config !!!"
exit $EXIT_ERROR
fi
}
# ------------------------------------------------------------------------------
if [[ $VERBOSE = y ]] ; then
echo "\"SSH_MINIMAL\" configuration validation is activated ..." >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $HELP = y ]] ; then
showSshMinimalConfiguration
fi
if [[ $HELP = n ]] ; then
if [[ $VERBOSE = y ]] ; then
showProperty "SSH_MINIMAL"
showProperty "SSH_SERVER_USER_NAME"
showProperty "SSH_SERVER_HOSTNAME"
showProperty "SSH_CLIENT_KEY_DIR"
showProperty "SSH_KEY_FILE_NAME"
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $SSH = y ]] ; then
exitOnMissingSshMinimalProperty "SSH_SERVER_USER_NAME"
exitOnMissingSshMinimalProperty "SSH_SERVER_HOSTNAME"
exitOnMissingSshMinimalProperty "SSH_CLIENT_KEY_DIR"
exitOnMissingSshMinimalProperty "SSH_KEY_FILE_NAME"
fi
showSuccess "\"SSH_MINIMAL\" configuration for \"$CONFIG\" validated !"
fi