Compare commits
	
		
			No commits in common. "main" and "wording" have entirely different histories.
		
	
	
		
	
		
@ -1,5 +1,5 @@
 | 
			
		||||
# Variablen:
 | 
			
		||||
# Typ:          Variablen für Script linux-updater.v3.sh
 | 
			
		||||
# Typ:          Variablen für Script linux-updater.v2.sh
 | 
			
		||||
# Git-Reposit.: 
 | 
			
		||||
# Version:      1.0
 | 
			
		||||
# Datum:        13.04.2024
 | 
			
		||||
 | 
			
		||||
@ -1,9 +0,0 @@
 | 
			
		||||
# Variablen:
 | 
			
		||||
# Typ:          Variablen für Script linux-updater.v4.sh
 | 
			
		||||
# Git-Reposit.: 
 | 
			
		||||
# Version:      1.0
 | 
			
		||||
# Datum:        25.11.2024
 | 
			
		||||
# Modifikation: Initial
 | 
			
		||||
#####################################################
 | 
			
		||||
 | 
			
		||||
NTFY_URL_ENV=https://ntfy.sh/topic
 | 
			
		||||
@ -1,105 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
- name: Update und Cronjob Setup für Linux Server (version 4)
 | 
			
		||||
  hosts: int_linux_servers:ext_linux_servers:int_linux_pbs
 | 
			
		||||
#  hosts: linux-testen
 | 
			
		||||
  become: yes
 | 
			
		||||
  vars:
 | 
			
		||||
    script_path: "/home/scripts/default/linux-updater.v4.sh"
 | 
			
		||||
    env_path: "/root/.env/.linux-updater.v4.env"
 | 
			
		||||
    script_src: "./files/linux-updater.v4.sh"
 | 
			
		||||
    env_src: "./files/.linux-updater.v4.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"
 | 
			
		||||
      - "/home/scripts/default/linux-updater.v4.sh"
 | 
			
		||||
    old_env:
 | 
			
		||||
      - "/root/.env/.weekly-update.v3.env"
 | 
			
		||||
      - "/root/.env/.linux-updater.v4.env"
 | 
			
		||||
      - "/root/.env/.linux-update.v4.env"
 | 
			
		||||
    cron_jobs_legacy:
 | 
			
		||||
      - "@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"
 | 
			
		||||
    cron_jobs:
 | 
			
		||||
      - "Monatliches Update Script"
 | 
			
		||||
      - "Woechentliches Weekly-Update Skript v2"
 | 
			
		||||
      - "Wöchentliches Weekly-Update Skript v2"
 | 
			
		||||
      - "Wöchentliches Update Skript"
 | 
			
		||||
 | 
			
		||||
  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 (legacy)
 | 
			
		||||
      ansible.builtin.cron:
 | 
			
		||||
        name: "Entferne altes Cronjob - {{ item }}"
 | 
			
		||||
        job: "{{ item }}"
 | 
			
		||||
        state: absent
 | 
			
		||||
      with_items: "{{ cron_jobs_legacy }}"
 | 
			
		||||
 | 
			
		||||
    - name: Entferne alte Cronjobs (persoenlich)
 | 
			
		||||
      cron:
 | 
			
		||||
        name: "{{ item }}"
 | 
			
		||||
        user: "{{ ansible_user | default('root') }}"
 | 
			
		||||
        state: absent
 | 
			
		||||
      loop: "{{ cron_jobs }}"
 | 
			
		||||
 | 
			
		||||
    - name: Entferne alte Cronjobs (cron_file)
 | 
			
		||||
      cron:
 | 
			
		||||
        name: "{{ item }}"
 | 
			
		||||
        user: "{{ ansible_user | default('root') }}"
 | 
			
		||||
        state: absent
 | 
			
		||||
        cron_file: "monthly_script_update"
 | 
			
		||||
      loop: "{{ 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: "Monatliches Update Script"
 | 
			
		||||
        user: "{{ ansible_user | default('root') }}"
 | 
			
		||||
        job: "/home/scripts/default/linux-updater.v4.sh > /dev/null 2>&1"
 | 
			
		||||
        minute: "0"
 | 
			
		||||
        hour: "0"
 | 
			
		||||
        day: "1-7"
 | 
			
		||||
        weekday: "0"
 | 
			
		||||
        month: "*"
 | 
			
		||||
        cron_file: "monthly_script_update"
 | 
			
		||||
        state: "present"
 | 
			
		||||
 | 
			
		||||
    - 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/linux-updater.v4.sh
 | 
			
		||||
      args:
 | 
			
		||||
        executable: /bin/bash
 | 
			
		||||
