hook
This commit is contained in:
24
servers/linux/.gitea/workflows/generate-hash.yaml
Normal file
24
servers/linux/.gitea/workflows/generate-hash.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
name: Generate SHA256 Hashes
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
hash:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Generate Hashes
|
||||
run: |
|
||||
# On boucle sur tous les fichiers .sh dans le dossier spécifique
|
||||
cd servers/linux/
|
||||
for file in *.sh; do
|
||||
sha256sum "$file" > "${file}.sha256"
|
||||
done
|
||||
|
||||
- name: Commit and Push
|
||||
run: |
|
||||
git config --global user.name "Gitea Action"
|
||||
git config --global user.email "actions@noreply.gitea.io"
|
||||
git add servers/linux/*.sha256
|
||||
git diff --quiet && git diff --staged --quiet || git commit -m "Auto-update SHA256 hashes"
|
||||
git push
|
||||
@@ -7,6 +7,8 @@ PROC_THRESHOLD=500
|
||||
TMP_THRESHOLD=90
|
||||
CONN_THRESHOLD=500
|
||||
HOST=$(hostname)
|
||||
SCRIPT_PATH="$0"
|
||||
SCRIPT_NAME=$(basename "$SCRIPT_PATH")
|
||||
|
||||
# On envoie à 'root', le système fera la redirection grâce aux aliases
|
||||
DEST="root"
|
||||
@@ -22,6 +24,55 @@ add_to_report() {
|
||||
|
||||
|
||||
|
||||
# --- Configuration de l'auto-update ---
|
||||
|
||||
BASE_URL="https://git.abonnel.fr/cedricAbonnel/scripts-bash/raw/branch/main/servers/linux"
|
||||
URL_SCRIPT="${BASE_URL}/${SCRIPT_NAME}"
|
||||
URL_HASH="${URL_SCRIPT}.sha256" # On suppose qu'un fichier .sha256 existe
|
||||
TMP_FILE="/tmp/${SCRIPT_NAME}.new"
|
||||
|
||||
# --- Fonction de mise à jour ---
|
||||
update_script() {
|
||||
# 1. Récupérer le hash distant avec timeout
|
||||
REMOTE_HASH=$(curl -s -f --connect-timeout 3 --max-time 5 "$URL_HASH" | awk '{print $1}')
|
||||
|
||||
# Si on n'arrive pas à lire le hash distant, on ignore l'update
|
||||
[[ -z "$REMOTE_HASH" ]] && return 1
|
||||
|
||||
# 2. Calculer le hash local
|
||||
LOCAL_HASH=$(sha256sum "$SCRIPT_PATH" | awk '{print $1}')
|
||||
|
||||
# 3. Comparaison
|
||||
if [ "$LOCAL_HASH" != "$REMOTE_HASH" ]; then
|
||||
echo "[Update] Nouvelle version détectée..."
|
||||
|
||||
# 4. Téléchargement du nouveau script
|
||||
if curl -s -f --connect-timeout 5 --max-time 10 "$URL_SCRIPT" -o "$TMP_FILE"; then
|
||||
|
||||
# 5. Vérification du hash du fichier téléchargé (Sécurité)
|
||||
DOWNLOADED_HASH=$(sha256sum "$TMP_FILE" | awk '{print $1}')
|
||||
|
||||
if [ "$DOWNLOADED_HASH" == "$REMOTE_HASH" ]; then
|
||||
mv "$TMP_FILE" "$SCRIPT_PATH"
|
||||
chmod +x "$SCRIPT_PATH"
|
||||
echo "[Update] Mise à jour appliquée. Relance..."
|
||||
exec "$SCRIPT_PATH" "$@"
|
||||
else
|
||||
echo "[Error] Hash corrompu après téléchargement."
|
||||
rm -f "$TMP_FILE"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Lancer la vérification
|
||||
update_script "$@"
|
||||
|
||||
# --- Reste du script ---
|
||||
echo "Exécution du script principal..."
|
||||
|
||||
|
||||
|
||||
# 1. CHECK DISQUE & INODES
|
||||
DISK_USAGE=$(df / | awk 'NR==2 {print $5}' | sed 's/%//')
|
||||
INODE_USAGE=$(df -i / | awk 'NR==2 {print $5}' | sed 's/%//')
|
||||
@@ -106,7 +157,7 @@ fi
|
||||
# ------------------------------------------------
|
||||
# On récupère les données, puis on exclut les processus du script lui-même
|
||||
# On exclut aussi souvent 'systemd-j' (journal) car il gère ses propres rotations
|
||||
DELETED_DATA=$(sudo lsof +L1 2>/dev/null | tail -n +2 | grep -Ev "lsof|tail|cron|sh|systemd-j|sys_check")
|
||||
DELETED_DATA=$(sudo lsof +L1 2>/dev/null | tail -n +2 | grep -Ev "grep|lsof|tail|cron|sh|systemd-j|sys_check")
|
||||
|
||||
# On compte proprement les lignes
|
||||
DELETED_COUNT=$(echo "$DELETED_DATA" | grep -v '^$' | wc -l)
|
||||
|
||||
Reference in New Issue
Block a user