#! /bin/bash #---------------------------------------------------------------------------- # extract-versions-and-tags.sh - Extract systems tags and version out of a # list of strings (which are folders out of # the tags folder). # # Creation : 2008-01-16 starwarsfan # Last Update: $Id$ # # Copyright (c) 2001-2009 the eisfair team, team(at)eisfair(dot)org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- #exec 2> `pwd`/package-trace$$.log #set -x # --------------------------------------------------------------------------- # This function iterates over the folders on the given path on $1 and # extracts version number, target number and system tags. # # If the parameter $2 is set to 'true', the function uses 'svn ls', # otherwise only 'ls' # # The function separates the parts out this schema: # # 1.2.3_0_eisfair-1_eisfair-2 # # This string will be cut by the "_", which delivers the version and the # number of the build target. The other parts (system tags) are sorted then # to protect against such things like a tag "1.2.3_0_eisfair-1_eisfair-2" and # "1.2.3_0_eisfair-2_eisfair-1". Normaly such a tag can't be created by the # scripts but you know: root can do everything... ;-) # # Results are written to files ${tmpStables} and ${tmpTestings} which must # be defined before calling this function. The results there are sorted by # the version number. # # Parameters: # $1 - Folder to examine (with full path) # $2 - 'true' if 'svn ls' should be used, otherwise # 'false' for 'ls' # $3 - 'true' if bugfix should be detected # 'false' if not # --------------------------------------------------------------------------- extractFoldernameParts () { if [ $# -lt 2 ] then return ${REQUIRED_PARAMETERS_MISSING} fi unset folderpartVersion unset folderpartTargetNumber unset folderpartSystemTag unset folderpartVersionStable unset folderpartTargetNumberStable unset folderpartSystemTagStable unset folderpartVersionTesting unset folderpartTargetNumberTesting unset folderpartSystemTagTesting pathToExamine=$1 useSVNls=$2 findBugfix=$3 myecho "Function 'extractFoldernameParts() ${pathToExamine} ${useSVNls} ${findBugfix}'" # ------------------------ # Setup the command to use if ${useSVNls} then # ----------------------------------------------------------------- # 'svn ls' should be used, so we have to do these steps: # # - Look only at folders, not at files. So grep everything with # a "/" at the end and then remove the "/" at the end # - Sort result in reverse numeric order # - 1st: by Major # - 2nd: by Minor # - 3rd: by the rest foundFolders=`svn ls ${pathToExamine} \ | grep "/$" \ | cut -d "/" -f1 \ | LANG="de_DE@euro" sort -t. -k1 -k2 -k3 -g -r` else # ----------------------------------------------------------------- # 'ls' should be used # # - Look only at folders, not at files. So 'ls -l' must be used. # '--full-time' and 'LANG="de_DE@euro"' is used to get same result # on every system. # - Grep for directories # - Trim spaces to exactly one space # - Cut out the last entry --> the directory name # - Sort result in reverse numeric order # - 1st: by Major # - 2nd: by Minor # - 3rd: by the rest foundFolders=`ls -l --full-time ${pathToExamine} \ | grep -E "^d" \ | tr -s [[:blank:]] \ | cut -d " " -f9 \ | LANG="de_DE@euro" sort -t. -k1 -k2 -k3 -g -r` fi # ------------------------------- # Now loop over the found folders folderIndex=0 for actualFolder in ${foundFolders} do myecho "Examining folder '${actualFolder}'" # ---------------------------------------------------------- # Separate the folder name by removing the '_' and loop over # the resulting parts idx=0 separator='' for actualFolderPart in `echo ${actualFolder} | sed "s/_/ /g"` do if [ ${idx} -eq 0 ] then # ------------------------------------------------------- # This is the first part which must be the version number folderpartVersion[${folderIndex}]=${actualFolderPart} elif [ ${idx} -eq 1 ] then # -------------------------------------------------- # This is the second part which needs one more check expr ${actualFolderPart} + 0 &> /dev/null if [ $? -lt 3 ] && [ -n "${actualFolderPart}" ] then # ------------------------------------------------- # Second part is a number, so store it on the array folderpartTargetNumber[${folderIndex}]=${actualFolderPart} else # ----------------------------------------------------- # Second part is not a number, so the build target # number seems not to exists on the folder name. Use 0. folderpartTargetNumber[${folderIndex}]='' fi else # ----------------------------------------------- # The rest are the system tags. Summarize them by # adding the '_' back folderpartSystemTag[${folderIndex}]="${folderpartSystemTag[${folderIndex}]}${separator}${actualFolderPart}" separator='_' fi idx=$((idx+1)) done folderIndex=$((folderIndex+1)) done # ----------------------------------------- # Now separate between stables and testings stableIndex=0 testingIndex=0 for (( i = 0 ; i < ${#folderpartVersion[@]} ; i++ )) do # ------------------------------- # Extract parts of version number major=` echo ${folderpartVersion[$i]} | cut -d "." -f1` minor=` echo ${folderpartVersion[$i]} | cut -d "." -f2` bugfix=`echo ${folderpartVersion[$i]} | cut -d "." -f3` # ----------------------------- # Check if minor is even or odd evenCheck=`expr ${minor} % 2` if [ $? -eq 1 ] then # ----------------------------------------------------- # Found a even minor --> add its values to the array of # stable releases, but only if the minor is "0" or if # ${findBugfix} == true if [ "${bugfix}" == "0" -o ${findBugfix} == true ] then myecho "Adding '${folderpartVersion[$i]}' to stables (target: '${folderpartTargetNumber[$i]}', system tags: '${folderpartSystemTag[$i]}'" folderpartVersionStable[${stableIndex}]=${folderpartVersion[$i]} folderpartTargetNumberStable[${stableIndex}]=${folderpartTargetNumber[$i]} folderpartSystemTagStable[${stableIndex}]=${folderpartSystemTag[$i]} stableIndex=$((stableIndex+1)) else myecho "Ignored '${folderpartVersion[$i]}'" fi else # ---------------------------------------------------- # Found a odd minor --> add its values to the array of # testing releases myecho "Adding '${folderpartVersion[$i]}' to testings (target: '${folderpartTargetNumber[$i]}', system tags: '${folderpartSystemTag[$i]}'" folderpartVersionTesting[${testingIndex}]=${folderpartVersion[$i]} folderpartTargetNumberTesting[${testingIndex}]=${folderpartTargetNumber[$i]} folderpartSystemTagTesting[${testingIndex}]="${folderpartSystemTag[$i]}" testingIndex=$((testingIndex+1)) fi done myecho "" }