sync: 2026-11-04 12:07
This commit is contained in:
1 parent
3825e60c1a
commit
009b8419db
1 file changed
+33
-11
@@ -1,35 +1,57 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Set PATH so cron can find git, date, ssh, etc.
|
# Set PATH so cron can find git, date, ssh, flock, etc.
|
||||||
export PATH="/usr/local/bin:/usr/bin:/bin"
|
export PATH="/usr/local/bin:/usr/bin:/bin"
|
||||||
|
|
||||||
# Explicitly set target directory (don't rely on $HOME in cron)
|
# Explicitly set target directory (don't rely on $HOME in cron)
|
||||||
TARGET_DIR="/home/benji/Documents/COURS"
|
TARGET_DIR="/home/benji/Documents/COURS"
|
||||||
|
|
||||||
|
# Éviter les exécutions concurrentes (cron simultanés ou exécution manuelle)
|
||||||
|
LOCKFILE="/tmp/cours_update.lock"
|
||||||
|
exec 200>"$LOCKFILE"
|
||||||
|
if ! flock -n 200; then
|
||||||
|
echo "Un autre processus de synchronisation est déjà en cours."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Navigate to target directory
|
# Navigate to target directory
|
||||||
cd "$TARGET_DIR" || {
|
cd "$TARGET_DIR" || {
|
||||||
echo "Directory not found"
|
echo "Directory not found: $TARGET_DIR"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# 1. Pull remote changes (repo principal + sous-modules)
|
# 1. Pull remote changes sur le repo principal COURS (Gitea Homelab)
|
||||||
git pull --rebase --autostash || {
|
git pull --rebase --autostash origin main || {
|
||||||
echo "Git pull failed on COURS"
|
echo "Git pull failed on COURS"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
git submodule update --remote --merge || {
|
|
||||||
echo "Git submodule update failed"
|
# S'assurer que le sous-module est initialisé
|
||||||
exit 1
|
git submodule update --init 2>/dev/null || true
|
||||||
}
|
|
||||||
|
|
||||||
# 2. Traitement du sous-module TP (Gitea IUT)
|
# 2. Traitement du sous-module TP (Gitea IUT)
|
||||||
if [ -d "DEV1.1/TP" ]; then
|
if [ -d "DEV1.1/TP" ]; then
|
||||||
cd DEV1.1/TP || return
|
cd DEV1.1/TP || {
|
||||||
|
echo "Impossible d'accéder au sous-module DEV1.1/TP"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# S'assurer d'être sur la branche main (éviter HEAD détachée)
|
||||||
|
CURRENT_BRANCH=$(git branch --show-current 2>/dev/null)
|
||||||
|
if [ "$CURRENT_BRANCH" != "main" ]; then
|
||||||
|
git checkout main 2>/dev/null || git checkout -B main origin/main 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Récupérer les changements distants du sous-module
|
||||||
|
git pull --rebase --autostash origin main || echo "Avertissement : Git pull a échoué sur le sous-module TP"
|
||||||
|
|
||||||
|
# Valider et pousser les modifications locales du sous-module
|
||||||
git add -A
|
git add -A
|
||||||
if ! git diff-index --quiet HEAD --; then
|
if ! git diff-index --quiet HEAD --; then
|
||||||
git commit -m "sync: $(date +'%Y-%m-%d %H:%M')"
|
git commit -m "sync: $(date +'%Y-%m-%d %H:%M')"
|
||||||
git push || echo "Avertissement : Git push à échoué sur le sous-module TP"
|
git push origin main || echo "Avertissement : Git push a échoué sur le sous-module TP"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "$TARGET_DIR" || exit 1
|
cd "$TARGET_DIR" || exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -38,7 +60,7 @@ git add -A
|
|||||||
|
|
||||||
if ! git diff-index --quiet HEAD --; then
|
if ! git diff-index --quiet HEAD --; then
|
||||||
git commit -m "sync: $(date +'%Y-%m-%d %H:%M')"
|
git commit -m "sync: $(date +'%Y-%m-%d %H:%M')"
|
||||||
git push || {
|
git push origin main || {
|
||||||
echo "Git push failed on COURS"
|
echo "Git push failed on COURS"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user