From 83fcfe0909e3d911cc8e40d5b0f5426888ce4b4e Mon Sep 17 00:00:00 2001
From: Elian Loraux <elian.loraux@tetras-libre.fr>
Date: Tue, 8 Apr 2025 16:12:22 +0200
Subject: [PATCH] Source .env with check, use -p for mkdir and check actual
 directory

---
 backup.sh | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/backup.sh b/backup.sh
index 506bb96..1a061e7 100644
--- a/backup.sh
+++ b/backup.sh
@@ -1,18 +1,25 @@
 #!/bin/bash
-
 echo "Backing up Keycloak DB and config"
 
+
+DIR=$(realpath $(dirname $0))
+
+if [ ! -e $DIR/.env ]
+then
+    echo ".env file do not exist"
+    exit 1
+fi
+
+. $DIR/.env
+
 if [ -z "$MARIADB_PASS" ]; then
   echo "Error: the MARIADB_PASS variable is not set or is empty."
   exit 1
 fi
 
-if [ ! -d "backups" ]; then
-  mkdir "backups"
-fi
+mkdir -p $DIR/backups`
 
-out="backups/keycloak_$(date +%Y%m%d_%H%M).tar.gz"
-. .env
+out="$DIR/backups/keycloak_$(date +%Y%m%d_%H%M).tar.gz"
 
 if command -v docker-compose &> /dev/null; then
     DOCKER_COMPOSE="docker-compose"
-- 
GitLab