2023-07-21 18:40:45 +02:00
|
|
|
#!/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
|
2023-07-21 18:40:45 +02:00
|
|
|
hex.grote.lan,/ssh/keys/hex"
|
2023-07-21 18:48:12 +02:00
|
|
|
|
2023-07-21 18:56:29 +02:00
|
|
|
|
|
|
|
GIT_REPO_PATH=/home/mg/oxidized-selfmade # wo soll das Repo angelegt werden
|
2023-07-21 18:46:16 +02:00
|
|
|
GIT_REPO_BRANCH=master
|
2023-07-21 18:56:29 +02:00
|
|
|
GIT_USERNAME=oxidized-selfmade
|
2023-07-21 18:48:12 +02:00
|
|
|
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:05:23 +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:05:23 +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:05:23 +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:05:23 +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:05:23 +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:05:23 +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"
|
|
|
|
|
2023-07-21 19:04:24 +02:00
|
|
|
if [ -d "$GIT_REPO_PATH" ] ; then
|
2023-07-21 18:56:29 +02:00
|
|
|
cd "$GIT_REPO_PATH"
|
2023-07-21 19:04:24 +02:00
|
|
|
if [ -d ".git" ] ; then
|
2023-07-21 20:28:42 +02:00
|
|
|
git pull "$GIT_REPO_REMOTE_NAME" "$GIT_REPO_BRANCH" --quiet
|
2023-07-21 18:56:29 +02:00
|
|
|
else
|
2023-07-21 19:19:59 +02:00
|
|
|
echo "Error: The directory exists but is not a Git repository"
|
2023-07-21 18:56:29 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
2023-07-21 20:28:42 +02:00
|
|
|
git clone "$GIT_REPO_URL" "$GIT_REPO_PATH" --quiet
|
2023-07-21 18:56:29 +02:00
|
|
|
fi
|
2023-07-21 18:40:45 +02:00
|
|
|
|
|
|
|
# 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 19:04:24 +02:00
|
|
|
if [ ! -e "$SSH_KEY_PATH" ] ; then
|
2023-07-21 19:19:59 +02:00
|
|
|
echo "Error: File $SSH_KEY_PATH does not exist"
|
|
|
|
echo "Error: can not export $FQDN config"
|
2023-07-21 18:56:29 +02:00
|
|
|
exit 2
|
|
|
|
fi
|
2023-07-21 20:26:53 +02:00
|
|
|
echo "export $FQDN config"
|
2023-07-21 18:57:50 +02:00
|
|
|
ssh -n -i "$SSH_KEY_PATH" "$FQDN" "/export show-sensitive" > "config_${FQDN}.rsc"
|
2023-07-21 19:19:59 +02:00
|
|
|
# entferne Datumszeile
|
2023-07-21 20:26:53 +02:00
|
|
|
sed -i -r '/^# [0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}\:[0-9]{2}\:[0-9]{2}\sby\sRouterOS\s[0-9\s\.]+/d' "config_${FQDN}.rsc"
|
2023-07-21 20:28:42 +02:00
|
|
|
git add "config_${FQDN}.rsc"
|
2023-07-21 20:27:22 +02:00
|
|
|
git commit -m "update config_${FQDN}" --quiet
|
2023-07-21 18:58:43 +02:00
|
|
|
done <<< "$DEVICES"
|
2023-07-21 18:40:45 +02:00
|
|
|
|
2023-07-21 18:46:16 +02:00
|
|
|
git push
|
|
|
|
|
2023-07-21 18:40:45 +02:00
|
|
|
# Restore the original IFS value
|
|
|
|
IFS=$OLD_IFS
|
|
|
|
|
2023-07-21 18:56:29 +02:00
|
|
|
|
|
|
|
# test mitvolume
|
|
|
|
# ohne volume wg git clone
|