#!/bin/bash
# upinfo ver. 1.0 by demovik@fr-wd.com /15.09.2009/
#-#-# variables
SVN_ST=/usr/local/scripts/svn_st
local_revision=`svn info | grep Revision | awk {'print $2'}`
project=`svn info | grep "Repository Root" | awk '{print $3}'`
rep_revision=`svn info $project | grep Revision | awk {'print $2'}`
last_rep_user=`svn info $project | grep "Last Changed Author" | awk '{print $4}'`
local_user=`whoami`
#echo $local_user" | "$last_rep_user
#-#-# messages
output=""
box_color="green"
html_green_begin="
"
html_red_begin="
"
html_end="
"
html_br="
"
txt_local_rev="Local revision: "$local_revision
txt_repos_rev="Repository revision: "$rep_revision
txt_fix="You need to execute: svn up"
txt_need_up="Local revision: "$local_revision" | Repository revision: "$rep_revision
txt_ok="Up to date!" #"Your copy is up to date"
txt_br="."
br=$txt_br
if [ "$1" = "html" ]; then
br=$html_br
fi
#-#-# code
if [ "$local_revision" != "$rep_revision" ]; then
if [ "$[ $rep_revision - $local_revision ]" = "1" -a "$local_user" = "$last_rep_user" ]; then
output=$output""$txt_fix # svn_info revision is different than svn_st but it is not an error
else
output=$output""$txt_local_rev""$br""$txt_repos_rev # you need svn up
box_color="red"
fi
else
output=$output""$txt_ok
fi
need_commit=`/usr/local/scripts/svn_st | awk '$1 ~ /^[MDA]/ {print "Need commit"; exit}'` # need commit verification
lost_files=`/usr/local/scripts/svn_st | awk '$1 ~ /^[!]/ {print "Lost files in local copy"; exit}'` # lost files verification
#need_commit=`/usr/local/scripts/svn_st | awk '$0 ~ /^Status against/ && NR != 1 {print "Need commit"}'` # alternative awk command
#need_commit=$($SVN_ST | grep -v "Status against")
if [ "$need_commit" != "" ]; then
if [ "$output" != "" ]; then
output=$output""$br
fi
output=$output""$need_commit # mesage about need commit
fi
if [ "$lost_files" != "" ]; then
if [ "$output" != "" ]; then
output=$output""$br
fi
output=$output""$lost_files # message about lost files
fi
#-#-# output
if [ "$1" = "html" ]; then
# HTML ouput
if [ "$box_color" = "green" ]; then
echo $html_green_begin $output $html_end
else
echo $html_red_begin $output $html_end
fi
else
# Plain text output
echo $output
fi