summaryrefslogtreecommitdiff
path: root/code/vlanscrape-wrapper
blob: 250d4775bc4ede0f953d911c2f1dbb2a1008bf80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/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

TmpFile=$(mktemp)
if [ -z $TmpFile ]
then
  echo "cannot create temp file, giving up on versioning vkanscrape 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 = "$CommiMsg and modification"
    fi
  fi
  if [ -z $CommitMsg ]
  then
    CommitMsg = "something changed"
  fi
fi

if [ -z $CommitMsg ]
then
  exit 0
fi

git add .
git commit -m "$CommitMsg"
git push