Add 'git_auto_save.sh'
This commit is contained in:
parent
ce3d26c7e6
commit
1d169e7eb5
34
git_auto_save.sh
Normal file
34
git_auto_save.sh
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#!/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
|
Loading…
Reference in New Issue
Block a user