[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
|
---|
[31961] | 33 | num_conflict=0
|
---|
[28490] | 34 |
|
---|
| 35 | # in the lines returned from the diff, test for archives or newline
|
---|
| 36 | # http://stackoverflow.com/questions/229551/string-contains-in-bash
|
---|
| 37 | # http://stackoverflow.com/questions/10515964/counter-increment-in-bash-loop-not-working
|
---|
| 38 | for file in ${filelisting[@]}; do
|
---|
[30613] | 39 | if [[ "$file" != *"zz"* && "$file" != *"test"* ]]; then
|
---|
[31715] | 40 | `svn up $file` # let's update the files first
|
---|
[30613] | 41 | status=`svn status $file`
|
---|
| 42 | # "LINE: $file - status: $status"
|
---|
| 43 | # if the file's svn status is modified, write the filename out to the report
|
---|
| 44 | if [[ "$status" == *"M "* ]]; then
|
---|
| 45 | #echo "$file has been modified: $status"
|
---|
| 46 | echo $status >> $report #echo $file >> $report
|
---|
| 47 | ((num_modified++))
|
---|
| 48 | fi
|
---|
[28490] | 49 | fi
|
---|
| 50 | done
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | if [[ $num_modified == 0 ]]; then
|
---|
| 54 | echo "No files modified" >> $report
|
---|
| 55 | else
|
---|
[28491] | 56 | echo "" >> $report
|
---|
| 57 | echo "The above $num_modified files were modified." >> $report
|
---|
[28490] | 58 | fi
|
---|
| 59 |
|
---|
| 60 | echo "---------------------------------------------" >> $report
|
---|
| 61 |
|
---|
[29830] | 62 | # repeat, this time looking for any newly added files
|
---|
| 63 | for file in ${filelisting[@]}; do
|
---|
[30613] | 64 | if [[ "$file" != *"zz"* && "$file" != *"test"* ]]; then
|
---|
| 65 | status=`svn status $file`
|
---|
| 66 | if [[ "$status" == *"? "* ]]; then
|
---|
| 67 | #echo "$file has been added: $status"
|
---|
| 68 | echo $status >> $report
|
---|
| 69 | ((num_added++))
|
---|
| 70 | fi
|
---|
[29830] | 71 | fi
|
---|
| 72 | done
|
---|
| 73 |
|
---|
| 74 | if [[ $num_added == 0 ]]; then
|
---|
| 75 | echo "No files added" >> $report
|
---|
| 76 | else
|
---|
| 77 | echo "" >> $report
|
---|
| 78 | echo "The above $num_added files were added." >> $report
|
---|
| 79 | fi
|
---|
| 80 |
|
---|
| 81 | echo "---------------------------------------------" >> $report
|
---|
| 82 |
|
---|
[31961] | 83 |
|
---|
| 84 | # repeat again, this time looking for any files in conflict
|
---|
| 85 | for file in ${filelisting[@]}; do
|
---|
| 86 | status=`svn status $file`
|
---|
| 87 | if [[ "$status" == *"C "* ]]; then
|
---|
| 88 | #echo "$file is in conflict: $status"
|
---|
| 89 | echo $status >> $report
|
---|
| 90 | ((num_conflict++))
|
---|
| 91 | fi
|
---|
| 92 | done
|
---|
| 93 |
|
---|
| 94 | if [[ $num_conflict == 0 ]]; then
|
---|
| 95 | echo "No files in conflict" >> $report
|
---|
| 96 | echo "---------------------------------------------" >> $report
|
---|
| 97 | else
|
---|
| 98 | echo "" >> $report
|
---|
| 99 | echo "The above $num_conflict files were IN CONFLICT." >> $report
|
---|
| 100 | echo "---------------------------------------------" >> $report
|
---|
| 101 | fi
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 |
|
---|
[29830] | 106 | # restore IFS
|
---|
| 107 | IFS=$IFS_BAK
|
---|
| 108 | IFS_BAK=
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 |
|
---|
[28490] | 112 | # if no files are modified, we don't send email, otherwise we do
|
---|
[29830] | 113 | if [[ $num_modified != 0 || $num_added != 0 ]]; then
|
---|
| 114 | # echo "Files were modified or added. Sending email..."
|
---|
[31961] | 115 | cat $report | mail -s 'GTI: '$num_modified/$num_added/$num_conflict' language file(s) on gti (nzdl) have been updated/added or conflict' $GREENSTONE_EMAIL
|
---|
[28491] | 116 | echo "Sent mail of report: $report"
|
---|
[31961] | 117 | elif [[ $num_conflict != 0 ]]; then
|
---|
| 118 | # echo "Files were modified or added. Sending email..."
|
---|
| 119 | cat $report | mail -s 'GTI: '$num_conflict' language file(s) on gti (nzdl) are IN CONFLICT' $GREENSTONE_EMAIL
|
---|
| 120 | echo "Sent mail of report: $report"
|
---|
[28491] | 121 | else
|
---|
| 122 | echo "No files modified. Not sending mail."
|
---|
[28490] | 123 | fi
|
---|
[30720] | 124 |
|
---|
| 125 | # Debugging
|
---|
| 126 | # print env vars
|
---|
| 127 | # if cron behaves differently from running this script from cmd line
|
---|
| 128 | #set
|
---|