refcodes-batch.0.3.0.source-code.validate-ssh-config.job Maven / Gradle / Ivy
#!/bin/bash
# ------------------------------------------------------------------------------
# Shows the according config:
# ------------------------------------------------------------------------------
function showSshConfiguration {
echo "The switch \"-j $JOB\" validates all \"SSH\" specific " >&2
echo "settings in the CONFIG file. Supported properties in the CONFIG file are: " >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
echo "SSH = (set to 'y' if we can (want to) use SSH, 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_SERVER_KEY_DIR = (the key path for the keys on the server for SSH access with the client)" >&2
echo "SSH_SERVER_SCRIPT_DIR = (the script path where to place for the ssh AUTHORIZED_KEYS command)" >&2
echo "SSH_SERVER_FS_USER = (the user to use for client filesystem SSH access rights) " >&2
echo "SSH_SERVER_FS_GROUP = (the group to use for client filesystem SSH access rights)" >&2
echo "SSH_CLIENT_KEY_DIR = (the key path for the keys on the client for SSH access with the server)" >&2
echo "SSH_CLIENT_FS_USER = (the user to use for client filesystem SSH access rights) " >&2
echo "SSH_CLIENT_FS_GROUP = (the group to use for client filesystem SSH access rights)" >&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 exitOnMissingSshProperty {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingSshProperty\" 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
showSshConfiguration "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 exitOnMissingSshPropertyPath {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingSshPropertyPath\" 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
showSshConfiguration "Path or file \"$VALUE\" not found defined in property \"$1\" of the \"$CONFIG\" config !!!"
exit $EXIT_ERROR
fi
}
# ------------------------------------------------------------------------------
if [[ $VERBOSE = y ]] ; then
echo "\"SSH\" configuration validation is activated ..." >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $SSH = y ]] ; then
SSH_MINIMAL=y
fi
. $SCRIPT_DIR/validate-ssh-minimal-config.job
if [[ $HELP = y ]] ; then
showSshConfiguration
fi
if [[ $HELP = n ]] ; then
if [[ $VERBOSE = y ]] ; then
showProperty "SSH"
showProperty "SSH_SERVER_KEY_DIR"
showProperty "SSH_SERVER_SCRIPT_DIR"
showProperty "SSH_SERVER_FS_USER"
showProperty "SSH_SERVER_FS_GROUP"
showProperty "SSH_CLIENT_FS_USER"
showProperty "SSH_CLIENT_FS_GROUP"
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $SSH = y ]] ; then
exitOnMissingSshProperty "SSH_SERVER_KEY_DIR"
exitOnMissingSshProperty "SSH_SERVER_SCRIPT_DIR"
exitOnMissingSshProperty "SSH_SERVER_FS_USER"
exitOnMissingSshProperty "SSH_SERVER_FS_GROUP"
exitOnMissingSshProperty "SSH_CLIENT_FS_USER"
exitOnMissingSshProperty "SSH_CLIENT_FS_GROUP"
fi
showSuccess "\"SSH\" configuration for \"$CONFIG\" validated !"
fi