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