routeros-config-export/x
2023-07-21 18:58:25 +02:00

57 lines
1.4 KiB
Bash

#!/bin/bash
# setze Variable
# Format <FQDN>,<SSH_KEY_PATH to ssh-private-key(passwordless)>
devices="rb5009.grote.lan,/home/mg/oxidized-selfmade/neu
hex.grote.lan,/ssh/keys/hex"
GIT_REPO_PATH=/home/mg/oxidized-selfmade # wo soll das Repo angelegt werden
GIT_REPO_BRANCH=master
GIT_USERNAME=oxidized-selfmade
GIT_USER_MAIL=michael.grote@posteo.de
GIT_REPO_REMOTE_NAME=origin
git config --global user.email "$GIT_USER_MAIL"
git config --global user.name "$GIT_USERNAME"
if [ -d "$GIT_REPO_PATH" ]; then
cd "$GIT_REPO_PATH"
if [ -d ".git" ]; then
git pull "$GIT_REPO_REMOTE_NAME" "$GIT_REPO_BRANCH"
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
# Save the current value of IFS to restore later
OLD_IFS=$IFS
# Set the IFS to a comma to split the values
IFS=','
while read -r FQDN SSH_KEY_PATH; do
# bereinige FQDN
FQDN=$(echo "$FQDN" | tr -d "[:space:]")
# prüfe ob Key existiert
if [ ! -e "$SSH_KEY_PATH" ]; then
echo "File $SSH_KEY_PATH does not exist."
exit 2
fi
ssh -n -i "$SSH_KEY_PATH" "$FQDN" "/export show-sensitive" > "config_${FQDN}.rsc"
git add "config_${FQDN}.rsc"
git commit -m "update config_${FQDN}"
done <<< "$devices"
git push
# Restore the original IFS value
IFS=$OLD_IFS
# test mitvolume
# ohne volume wg git clone