Linux get SVN head version, and check if need to checkout

 #!/bin/bash

 svn_version_file_ncb=svn_ncb.txt
 svn_version_file_api=svn_api.txt

 svn_resp_api='https://svn.xxx.net/api/trunk'
 svn_resp_ncb='https://svn.xxx.net/ncb/trunk'


 [ ! -f $svn_version_file_ncb ] && echo 0 > $svn_version_file_ncb
 [ ! -f $svn_version_file_api ] && echo 0 > $svn_version_file_api


 check_need_run()
 {
     local need_run=0
     local svn_resp=$1
     local svn_version_file=$2
     local last_version=$(tail -n 1 $svn_version_file)
     echo $last_version
     echo '==========='
     local head_version=`svn info -r head $svn_resp | grep "Last Changed Rev" | awk  '{print $NF}'`
     echo $head_version

     # need run task
     if [ $head_version -gt $last_version ]; then
         echo "need run"
         #rake
         if [ $? -eq 0 ]; then
             echo $head_version >> $svn_version_file
         fi
         need_run=1
     else
         echo "alread is the newest version."
         need_run=0
     fi
     return $need_run
 }


 check_need_run $svn_resp_api $svn_version_file_api
 need_run_api=$?
 echo $need_run_api

 check_need_run $svn_resp_ncb $svn_version_file_ncb
 need_run_ncb=$?
 echo $need_run_ncb

你可能感兴趣的:(Linux get SVN head version, and check if need to checkout)