[29830] | 1 | #!/bin/bash
|
---|
[28490] | 2 |
|
---|
[28492] | 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 |
|
---|
[28490] | 8 | [email protected]
|
---|
[30720] | 9 | # Need this now on gti
|
---|
| 10 | MAIL=/var/spool/mail/gs2
|
---|
[28490] | 11 |
|
---|
| 12 | # get rid of any old reports
|
---|
| 13 | report=translation_status_report.txt
|
---|
| 14 | if test -f $report; then
|
---|
| 15 | rm -f $report
|
---|
| 16 | fi
|
---|
| 17 |
|
---|
[30581] | 18 | 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")
|
---|
[28490] | 19 |
|
---|
| 20 | date=`date +"%d-%m-%y"`
|
---|
| 21 | echo "Translation status report for date: $date" >> $report
|
---|
| 22 | echo "Checked in ${filelisting[@]}" >> $report
|
---|
| 23 | echo "---------------------------------------------" >> $report
|
---|
| 24 |
|
---|
| 25 | # store backup of Internal Field Separator value, then set IFS to newline for splitting on newline
|
---|
| 26 | IFS_BAK=$IFS
|
---|
| 27 | # IFS='\n' # splits on all whitespace
|
---|
| 28 | IFS='
|
---|
| 29 | '
|
---|
| 30 |
|
---|
| 31 | num_modified=0
|
---|
[29830] | 32 | num_added=0
|
---|
[28490] | 33 |
|
---|
| 34 | # in the lines returned from the diff, test for archives or newline
|
---|
| 35 | # http://stackoverflow.com/questions/229551/string-contains-in-bash
|
---|
| 36 | # http://stackoverflow.com/questions/10515964/counter-increment-in-bash-loop-not-working
|
---|
| 37 | for file in ${filelisting[@]}; do
|
---|
[30613] | 38 | if [[ "$file" != *"zz"* && "$file" != *"test"* ]]; then
|
---|
| 39 | status=`svn status $file`
|
---|
| 40 | # "LINE: $file - status: $status"
|
---|
| 41 | # if the file's svn status is modified, write the filename out to the report
|
---|
| 42 | if [[ "$status" == *"M "* ]]; then
|
---|
| 43 | #echo "$file has been modified: $status"
|
---|
| 44 | echo $status >> $report #echo $file >> $report
|
---|
| 45 | ((num_modified++))
|
---|
| 46 | fi
|
---|
[28490] | 47 | fi
|
---|
| 48 | done
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | if [[ $num_modified == 0 ]]; then
|
---|
| 52 | echo "No files modified" >> $report
|
---|
| 53 | else
|
---|
[28491] | 54 | echo "" >> $report
|
---|
| 55 | echo "The above $num_modified files were modified." >> $report
|
---|
[28490] | 56 | fi
|
---|
| 57 |
|
---|
| 58 | echo "---------------------------------------------" >> $report
|
---|
| 59 |
|
---|
[29830] | 60 | # repeat, this time looking for any newly added files
|
---|
| 61 | for file in ${filelisting[@]}; do
|
---|
[30613] | 62 | if [[ "$file" != *"zz"* && "$file" != *"test"* ]]; then
|
---|
| 63 | status=`svn status $file`
|
---|
| 64 | if [[ "$status" == *"? "* ]]; then
|
---|
| 65 | #echo "$file has been added: $status"
|
---|
| 66 | echo $status >> $report
|
---|
| 67 | ((num_added++))
|
---|
| 68 | fi
|
---|
[29830] | 69 | fi
|
---|
| 70 | done
|
---|
| 71 |
|
---|
| 72 | if [[ $num_added == 0 ]]; then
|
---|
| 73 | echo "No files added" >> $report
|
---|
| 74 | else
|
---|
| 75 | echo "" >> $report
|
---|
| 76 | echo "The above $num_added files were added." >> $report
|
---|
| 77 | fi
|
---|
| 78 |
|
---|
| 79 | echo "---------------------------------------------" >> $report
|
---|
| 80 |
|
---|
| 81 | # restore IFS
|
---|
| 82 | IFS=$IFS_BAK
|
---|
| 83 | IFS_BAK=
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 |
|
---|
[28490] | 87 | # if no files are modified, we don't send email, otherwise we do
|
---|
[29830] | 88 | if [[ $num_modified != 0 || $num_added != 0 ]]; then
|
---|
| 89 | # echo "Files were modified or added. Sending email..."
|
---|
[30605] | 90 | cat $report | mail -s 'GTI: '$num_modified/$num_added' language file(s) on gti (nzdl) have been updated/added' $GREENSTONE_EMAIL
|
---|
[28491] | 91 | echo "Sent mail of report: $report"
|
---|
| 92 | else
|
---|
| 93 | echo "No files modified. Not sending mail."
|
---|
[28490] | 94 | fi
|
---|
[30720] | 95 |
|
---|
| 96 | # Debugging
|
---|
| 97 | # print env vars
|
---|
| 98 | # if cron behaves differently from running this script from cmd line
|
---|
| 99 | #set
|
---|