Compare commits
No commits in common. "843079774d53651f098c23af9872f2956768a3c4" and "ddc61d59c5deeaa61c5d6f52725526b47dc783f2" have entirely different histories.
843079774d
...
ddc61d59c5
@ -1,10 +0,0 @@
|
|||||||
# Variablen:
|
|
||||||
# Typ: Variablen für Script weekly-update.v3.sh
|
|
||||||
# Git-Reposit.:
|
|
||||||
# Version: 1.0
|
|
||||||
# Datum: 13.04.2024
|
|
||||||
# Modifikation: Initial
|
|
||||||
#####################################################
|
|
||||||
|
|
||||||
WEBHOOK_URL_ENV=https://webhooks.techniverse.net/webhooks
|
|
||||||
API_KEY_ENV=123456
|
|
@ -1,78 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Update und Cronjob Setup für Linux Server
|
|
||||||
hosts: int_linux_servers:ext_linux_servers
|
|
||||||
# hosts: int_dev_linux_servers
|
|
||||||
become: yes
|
|
||||||
vars:
|
|
||||||
script_path: "/home/scripts/default/weekly-update.v3.sh"
|
|
||||||
env_path: "/root/.env/.weekly-update.v3.env"
|
|
||||||
script_src: "./files/weekly-update.v3.sh"
|
|
||||||
env_src: "./files/.weekly-update.v3.env"
|
|
||||||
old_scripts:
|
|
||||||
- "/home/scripts/default/weekly_update.sh"
|
|
||||||
- "/home/scripts/default/weekly-update.v3.sh"
|
|
||||||
- "/home/scripts/default/weekly-update-2.0.sh"
|
|
||||||
- "/home/scripts/default/weekly-update.v2.sh"
|
|
||||||
- "/root/.env/.weekly-update.v3.env"
|
|
||||||
old_env:
|
|
||||||
- "/root/.env/.weekly-update.v3.env"
|
|
||||||
cron_jobs:
|
|
||||||
- "@weekly bash /home/scripts/default/weekly-update.v3.sh > /dev/null 2>&1"
|
|
||||||
- "@weekly bash /home/scripts/default/weekly-update.v2.sh > /dev/null 2>&1"
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
- name: Lösche alte Skripte
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ item }}"
|
|
||||||
state: absent
|
|
||||||
with_items: "{{ old_scripts }}"
|
|
||||||
|
|
||||||
- name: Lösche alte .env
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ item }}"
|
|
||||||
state: absent
|
|
||||||
with_items: "{{ old_env }}"
|
|
||||||
|
|
||||||
- name: Entferne alte Cronjobs
|
|
||||||
ansible.builtin.cron:
|
|
||||||
name: "Entferne altes Cronjob - {{ item }}"
|
|
||||||
job: "{{ item }}"
|
|
||||||
state: absent
|
|
||||||
with_items: "{{ cron_jobs }}"
|
|
||||||
|
|
||||||
- name: Stelle sicher, dass das Skriptverzeichnis existiert
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "/home/scripts/default/"
|
|
||||||
state: directory
|
|
||||||
mode: '0711'
|
|
||||||
|
|
||||||
- name: Stelle sicher, dass das ENV Verzeichnis existiert
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "/root/.env/"
|
|
||||||
state: directory
|
|
||||||
mode: '0711'
|
|
||||||
|
|
||||||
- name: Verteile das neue Skript
|
|
||||||
ansible.builtin.copy:
|
|
||||||
src: "{{ script_src }}"
|
|
||||||
dest: "{{ script_path }}"
|
|
||||||
mode: '0711'
|
|
||||||
|
|
||||||
- name: Richte neuen Cronjob ein
|
|
||||||
ansible.builtin.cron:
|
|
||||||
name: "Wöchentliches Update Skript"
|
|
||||||
user: "{{ ansible_user | default('root') }}"
|
|
||||||
job: "bash {{ script_path }} > /dev/null 2>&1"
|
|
||||||
special_time: weekly
|
|
||||||
cron_file: weekly_script_update
|
|
||||||
|
|
||||||
- name: Verteile die .env Datei
|
|
||||||
ansible.builtin.copy:
|
|
||||||
src: "{{ env_src }}"
|
|
||||||
dest: "{{ env_path }}"
|
|
||||||
mode: '0711'
|
|
||||||
|
|
||||||
- name: Führe das Skript einmalig aus
|
|
||||||
ansible.builtin.shell: bash < /home/scripts/default/weekly-update.v3.sh
|
|
||||||
args:
|
|
||||||
executable: /bin/bash
|
|
@ -1,80 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# Script Name: weekly-update.v3.sh
|
|
||||||
# Beschreibung: Wöchentliches Update-Skript für Linux-Systeme
|
|
||||||
# Aufruf: bash ./weekly-update.v3.sh
|
|
||||||
# Autor: Patrick Asmus
|
|
||||||
# Web: https://www.techniverse.net
|
|
||||||
# Git-Reposit.: https://git.techniverse.net/scriptos/weekly-updater.git
|
|
||||||
# Version: 3.0
|
|
||||||
# Datum: 13.04.2024
|
|
||||||
# Modifikation: Version 3 released | Webhooks sind jetzt Bestandteil
|
|
||||||
#####################################################
|
|
||||||
|
|
||||||
# Umgebungsvariablen
|
|
||||||
source /root/.env/.weekly-update.v3.env
|
|
||||||
|
|
||||||
# Variablen
|
|
||||||
SCRIPT_NAME=weekly-update.v3.sh
|
|
||||||
HOSTNAME=$(hostname)
|
|
||||||
MAIL=root
|
|
||||||
LOGDIR=/var/log/script-logs
|
|
||||||
|
|
||||||
WEBHOOK_URL=$WEBHOOK_URL_ENV
|
|
||||||
API_KEY=$API_KEY_ENV
|
|
||||||
|
|
||||||
# Logging aktivieren
|
|
||||||
mkdir -p $LOGDIR
|
|
||||||
exec &> >(tee -a "$LOGDIR/$SCRIPT_NAME.log")
|
|
||||||
|
|
||||||
# Aktualisiere das System
|
|
||||||
sudo apt update && sudo apt upgrade -y
|
|
||||||
|
|
||||||
# Überprüfe, ob das Update erfolgreich war
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
# Räume das System auf
|
|
||||||
sudo apt-get autoremove --purge -y
|
|
||||||
sudo apt-get clean -y
|
|
||||||
|
|
||||||
# Bereinige Log-Dateien, die älter als 60 Tage sind
|
|
||||||
find /var/log -type f -name "*.log" -mtime +60 -exec rm {} \;
|
|
||||||
|
|
||||||
# Bereinige den APT-Cache
|
|
||||||
sudo apt-get clean
|
|
||||||
|
|
||||||
# Bereinige den Paket-Cache von alten Paketen
|
|
||||||
sudo apt-get autoclean
|
|
||||||
|
|
||||||
# Entferne ungenutzte Abhängigkeiten
|
|
||||||
sudo apt-get autoremove --purge
|
|
||||||
|
|
||||||
# Bereinige die Homeverzeichnisse der Benutzer
|
|
||||||
find /home -type f \( -name "*.bak" -o -name "*.tmp" -o -name "*.swp" \) -delete
|
|
||||||
|
|
||||||
# Leere den Trash-Ordner des Root-Benutzers
|
|
||||||
sudo rm -rf /root/.local/share/Trash/*
|
|
||||||
|
|
||||||
# Leere den Trash-Ordner der Benutzer, falls vorhanden
|
|
||||||
for user in /home/*; do
|
|
||||||
if [ -d "$user/.local/share/Trash" ]; then
|
|
||||||
sudo rm -rf "$user/.local/share/Trash/*"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Leere das temporäre Verzeichnis
|
|
||||||
sudo rm -rf /tmp/*
|
|
||||||
|
|
||||||
# Sende Benachrichtigung über Webhook
|
|
||||||
curl -d "{\"body\": \"$HOSTNAME: Das wöchentliche Update wurde erfolgreich durchgeführt.\", \"key\": \"$API_KEY\"}" \
|
|
||||||
"$WEBHOOK_URL"
|
|
||||||
|
|
||||||
else
|
|
||||||
# Sende eine E-Mail, wenn das Update fehlgeschlagen ist
|
|
||||||
log_contents=$(cat $LOGDIR/$SCRIPT_NAME.log)
|
|
||||||
echo -e "Das Update auf $HOSTNAME ist fehlgeschlagen! \n\nLog-Inhalt: \n\n$log_contents" | mail -s "Wöchentliches Update auf $HOSTNAME fehlgeschlagen" $MAIL
|
|
||||||
|
|
||||||
# Sende Benachrichtigung über Webhook
|
|
||||||
curl -d "{\"body\": \"$HOSTNAME: Das wöchentliche Update ist fehlgeschlagen.\", \"key\": \"$API_KEY\"}" \
|
|
||||||
"$WEBHOOK_URL"
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
|
@ -1,18 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#Weekly Update
|
|
||||||
function update_and_clean {
|
|
||||||
apt update
|
|
||||||
apt full-upgrade -y
|
|
||||||
apt autoclean -y
|
|
||||||
apt autoremove -y
|
|
||||||
}
|
|
||||||
#START
|
|
||||||
wget --user download --password download https://pv1.media-techport.de/repos/ubuntu20.04-sources.list
|
|
||||||
mv /root/ubuntu20.04-sources.list /root/sources.list
|
|
||||||
cp /etc/apt/sources.list /etc/apt/sources.list.orig
|
|
||||||
mv /root/sources.list /etc/apt/sources.list
|
|
||||||
sudo rm -rf /var/lib/apt/lists/*
|
|
||||||
apt clean
|
|
||||||
update_and_clean
|
|
||||||
cat /dev/null > ~/.bash_history && history -c && history -w
|
|
||||||
exit 0
|
|
Loading…
Reference in New Issue
Block a user