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