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

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

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

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

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

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

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

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

if [[ $HELP = n ]] ; then
	if [[ $VERBOSE = y ]] ; then
		showProperty "DB_BACKUP"
		showProperty "DB_BACKUP_DIR"
		showProperty "DB_BACKUP_BASE_NAME"
		showProperty "DB_BACKUP_FS_USER"
		showProperty "DB_BACKUP_FS_GROUP"
		# echo "--------------------------------------------------------------------------------" >&2
		logSeparator
	fi

	if [[ $DB_BACKUP = y ]] ; then
		exitOnMissingDbBackupProperty "DB_BACKUP_DIR"
		exitOnMissingDbBackupProperty "DB_BACKUP_BASE_NAME"
		exitOnMissingDbBackupProperty "DB_BACKUP_FS_USER"
		exitOnMissingDbBackupProperty "DB_BACKUP_FS_GROUP"
	fi
	
	if [[ $DB = n ]] ; then
		if [[ $DB_BACKUP = y ]] ; then
			showMediawikiConfiguration "Setting \"DB_BACKUP=y\") not possible whilst \"DB=n\" !!!"
			exit $EXIT_ERROR
		fi
	fi

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy