Files
cours/update.sh
T
2026-10-12 23:44:24 +02:00

48 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# Set PATH so cron can find git, date, ssh, etc.
export PATH="/usr/local/bin:/usr/bin:/bin"
# Explicitly set target directory (don't rely on $HOME in cron)
TARGET_DIR="/home/benji/Documents/COURS"
# Navigate to target directory
cd "$TARGET_DIR" || {
echo "Directory not found"
exit 1
}
# 1. Pull remote changes (repo principal + sous-modules)
git pull --rebase --autostash || {
echo "Git pull failed on COURS"
exit 1
}
git submodule update --remote --merge || {
echo "Git submodule update failed"
exit 1
}
# 2. Traitement du sous-module TP (Gitea IUT)
if [ -d "DEV1.1/TP" ]; then
cd DEV1.1/TP || return
git add -A
if ! git diff-index --quiet HEAD --; then
git commit -m "sync: $(date +'%Y-%m-%d %H:%M')"
git push || echo "Avertissement : Git push à échoué sur le sous-module TP"
fi
cd "$TARGET_DIR" || exit 1
fi
# 3. Traitement du dépôt principal COURS (Gitea Homelab)
git add -A
if ! git diff-index --quiet HEAD --; then
git commit -m "sync: $(date +'%Y-%m-%d %H:%M')"
git push || {
echo "Git push failed on COURS"
exit 1
}
else
echo "No changes to commit in COURS."
fi