2 # Autocommit script - pushes your todo file to a git repository and pulls any
5 # Add it to cron to run every minute (or 5 minutes if desired)
10 [[ -f $MYDIR/autocommit.cfg ]] && . $MYDIR/autocommit.cfg
13 if [[ "$1" == "-x" ]]; then
20 if [[ "$DEBUG" == "yes" ]]; then
28 PINGCMD="ping -q -n -W 1 -c 1 $PINGHOST"
32 debugmsg "==================================================================="
33 debugmsg "Running $0 - `date`"
34 debugmsg "==================================================================="
37 debugmsg "Currtime: $CURRTIME"
41 MODTIME=`stat -c %Y $f`
42 debugmsg -n " $f - $MODTIME - "
43 # If the file wasn't modified in the last $SECONDS seconds, then add it to
45 if [[ "($CURRTIME - $SECONDS)" -gt "$MODTIME" ]]; then
47 $GIT add $f > /dev/null
49 debugmsg "not adding: recently modified"
54 debugmsg -n "Testing for network connectivity - "
55 if $PINGCMD > /dev/null 2>&1; then
63 debugmsg "Not testing for network connectivity - assuming it is up"
67 if $GIT status > /dev/null; then
68 debugmsg "We have changed files - committing"
69 $GIT commit -m "$MESSAGE" >> $LOGFILE
72 if [[ "$PUSH" == "yes" ]]; then
73 debugmsg -n "Try to push - "
74 if [[ "$NETWORKUP" == "yes" ]]; then
75 if ! $GIT diff --quiet $BRANCH..$REMOTE/$BRANCH; then
77 $GIT push --porcelain $REMOTE $BRANCH >> $LOGFILE 2>&1
79 debugmsg "Nothing to push"
82 debugmsg "Network down"
86 if [[ "$PULL" == "yes" ]]; then
87 debugmsg -n "Try to pull - "
88 if [[ "$NETWORKUP" == "yes" ]]; then
90 $GIT pull $REMOTE $BRANCH >> $LOGFILE 2>&1
92 debugmsg "Network down"