routeros-config-export/x

83 lines
1.8 KiB
Text
Raw Normal View History

#!/bin/bash
# setze Variable
2023-07-21 18:57:50 +02:00
# Format <FQDN>,<SSH_KEY_PATH to ssh-private-key(passwordless)>
2023-07-21 18:58:43 +02:00
DEVICES="rb5009.grote.lan,/home/mg/oxidized-selfmade/neu
hex.grote.lan,/ssh/keys/hex"
2023-07-21 18:56:29 +02:00
GIT_REPO_PATH=/home/mg/oxidized-selfmade # wo soll das Repo angelegt werden
GIT_REPO_BRANCH=master
2023-07-21 18:56:29 +02:00
GIT_USERNAME=oxidized-selfmade
GIT_USER_MAIL=michael.grote@posteo.de
2023-07-21 18:56:29 +02:00
GIT_REPO_REMOTE_NAME=origin
2023-07-21 19:02:05 +02:00
# Checks
2023-07-21 19:03:02 +02:00
if [ -z $GIT_REPO_PATH ]; then
2023-07-21 19:02:05 +02:00
echo "GIT_REPO_PATH is not set."
exit 3
fi
2023-07-21 19:03:02 +02:00
if [ -z $GIT_REPO_BRANCH ]; then
2023-07-21 19:02:05 +02:00
echo "GIT_REPO_BRANCH is not set."
exit 3
fi
2023-07-21 19:03:02 +02:00
if [ -z $GIT_USERNAME ]; then
2023-07-21 19:02:05 +02:00
echo "GIT_USERNAME is not set."
exit 3
fi
2023-07-21 19:03:02 +02:00
if [ -z $GIT_USER_MAIL ]; then
2023-07-21 19:02:05 +02:00
echo "GIT_USER_MAIL is not set."
exit 3
fi
2023-07-21 19:03:02 +02:00
if [ -z $GIT_REPO_REMOTE_NAME ]; then
2023-07-21 19:02:05 +02:00
echo "GIT_REPO_REMOTE_NAME is not set."
exit 3
fi
2023-07-21 19:03:02 +02:00
if [ -z $DEVICES ]; then
2023-07-21 19:02:05 +02:00
echo "DEVICES is not set."
exit 3
fi
2023-07-21 18:56:29 +02:00
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=','
2023-07-21 18:57:50 +02:00
while read -r FQDN SSH_KEY_PATH; do
2023-07-21 18:56:29 +02:00
# bereinige FQDN
2023-07-21 18:57:50 +02:00
FQDN=$(echo "$FQDN" | tr -d "[:space:]")
2023-07-21 18:56:29 +02:00
# prüfe ob Key existiert
2023-07-21 18:57:50 +02:00
if [ ! -e "$SSH_KEY_PATH" ]; then
2023-07-21 18:58:25 +02:00
echo "File $SSH_KEY_PATH does not exist."
2023-07-21 18:56:29 +02:00
exit 2
fi
2023-07-21 18:57:50 +02:00
ssh -n -i "$SSH_KEY_PATH" "$FQDN" "/export show-sensitive" > "config_${FQDN}.rsc"
git add "config_${FQDN}.rsc"
git commit -m "update config_${FQDN}"
2023-07-21 18:58:43 +02:00
done <<< "$DEVICES"
git push
# Restore the original IFS value
IFS=$OLD_IFS
2023-07-21 18:56:29 +02:00
# test mitvolume
# ohne volume wg git clone