Files
cours/update.sh
T
2026-09-28 19:23:30 +02:00

34 lines
685 B
Bash
Executable File

#!/bin/sh
# Set PATH so cron can find git, date, ssh, etc.
export PATH="/usr/local/bin:/usr/bin:/bin:$PATH"
# 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
}
# Pull remote changes rebase-style
git pull --rebase --autostash || {
echo "Git pull failed"
exit 1
}
# Stage all files
git add -A
# Commit only if there are actual changes staged
if ! git diff-index --quiet HEAD --; then
git commit -m "sync: $(date +'%Y-%m-%d %H:%M')"
git push || {
echo "Git push failed"
exit 1
}
else
echo "No changes to commit."
fi