Compare commits
7 Commits
843079774d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e2ca5c302 | ||
|
|
9ddea36088 | ||
|
|
f30b0ab8da | ||
| 626976b117 | |||
|
|
715788318c | ||
|
|
49f9ab3703 | ||
|
|
5b702be1d3 |
@@ -1,5 +1,5 @@
|
||||
# Variablen:
|
||||
# Typ: Variablen für Script weekly-update.v3.sh
|
||||
# Typ: Variablen für Script linux-updater.v3.sh
|
||||
# Git-Reposit.:
|
||||
# Version: 1.0
|
||||
# Datum: 13.04.2024
|
||||
9
.linux-updater.v4.env
Normal file
9
.linux-updater.v4.env
Normal file
@@ -0,0 +1,9 @@
|
||||
# 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
|
||||
16
README.md
16
README.md
@@ -12,9 +12,9 @@ Dieses Skript ist eine verbesserte Version eines wöchentlichen Update-Skripts f
|
||||
|
||||
## Verwendung
|
||||
|
||||
1. Klone das Repository: `git clone https://git.techniverse.net/scriptos/weekly-updater.git`
|
||||
2. Navigiere in das Verzeichnis: `cd weekly-updater`
|
||||
3. Führe das Skript aus: `bash weekly-update.v2.sh`
|
||||
1. Klone das Repository: `git clone https://git.techniverse.net/scriptos/linux-updater.git`
|
||||
2. Navigiere in das Verzeichnis: `cd linux-updater`
|
||||
3. Führe das Skript aus: `bash linux-updater.v3.sh`
|
||||
|
||||
## Beispiel Installation:
|
||||
|
||||
@@ -22,12 +22,12 @@ Dieses Skript ist eine verbesserte Version eines wöchentlichen Update-Skripts f
|
||||
# Script zum Updaten des Systems und CronJob erstellen
|
||||
mkdir -p /home/scripts/default
|
||||
mkdir -p /tmp/git
|
||||
git clone https://git.techniverse.net/scriptos/weekly-updater.git /tmp/git/weekly-updater
|
||||
cp /tmp/git/weekly-updater/weekly-update.v2.sh /home/scripts/default/weekly-update.v2.sh
|
||||
git clone https://git.techniverse.net/scriptos/linux-updater.git /tmp/git/linux-updater
|
||||
cp /tmp/git/linux-updater/weekly-update.v3.sh /home/scripts/default/weekly-update.v3.sh
|
||||
chmod 755 -R /home/scripts/default
|
||||
chmod +x /home/scripts/default/weekly-update.v2.sh
|
||||
cat <(crontab -l) <(echo "@weekly /home/scripts/default/weekly-update.v2.sh > /dev/null 2>&1") | crontab -
|
||||
rm -r /tmp/git/weekly-updater
|
||||
chmod +x /home/scripts/default/weekly-update.v3.sh
|
||||
cat <(crontab -l) <(echo "@weekly /home/scripts/default/weekly-update.v3.sh > /dev/null 2>&1") | crontab -
|
||||
rm -r /tmp/git/linux-updater
|
||||
```
|
||||
|
||||
## Lizenz
|
||||
|
||||
105
ansible-playbook/linux-updater.v4_script_verteilen.yml
Normal file
105
ansible-playbook/linux-updater.v4_script_verteilen.yml
Normal file
@@ -0,0 +1,105 @@
|
||||
---
|
||||
- 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
|
||||
2
cron/monthly_script_update
Normal file
2
cron/monthly_script_update
Normal file
@@ -0,0 +1,2 @@
|
||||
#Ansible: Monatliches Update Script
|
||||
0 0 1-7 * 0 root /home/scripts/default/linux-updater.v4.sh > /dev/null 2>&1
|
||||
@@ -1,17 +1,17 @@
|
||||
#!/bin/bash
|
||||
# Script Name: weekly-update.v2.sh
|
||||
# Script Name: linux-updater.v2.sh
|
||||
# Beschreibung: Wöchentliches Update-Skript für Linux-Systeme
|
||||
# Aufruf: bash ./weekly-update.v2.sh
|
||||
# Aufruf: bash ./linux-updater.v2.sh
|
||||
# Autor: Patrick Asmus
|
||||
# Web: https://www.techniverse.net
|
||||
# Git-Reposit.: https://git.techniverse.net/scriptos/weekly-updater.git
|
||||
# Git-Reposit.: https://git.techniverse.net/scriptos/linux-updater.git
|
||||
# Version: 2.2
|
||||
# Datum: 31.03.2024
|
||||
# Modifikation: Umstellung auf neue Domain
|
||||
# Datum: 25.11.2024
|
||||
# Modifikation: Wording geändert
|
||||
#####################################################
|
||||
|
||||
# Variablen
|
||||
SCRIPT_NAME=weekly-update.v2.sh
|
||||
SCRIPT_NAME=linux-updater.v2.sh
|
||||
HOSTNAME=$(hostname)
|
||||
MAIL=root
|
||||
LOGDIR=/var/log/script-logs
|
||||
@@ -1,20 +1,20 @@
|
||||
#!/bin/bash
|
||||
# Script Name: weekly-update.v3.sh
|
||||
# Script Name: linux-updater.v3.sh
|
||||
# Beschreibung: Wöchentliches Update-Skript für Linux-Systeme
|
||||
# Aufruf: bash ./weekly-update.v3.sh
|
||||
# Aufruf: bash ./linux-updater.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
|
||||
# Git-Reposit.: https://git.techniverse.net/scriptos/linux-updater.git
|
||||
# Version: 3.1
|
||||
# Datum: 24.11.2024
|
||||
# Modifikation: Wording geändert
|
||||
#####################################################
|
||||
|
||||
# Umgebungsvariablen
|
||||
source /root/.env/.weekly-update.v3.env
|
||||
source /root/.env/.linux-updater.v3.env
|
||||
|
||||
# Variablen
|
||||
SCRIPT_NAME=weekly-update.v3.sh
|
||||
SCRIPT_NAME=linux-updater.v3.sh
|
||||
HOSTNAME=$(hostname)
|
||||
MAIL=root
|
||||
LOGDIR=/var/log/script-logs
|
||||
95
linux-updater.v4.sh
Normal file
95
linux-updater.v4.sh
Normal file
@@ -0,0 +1,95 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user