This commit is contained in:
Michael Grote 2023-07-21 20:40:39 +02:00
parent 8642843adb
commit b11eb60ac3
6 changed files with 111 additions and 3501 deletions

View file

@ -3,24 +3,20 @@ FROM ubuntu:latest
# deaktiviert Nachfragen beim installieren von Paketen
ENV DEBIAN_FRONTEND=noninteractive
# Install necessary packages
RUN apt-get update && \
apt-get -y --no-install-recommends install git python3 python3-pip && \
pip install --no-cache-dir paramiko gitpython && \
apt-get -y --no-install-recommends install git openssh-client && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /var/tmp/* /tmp/*
# Copy the script into the container
COPY app.py /app/app.py
COPY app.sh /app/app.sh
# Set the working directory
WORKDIR /app
# Make the script executable
RUN chmod +x app.py
RUN chmod +x app.sh
# Set the entrypoint to execute the script
ENTRYPOINT ["/app/app.py"]
# cron fehlt
ENTRYPOINT ["/app/app.sh"]

107
app.sh Normal file
View file

@ -0,0 +1,107 @@
#!/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
INTERVAL=3600 # in Sekunden
FAILFILE=$(mktemp)
while true ; do
# Healthcheck
echo "" > "$FAILFILE"
# Checks
if [ -z "$GIT_REPO_PATH" ] ; then
echo "GIT_REPO_PATH is not set."
exit 3
fi
if [ -z "$INTERVAL" ] ; then
echo "INTERVAL is not set."
exit 3
fi
if [ -z "$GIT_REPO_BRANCH" ] ; then
echo "GIT_REPO_BRANCH is not set."
exit 3
fi
if [ -z "$GIT_USERNAME" ] ; then
echo "GIT_USERNAME is not set."
exit 3
fi
if [ -z "$GIT_USER_MAIL" ] ; then
echo "GIT_USER_MAIL is not set."
exit 3
fi
if [ -z "$GIT_REPO_REMOTE_NAME" ] ; then
echo "GIT_REPO_REMOTE_NAME is not set."
exit 3
fi
if [ -z "$DEVICES" ] ; then
echo "DEVICES is not set."
exit 3
fi
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" --quiet
else
echo "Error: The directory exists but is not a Git repository"
exit 1
fi
else
git clone "$GIT_REPO_URL" "$GIT_REPO_PATH" --quiet
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 "Error: File $SSH_KEY_PATH does not exist"
echo "Error: can not export $FQDN config"
exit 2
fi
echo "export $FQDN config"
ssh -n -i "$SSH_KEY_PATH" "$FQDN" "/export show-sensitive" > "config_${FQDN}.rsc"
# entferne Datumszeile
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"
git add "config_${FQDN}.rsc"
git commit -m "update config_${FQDN}" --quiet
done <<< "$DEVICES"
git push
# Restore the original IFS value
IFS=$OLD_IFS
# loop
sleep "$INTERVAL"
done
# test mitvolume
# ohne volume wg git clone
# healtcheck mit letzue exit code
# beschrieben wie keys abgelegt werden müssen
# hadolint

File diff suppressed because it is too large Load diff

49
neu
View file

@ -1,49 +0,0 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAgEAph66MPxBFHM+pchivS2Eg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AAAADAQABAAACAQCmHrow/EEUcz6lyGK9LYSD4T/CGoj0OHXutzHWMH3jN779KW+bRS4HNQ+tYwGptxh/O8a+vhBRl+Tids9b5eAclOyJ0w76IR4ndW5xuIrer9h0wh1NT7Ljw/eEk4aTFMkGUv0R7ufuqnb2xdL8AbNUAZ7PUZqFIC6IEGfhrAxRT/tIoQ8U1JLkZaobfJygdGw8Gi79DNgowlb1RN7KzL3sMlY4g9FAHEszBfbfsfLnnvXWMvRX0B9lZQr1YOfy8TnUuJwRYuC2eM5Hgpe7iY02uieprZJJadW7ZmKmi0Ak6PqLDK4idcupUH9rKYwqdOHLezPU4WF3CVi6QZog0SxbXtYSOXj33kHwfNqtyXQ1Q/+ZC2lvvJ7I0JfOrEpemBNK5GPFMcIRsSEarSjGTeAki7879z1IfLe5zn6bfqC21A9A/GpEMfAmJLEVPWMs1UTsx6LnkH1rQVaEI+UaQm+9JpvwDQUXge7AH1TM8dsChxTQwzzJ6iuVOxUygizat4EdhQQtT7BVRzsf+kgw3rQK4Zzhe/C/340Es5aPDlFmiSaoC+bye02jbhUEGnoAwu3wNp9f2cgFiaGG1w/cp7rd7WeOc8EWdY0vytnAkK1SZp6HHpXozNz/jCocnFieS5sh/flLhizj/eHB9EFV6AQRssl0niQ//aaC6WnfVtnbiw== testschlüssel

87
x
View file

@ -1,87 +0,0 @@
#!/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
# Checks
if [ -z "$GIT_REPO_PATH" ] ; then
echo "GIT_REPO_PATH is not set."
exit 3
fi
if [ -z "$GIT_REPO_BRANCH" ] ; then
echo "GIT_REPO_BRANCH is not set."
exit 3
fi
if [ -z "$GIT_USERNAME" ] ; then
echo "GIT_USERNAME is not set."
exit 3
fi
if [ -z "$GIT_USER_MAIL" ] ; then
echo "GIT_USER_MAIL is not set."
exit 3
fi
if [ -z "$GIT_REPO_REMOTE_NAME" ] ; then
echo "GIT_REPO_REMOTE_NAME is not set."
exit 3
fi
if [ -z "$DEVICES" ] ; then
echo "DEVICES is not set."
exit 3
fi
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" --quiet
else
echo "Error: The directory exists but is not a Git repository"
exit 1
fi
else
git clone "$GIT_REPO_URL" "$GIT_REPO_PATH" --quiet
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 "Error: File $SSH_KEY_PATH does not exist"
echo "Error: can not export $FQDN config"
exit 2
fi
echo "export $FQDN config"
ssh -n -i "$SSH_KEY_PATH" "$FQDN" "/export show-sensitive" > "config_${FQDN}.rsc"
# entferne Datumszeile
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"
git add "config_${FQDN}.rsc"
git commit -m "update config_${FQDN}" --quiet
done <<< "$DEVICES"
git push
# Restore the original IFS value
IFS=$OLD_IFS
# test mitvolume
# ohne volume wg git clone
# healtcheck mit letzue exit code