From dd9a601542a3022cd69905f670f7adf9b2d80245 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Fri, 19 Oct 2018 22:17:43 -0600 Subject: [PATCH] Check for required files before starting --- root/scripts/backup.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/root/scripts/backup.sh b/root/scripts/backup.sh index 8471328..7a4e272 100644 --- a/root/scripts/backup.sh +++ b/root/scripts/backup.sh @@ -215,6 +215,9 @@ borgPruneParams='--list' ### Set script parameters to null and initialize array variables +unset mailcowConfigFilePath +unset mailcowPath +unset dockerComposeFilePath unset PARAMS unset sqlDumpDir unset webroot @@ -332,7 +335,24 @@ if [ $(id -u) -ne 0 ]; then exit 2 fi +## Find mailcow configuration file so additional variables can be read +mailcowConfigFilePath=$(find / -mount -name "$mailcowConfigFile" -print ) +if [ -z "$mailcowConfigFilePath" ]; then + echo -e "\n${err}Could not locate the specified mailcow configuration" \ + "file: ${lit}${mailcowConfigFile}${normal}" + exit 1 +fi +## Find docker-compose file using mailcow configuration file path as a reference +mailcowPath="${mailcowConfigFilePath%/$mailcowConfigFile*}" +dockerComposeFilePath="$mailcowPath/$dockerComposeFile" +checkExist ff "$dockerComposeFilePath" +checkResult="$?" +if [ "$checkResult" = 1 ]; then + echo -e "\n${err}Could not locate docker-compose configuration file:" \ + "${lit}${dockerComposeFilePath}${normal}" + exit 1 +fi ## Ensure borgDetails file exists checkExist ff "$borgDetails"