#!/bin/bash
# Script to update all the honours stuff on a regular basis
+# Called by cron(8)
+# Sam Moore 2012
# Need to cd to the directory, otherwise nothing will work
directory="/home/sam/Documents/University/honours/"
cd "$directory"
-echo "Committing at $(date)" >> commits.log
-git add update.sh
-git add papers
-git add research
-git add thesis/proposal/*.tex
-git add thesis/proposal/*.pdf
-git add thesis/proposal/*.bib
-git add thesis/*.tex
-git add thesis/*.pdf
-git add thesis/*.bib
-git add course/semester2
+# Need to do this too. Apparently
+git="/usr/bin/git"
+eval $(ssh-agent) 2>/dev/null
+ssh-add /home/sam/.ssh/honours 2>/dev/null
+# This bit plots any open data files, so I can remotely view them
+gnuplot="/usr/bin/gnuplot"
+for data in $(lsof | grep interface | grep $(date +%Y) | awk '{print $NF}'); do
+ $gnuplot -e "set term png; set output \"$data.png\"; plot \"$data\" u 1:3 w lp title \"ADC4\", \"$data\" u 1:5 w lp title \"ADC5\""
+done
-git commit -m "Automatic commit at $(date)"
+$git pull # This is probably a good thing to do...
+
+$git add update.sh
+$git add papers
+$git add research
+$git add thesis/proposal/*.tex
+$git add thesis/proposal/*.pdf
+$git add thesis/proposal/*.bib
+$git add thesis/*.tex
+$git add thesis/*.pdf
+$git add thesis/*.bib
+$git add course/semester2
+
+# This sets a commit message and commits. Commit will only be done if there are changed files.
+fortune="/usr/games/fortune"
+message=$(echo "Automatic commit. $(date)"; echo ""; $fortune; echo "")
+$git commit -m "$message"
if [ "$?" == 0 ]; then
- git push git.ucc
+ echo "Commit at $(date)" >> commits.log
+ $git push git.ucc 2>&1 >> commits.log
fi
+
+kill -9 $SSH_AGENT_PID