1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # This script makes a report of any language files that have been modified via the online GTI,
|
---|
4 | # and sends off an email containing this report if any have been modified.
|
---|
5 | # Although it works in local GS2 installations as well, this file needs to live in the top-level
|
---|
6 | # of the GTI greenstone installation on nzdl. It's called by the cronjobs running on nzdl.
|
---|
7 |
|
---|
8 | GREENSTONE_EMAIL=greenstone_team@cs.waikato.ac.nz
|
---|
9 |
|
---|
10 | # get rid of any old reports
|
---|
11 | report=translation_status_report.txt
|
---|
12 | if test -f $report; then
|
---|
13 | rm -f $report
|
---|
14 | fi
|
---|
15 |
|
---|
16 | filelisting=("macros/*.dm" "perllib/strings*.properties" "gli/classes/dictionary*.properties" "gli/help/" "gsinstaller/LanguagePack*.properties" "greenstone3/*.properties" "gs3-collection-configs/*.properties" "greenstoneorg/website/classes/Gsc*.properties")
|
---|
17 |
|
---|
18 | date=`date +"%d-%m-%y"`
|
---|
19 | echo "Translation status report for date: $date" >> $report
|
---|
20 | echo "Checked in ${filelisting[@]}" >> $report
|
---|
21 | echo "---------------------------------------------" >> $report
|
---|
22 |
|
---|
23 | # store backup of Internal Field Separator value, then set IFS to newline for splitting on newline
|
---|
24 | IFS_BAK=$IFS
|
---|
25 | # IFS='\n' # splits on all whitespace
|
---|
26 | IFS='
|
---|
27 | '
|
---|
28 |
|
---|
29 | num_modified=0
|
---|
30 | num_added=0
|
---|
31 |
|
---|
32 | # in the lines returned from the diff, test for archives or newline
|
---|
33 | # http://stackoverflow.com/questions/229551/string-contains-in-bash
|
---|
34 | # http://stackoverflow.com/questions/10515964/counter-increment-in-bash-loop-not-working
|
---|
35 | for file in ${filelisting[@]}; do
|
---|
36 | status=`svn status $file`
|
---|
37 | # "LINE: $file - status: $status"
|
---|
38 | # if the file's svn status is modified, write the filename out to the report
|
---|
39 | if [[ "$status" == *"M "* ]]; then
|
---|
40 | #echo "$file has been modified: $status"
|
---|
41 | echo $status >> $report #echo $file >> $report
|
---|
42 | ((num_modified++))
|
---|
43 | fi
|
---|
44 | done
|
---|
45 |
|
---|
46 |
|
---|
47 | if [[ $num_modified == 0 ]]; then
|
---|
48 | echo "No files modified" >> $report
|
---|
49 | else
|
---|
50 | echo "" >> $report
|
---|
51 | echo "The above $num_modified files were modified." >> $report
|
---|
52 | fi
|
---|
53 |
|
---|
54 | echo "---------------------------------------------" >> $report
|
---|
55 |
|
---|
56 | # repeat, this time looking for any newly added files
|
---|
57 | for file in ${filelisting[@]}; do
|
---|
58 | status=`svn status $file`
|
---|
59 | if [[ "$status" == *"? "* ]]; then
|
---|
60 | #echo "$file has been added: $status"
|
---|
61 | echo $status >> $report
|
---|
62 | ((num_added++))
|
---|
63 | fi
|
---|
64 | done
|
---|
65 |
|
---|
66 | if [[ $num_added == 0 ]]; then
|
---|
67 | echo "No files added" >> $report
|
---|
68 | else
|
---|
69 | echo "" >> $report
|
---|
70 | echo "The above $num_added files were added." >> $report
|
---|
71 | fi
|
---|
72 |
|
---|
73 | echo "---------------------------------------------" >> $report
|
---|
74 |
|
---|
75 | # restore IFS
|
---|
76 | IFS=$IFS_BAK
|
---|
77 | IFS_BAK=
|
---|
78 |
|
---|
79 |
|
---|
80 |
|
---|
81 | # if no files are modified, we don't send email, otherwise we do
|
---|
82 | if [[ $num_modified != 0 || $num_added != 0 ]]; then
|
---|
83 | # echo "Files were modified or added. Sending email..."
|
---|
84 | cat $report | mail -s 'GTI: '$num_modified/$num_added' language file(s) on nzdl have been updated/added' $GREENSTONE_EMAIL
|
---|
85 | echo "Sent mail of report: $report"
|
---|
86 | else
|
---|
87 | echo "No files modified. Not sending mail."
|
---|
88 | fi
|
---|