1#! /bin/bash 2# 3# Create the $2 file from $1 using the tag in $3 4# 5 6# Check for the in file, if not there we're probably in the wrong directory 7if [ ! -f $1 ]; then 8 echo file "$1" not found 9 exit 1 10fi 11 12 # Tag should be in the form 13 # <NAME>_REL_<MAJ>_<MINOR> 14 # or 15 # <NAME>_REL_<MAJ>_<MINOR>_RC<RCNUM> 16 # or 17 # <NAME>_REL_<MAJ>_<MINOR>_RC<RCNUM>_<INCREMENTAL> 18 TAG=$3 19 20 # Remove leading cvs "Name: " and trailing " $" 21 TAG=${TAG/#*: /} 22 TAG=${TAG/% $/} 23 24 # Split the tag into an array on underbar or whitespace boundaries. 25 IFS="_ " tag=(${TAG}) 26 unset IFS 27 28 tagged=1 29 if [ ${#tag[*]} -eq 0 ]; then 30 tag=(`date '+TOT REL %Y %m %d 0 %y'`); 31 tagged=0 32 fi 33 34 # Allow environment variable to override values. 35 # Missing values default to 0 36 # 37 maj=${MOD_MAJOR_VERSION:-${tag[2]:-0}} 38 min=${MOD_MINOR_VERSION:-${tag[3]:-0}} 39 rcnum=${MOD_RC_NUMBER:-${tag[4]:-0}} 40 incremental=${MOD_INCREMENTAL_NUMBER:-${tag[5]:-0}} 41 build=${MOD_BUILD_NUMBER:-0} 42 43 # Strip 'RC' from front of rcnum if present 44 rcnum=${rcnum/#RC/} 45 46 # strip leading zero off the number (otherwise they look like octal) 47 maj=${maj/#0/} 48 min=${min/#0/} 49 min_router=${min} 50 rcnum=${rcnum/#0/} 51 incremental=${incremental/#0/} 52 build=${build/#0/} 53 54 # some numbers may now be null. replace with with zero. 55 maj=${maj:-0} 56 min=${min:-0} 57 rcnum=${rcnum:-0} 58 incremental=${incremental:-0} 59 build=${build:-0} 60 61 if [ ${tagged} -eq 1 ]; then 62 vernum=`printf "0x%02x%02x%02x%02x" ${maj} ${min} ${rcnum} ${incremental}` 63 else 64 vernum=`printf "0x00%02x%02x%02x" ${tag[7]} ${min} ${rcnum}` 65 fi 66 67 68 # PR17029: increment minor number for tagged router builds 69 # with an even minor revision 70 if [ ${tagged} -eq 1 -a `expr \( \( ${min} + 1 \) % 2 \)` -eq 1 ]; then 71 min_router=`expr ${min} + 1` 72 fi 73 74 75 # OK, go do it 76 77 echo "maj=${maj}, min=${min}, rc=${rcnum}, inc=${incremental}, build=${build}" 78 echo "Router maj=${maj}, min=${min_router}, rc=${rcnum}, inc=${incremental}, build=${build}" 79 80 sed \ 81 -e "s;@MOD_MAJOR_VERSION@;${maj};" \ 82 -e "s;@MOD_MINOR_VERSION@;${min};" \ 83 -e "s;@MOD_RC_NUMBER@;${rcnum};" \ 84 -e "s;@MOD_INCREMENTAL_NUMBER@;${incremental};" \ 85 -e "s;@MOD_BUILD_NUMBER@;${build};" \ 86 -e "s;@MOD_VERSION@;${maj}, ${min}, ${rcnum}, ${incremental};" \ 87 -e "s;@MOD_VERSION_STR@;${maj}.${min}.${rcnum}.${incremental};" \ 88 -e "s;@MOD_ROUTER_VERSION_STR@;${maj}.${min_router}.${rcnum}.${incremental};" \ 89 -e "s;@MOD_VERSION_NUM@;${vernum};" \ 90 < $1 > $2 91