51 lines
1.2 KiB
Bash
Executable File
51 lines
1.2 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"
|
|
|
|
# SSH key pour Git (appliquée à la fois à Homelab et IUT)
|
|
export GIT_SSH_COMMAND="ssh -i /home/benji/.ssh/git -o IdentitiesOnly=yes"
|
|
|
|
# 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
|
|
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
|