34 lines
685 B
Bash
34 lines
685 B
Bash
#!/bin/bash
|
|
|
|
echo 'Auto Syncing'
|
|
|
|
while true
|
|
do
|
|
# check every 30s
|
|
sleep 30
|
|
|
|
# sync only 5min after last modifiication to avoid too many temperaty updates
|
|
last_modified=`find ./ -type f -exec stat \{} --printf="%Y\n" \; | sort -n -r | head -n 1`
|
|
current=`date +%s`
|
|
if (( ${current} - ${last_modified} < 300 )); then
|
|
continue
|
|
fi
|
|
|
|
# commit changes -> pull rebase -> push to remote
|
|
no_output=`git diff-index --quiet HEAD --`
|
|
is_dirty=$?
|
|
|
|
if [ -n "$(git status --porcelain)" ]; then
|
|
is_dirty=1
|
|
fi
|
|
|
|
if test "$is_dirty" = 0; then
|
|
continue
|
|
fi
|
|
|
|
git add . -A
|
|
git commit -am "Auto update by $(whoami)"
|
|
git pull --rebase
|
|
git push origin master
|
|
|
|
done |