#!/bin/bash # This script makes a report of any language files that have been modified via the online GTI, # and sends off an email containing this report if any have been modified. # Although it works in local GS2 installations as well, this file needs to live in the top-level # of the GTI greenstone installation on nzdl. It's called by the cronjobs running on nzdl. GREENSTONE_EMAIL=greenstone_team@cs.waikato.ac.nz # get rid of any old reports report=translation_status_report.txt if test -f $report; then rm -f $report fi 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") date=`date +"%d-%m-%y"` echo "Translation status report for date: $date" >> $report echo "Checked in ${filelisting[@]}" >> $report echo "---------------------------------------------" >> $report # store backup of Internal Field Separator value, then set IFS to newline for splitting on newline IFS_BAK=$IFS # IFS='\n' # splits on all whitespace IFS=' ' num_modified=0 num_added=0 # in the lines returned from the diff, test for archives or newline # http://stackoverflow.com/questions/229551/string-contains-in-bash # http://stackoverflow.com/questions/10515964/counter-increment-in-bash-loop-not-working for file in ${filelisting[@]}; do if [[ "$file" != *"zz"* && "$file" != *"test"* ]]; then status=`svn status $file` # "LINE: $file - status: $status" # if the file's svn status is modified, write the filename out to the report if [[ "$status" == *"M "* ]]; then #echo "$file has been modified: $status" echo $status >> $report #echo $file >> $report ((num_modified++)) fi fi done if [[ $num_modified == 0 ]]; then echo "No files modified" >> $report else echo "" >> $report echo "The above $num_modified files were modified." >> $report fi echo "---------------------------------------------" >> $report # repeat, this time looking for any newly added files for file in ${filelisting[@]}; do if [[ "$file" != *"zz"* && "$file" != *"test"* ]]; then status=`svn status $file` if [[ "$status" == *"? "* ]]; then #echo "$file has been added: $status" echo $status >> $report ((num_added++)) fi fi done if [[ $num_added == 0 ]]; then echo "No files added" >> $report else echo "" >> $report echo "The above $num_added files were added." >> $report fi echo "---------------------------------------------" >> $report # restore IFS IFS=$IFS_BAK IFS_BAK= # if no files are modified, we don't send email, otherwise we do if [[ $num_modified != 0 || $num_added != 0 ]]; then # echo "Files were modified or added. Sending email..." cat $report | mail -s 'GTI: '$num_modified/$num_added' language file(s) on gti (nzdl) have been updated/added' $GREENSTONE_EMAIL echo "Sent mail of report: $report" else echo "No files modified. Not sending mail." fi