#!/bin/sh # # simple script to call the 'vlanscrape' script, check if there are changes # in the output directory, and `git add . ; git commit -m "msg" ; git push` # if there are # call the script /usr/local/bin/vlanscrape cd /home/vlanscrape/git/git.nordu.net/vlanscrape-data PullMsg=$(git pull 2>&1) if [ $? -ne 0 ] then echo "\"git pull\" failed: ${PullMsg}" exit 1 fi TmpFile=$(mktemp) if [ -z "${TmpFile}" ] then echo "cannot create temp file, giving up on versioning vlanscrape data" exit 1 fi git status --porcelain=1 >"${TmpFile}" FilesAdded=$(grep -E '^??' "${TmpFile}" | wc -l) FilesAdded=$(echo ${FilesAdded} | cut -f 1 -d \ ) FilesModified=$(grep -E '^ M' "${TmpFile}" | wc -l) FilesModified=$(echo ${FilesModified} | cut -f 1 -d \ ) Something=$(wc -l "${TmpFile}") Something=$(echo ${Something} | cut -f 1 -d \ ) if [ ${Something} -ne 0 ] then if [ ${FilesAdded} -ne 0 ] then CommitMsg="File addition" fi if [ ${FilesModified} -ne 0 ] then if [ -z "${CommitMsg}" ] then CommitMsg="File modification" else CommitMsg="${CommitMsg} and modification" fi fi if [ -z "${CommitMsg}" ] then CommitMsg="something changed" fi fi if [ ! -z "${CommitMsg}" ] then git add . git commit -m "${CommitMsg}" git push fi rm "${TmpFile}"