All Downloads are FREE. Search and download functionalities are using the official Maven repository.

refcodes-batch.0.3.0.source-code.validate-folder-backup-config.job Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
#!/bin/bash

# -----------------------------------------------------------------------------
# Shows the according config:
# -----------------------------------------------------------------------------
function showBackupFolderConfiguration {
	echo "The switch \"-j $JOB\" validates all \"FOLDER_BACKUP\" specific                 " >&2
	echo "settings in the CONFIG file. Supported properties in the CONFIG file are:       " >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
	echo "FOLDER_BACKUP = (set to 'y' if want to enable folder backups, else 'n')         " >&2
	echo "FOLDER_BACKUP_DIR = (the folder for the backups)                               " >&2
	echo "FOLDER_BACKUP_BASE_NAME = (the base name for the folder backup archive)         " >&2
	echo "FOLDER_BACKUP_FS_USER = (the user to use for file access rights on folder backup)" >&2
	echo "FOLDER_BACKUP_FS_GROUP = (the group to use for file access rights on the folder backup)" >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
	if [[ $# -eq 1 ]] ; then
		showError "$1"
	fi
}

# ------------------------------------------------------------------------------
# Missing property: 
# $1: The missing property's name (without prepended "$").
# ------------------------------------------------------------------------------
function exitOnMissingFolderBackupProperty {
	if [ -z "$1" ] ; then
		showError "Argument missing: The function \"exitOnMissingFolderBackupProperty\" 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
		showBackupFolderConfiguration "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 exitOnMissingFolderBackupPropertyPath {
	if [ -z "$1" ] ; then
		showError "Argument missing: The function \"exitOnMissingFolderBackupPropertyPath\" 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
		showBackupFolderConfiguration "Path or file \"$VALUE\" not found defined in property \"$1\" of the \"$CONFIG\" config !!!"
		exit $EXIT_ERROR
	fi
}

# -----------------------------------------------------------------------------

if [[ $VERBOSE = y ]] ; then
	echo "\"FOLDER_BACKUP\" configuration validation is activated ..." >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
fi

if [[ $HELP = y ]] ; then
	showBackupFolderConfiguration 
fi

if [[ $HELP = n ]] ; then
	if [[ $VERBOSE = y ]] ; then
		showProperty "FOLDER_BACKUP"
		showProperty "FOLDER_BACKUP_DIR"
		showProperty "FOLDER_BACKUP_BASE_NAME"
		showProperty "FOLDER_BACKUP_FS_USER"
		showProperty "FOLDER_BACKUP_FS_GROUP"
		# echo "--------------------------------------------------------------------------------" >&2
		logSeparator
	fi

	if [[ $FOLDER_BACKUP = y ]] ; then
		exitOnMissingFolderBackupProperty "FOLDER_BACKUP_DIR"
		exitOnMissingFolderBackupProperty "FOLDER_BACKUP_BASE_NAME"
		exitOnMissingFolderBackupProperty "FOLDER_BACKUP_FS_USER"
		exitOnMissingFolderBackupProperty "FOLDER_BACKUP_FS_GROUP"
	fi

	showSuccess "\"FOLDER_BACKUP\" configuration for \"$CONFIG\" validated !"
fi




© 2015 - 2024 Weber Informatics LLC | Privacy Policy