@ -1,2 +0,0 @@
 | 
			
		||||
#Ansible: Monatliches Update Script
 | 
			
		||||
0 0 1-7 * 0 root /home/scripts/default/linux-updater.v4.sh > /dev/null 2>&1
 | 
			
		||||
@ -4,7 +4,7 @@
 | 
			
		||||
# Aufruf:       bash ./linux-updater.v2.sh
 | 
			
		||||
# Autor:        Patrick Asmus
 | 
			
		||||
# Web:          https://www.techniverse.net
 | 
			
		||||
# Git-Reposit.: https://git.techniverse.net/scriptos/linux-updater.git
 | 
			
		||||
# Git-Reposit.: https://git.techniverse.net/scriptos/weekly-updater.git
 | 
			
		||||
# Version:      2.2
 | 
			
		||||
# Datum:        25.11.2024
 | 
			
		||||
# Modifikation: Wording geändert
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,7 @@
 | 
			
		||||
# Aufruf:       bash ./linux-updater.v3.sh
 | 
			
		||||
# Autor:        Patrick Asmus
 | 
			
		||||
# Web:          https://www.techniverse.net
 | 
			
		||||
# Git-Reposit.: https://git.techniverse.net/scriptos/linux-updater.git
 | 
			
		||||
# Git-Reposit.: https://git.techniverse.net/scriptos/weekly-updater.git
 | 
			
		||||
# Version:      3.1
 | 
			
		||||
# Datum:        24.11.2024
 | 
			
		||||
# Modifikation: Wording geändert
 | 
			
		||||
 | 
			
		||||
@ -1,95 +0,0 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
# Script Name:  linux-updater.v4.sh
 | 
			
		||||
# Beschreibung: Wöchentliches Update-Skript für Linux-Systeme
 | 
			
		||||
# Aufruf:       bash ./linux-updater.v4.sh
 | 
			
		||||
# Autor:        Patrick Asmus
 | 
			
		||||
# Web:          https://www.techniverse.net
 | 
			
		||||
# Git-Reposit.: https://git.techniverse.net/scriptos/linux-updater.git
 | 
			
		||||
# Version:      4.0
 | 
			
		||||
# Datum:        25.11.2024
 | 
			
		||||
# Modifikation: Integration von Ntfy für Benachrichtigungen
 | 
			
		||||
#####################################################
 | 
			
		||||
 | 
			
		||||
# Umgebungsvariablen
 | 
			
		||||
source /root/.env/.linux-updater.v4.env
 | 
			
		||||
 | 
			
		||||
# Variablen
 | 
			
		||||
SCRIPT_NAME=linux-updater.v4.sh
 | 
			
		||||
HOSTNAME=$(hostname)
 | 
			
		||||
MAIL=root
 | 
			
		||||
LOGDIR=/var/log/script-logs
 | 
			
		||||
 | 
			
		||||
# Benachrichtigungseinstellungen
 | 
			
		||||
NOTIFY_SUCCESS=0
 | 
			
		||||
NOTIFY_FAILURE=1
 | 
			
		||||
 | 
			
		||||
NTFY_URL=$NTFY_URL_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 "*.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 Ntfy, wenn Update erfolgreich
 | 
			
		||||
    if [ "$NOTIFY_SUCCESS" -eq 1 ]; then
 | 
			
		||||
        curl -H "Title: Update erfolgreich" \
 | 
			
		||||
             -H "Priority: min" \
 | 
			
		||||
             -H "Tags: white_check_mark,partying_face" \
 | 
			
		||||
             -H "Attach: https://assets.techniverse.net/f1/scripts/happy_meme.jpg" \
 | 
			
		||||
             -d "Das Update auf Server '$HOSTNAME' wurde erfolgreich abgeschlossen." \
 | 
			
		||||
             "$NTFY_URL"
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
else
 | 
			
		||||
    # Sende E-Mail, wenn Update fehlgeschlagen
 | 
			
		||||
    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 Ntfy, wenn Update fehlgeschlagen
 | 
			
		||||
    if [ "$NOTIFY_FAILURE" -eq 1 ]; then
 | 
			
		||||
        curl -H "Title: Update fehlgeschlagen" \
 | 
			
		||||
             -H "Priority: high" \
 | 
			
		||||
             -H "Tags: warning,skull" \
 | 
			
		||||
             -H "Attach: https://assets.techniverse.net/f1/scripts/fire_meme.jpg" \
 | 
			
		||||
             -d "Das Update auf Server '$HOSTNAME' ist fehlgeschlagen." \
 | 
			
		||||
             "$NTFY_URL"
 | 
			
		||||
    fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
exit 0
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user