ceck clone

This commit is contained in:
Michael Grote 2023-07-19 21:41:48 +02:00
parent 3e3df9f015
commit 41d82dc21d
3 changed files with 21 additions and 8 deletions

View File

@ -14,3 +14,5 @@ RUN chmod +x app.sh
# Set the entrypoint to execute the script
ENTRYPOINT ["/app/app.sh"]
# cron fehlt

26
app.sh
View File

@ -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

View File

@ -13,6 +13,7 @@ services:
- ./keys/rb5009:/keys/rb5009:ro
# git
- ./keys/git:/keys/git:ro
-
# Add any other volumes or configurations needed