~ubuntu-branches/debian/jessie/resource-agents/jessie

« back to all changes in this revision

Viewing changes to heartbeat/ocf-shellfuncs.in

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2011-06-21 13:45:36 UTC
  • Revision ID: james.westby@ubuntu.com-20110621134536-155vq8sf8p2p18wt
Tags: upstream-3.9.1
ImportĀ upstreamĀ versionĀ 3.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
23
24
24
 
25
 
# Build version: 6b9b4274aef554abfbdf5ea38b0d213414ff6877
 
25
# Build version: ac185337533b94054fef0094362fac3409d3b3d4
26
26
 
27
27
# TODO: Some of this should probably split out into a generic OCF
28
28
# library for shell scripts, but for the time being, we'll just use it
433
433
    [ ! -z "${OCF_RESKEY_CRM_meta_master_max}" ] && [ "${OCF_RESKEY_CRM_meta_master_max}" -gt 0 ]
434
434
}
435
435
 
 
436
# version check functions
 
437
# allow . and - to delimit version numbers
 
438
# max version number is 999
 
439
# letters and such are effectively ignored
 
440
#
 
441
ocf_is_ver() {
 
442
        echo $1 | grep '^[0-9][0-9.-]*[0-9]$' >/dev/null 2>&1
 
443
}
 
444
ocf_ver2num() {
 
445
        echo $1 | awk -F'[.-]' '
 
446
        {for(i=1; i<=NF; i++) s=s*1000+$i; print s}
 
447
        '
 
448
}
 
449
 
 
450
# usage: ocf_version_cmp VER1 VER2
 
451
#     version strings can contain digits, dots, and dashes
 
452
#     must start and end with a digit
 
453
# returns:
 
454
#     0: VER1 smaller (older) than VER2
 
455
#     1: versions equal
 
456
#     2: VER1 greater (newer) than VER2
 
457
#     3: bad format
 
458
ocf_version_cmp() {
 
459
        ocf_is_ver "$1" || return 3
 
460
        ocf_is_ver "$2" || return 3
 
461
        local v1=`ocf_ver2num $1`
 
462
        local v2=`ocf_ver2num $2`
 
463
        if [ $v1 -eq $v2 ]; then
 
464
                return 1
 
465
        elif [ $v1 -lt $v2 ]; then
 
466
                return 0
 
467
        else
 
468
                return 2 # -1 would look funny in shell ;-)
 
469
        fi
 
470
}
 
471
 
436
472
# usage: dirname DIR
437
473
dirname()
438
474
{