Automatically Commit Files with Script
Problem
While having backups are important, the problem that I had was that I would not remember to do the backups on a regular basis.
The Christmas light show has lots of files that are used for it. Those that have owned a Raspberry Pi, know that the SD card can easily become corrupted or unusable due to power outage or other reason. I have seen several posts in the Xlights Facebook group and the Falcon Pi Player Facebook group about people trying to figure out how they can get the files off the corrupt SD card and onto their new SD card.
Solution
One thing that I have learned when it comes to IT support and working in tech is that if you can come up with a proactive strategy for dealing with something instead of a reactive strategy, you will be better off and have less of a headache when it is done.
The Script
#!/bin/bash
###############################################################################
# Author: Kenny Robinson, @almostengr
# Description: Script to automatically commit the updates to the files and
# the push them to remote repository.
###############################################################################
/bin/date
if [ "${1}" == "" ]
then
exit 1;
fi
cd ${1}
OUTPUT=$(/usr/bin/git status)
ROWCOUNT=$(echo ${OUTPUT} | /bin/grep -i "nothing to commit, working tree clean" | wc -l)
if [ ${ROWCOUNT} -eq 0 ]
then
/usr/bin/git add .
/usr/bin/git commit -m 'Commiting new files'
/usr/bin/git fetch -p
/usr/bin/git push
fi
/bin/date