From 41d82dc21dc30d244824a5bcf3680bc880479e54 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Wed, 19 Jul 2023 21:41:48 +0200 Subject: [PATCH] ceck clone --- Dockerfile | 2 ++ app.sh | 26 ++++++++++++++++++-------- docker-compose.yml | 1 + 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2bc04ed..02dd608 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,3 +14,5 @@ RUN chmod +x app.sh # Set the entrypoint to execute the script ENTRYPOINT ["/app/app.sh"] + +# cron fehlt diff --git a/app.sh b/app.sh index 5b57164..ab35d30 100644 --- a/app.sh +++ b/app.sh @@ -9,13 +9,29 @@ GIT_USERNAME="$GIT_USERNAME" # Git username for SSH authentication GIT_SSH_KEY="$GIT_SSH_KEY" # Git SSH private key path (mounted in Docker container) GIT_REPO_PATH="/app/config_repo" # Directory where the Git repository is cloned in the Docker container +mkdir -p /app # Function to export RouterOS configuration export_routeros_config() { local device="$1" local username="$2" local ssh_key="$3" - ssh -i "$ssh_key" "$username"@"$device" /export > "/app/${device}_config_export.txt" + ssh -i "$ssh_key" "$username"@"$device" /export > "/${GIT_REPO_PATH}/${device}.txt" +} + +# Function to check if the Git repository exists and pull or clone accordingly +check_and_pull_git_repo() { + if [ -d "$GIT_REPO_PATH" ]; then + cd "$GIT_REPO_PATH" + if [ -d ".git" ]; then + git pull origin master + else + echo "Error: The directory exists but is not a Git repository." + exit 1 + fi + else + git clone "$GIT_REPO_URL" "$GIT_REPO_PATH" + fi } # Function to commit and push the configuration to the Git repository @@ -41,12 +57,6 @@ for device_config in "${devices[@]}"; do export_routeros_config "$device" "$username" "$ssh_key" done -cd "$GIT_REPO_PATH" - -if [ -d "$GIT_REPO_PATH" ]; then - git pull origin master -else - git clone "$GIT_REPO_URL" "$GIT_REPO_PATH" -fi +check_and_pull_git_repo commit_and_push_to_git diff --git a/docker-compose.yml b/docker-compose.yml index b7d106e..02ea0ad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,7 @@ services: - ./keys/rb5009:/keys/rb5009:ro # git - ./keys/git:/keys/git:ro + - # Add any other volumes or configurations needed