You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.1 KiB

#! /bin/bash
# This script gets two arguments:
# 1) An operand (eq/ne/ge/gt/le/lt)
# 2) A version number
# and returns the result of the comparison.
#
# Example usage:
# To test whether the libc version is == 2.26 , run the following command:
# testLibcVersion eq 2.26
# this function takes a string in version format (s.a 2.6.16) and makes it an integer (00020006001600000000)
function digit_version { echo $1 | awk -F. '{ printf("%04d%04d%04d\n", $1, $2, $3); }'; }
libc_ver=$(digit_version `ldd --version| egrep -o "[1-9]+\.[0-9]+(\.[0-9]*)?" | head -1`)
arg_ver=$(digit_version $2)
case $1 in
"eq" ) if [ $libc_ver -eq $arg_ver ]; then echo 1; else echo 0; fi;;
"ne" ) if [ $libc_ver -ne $arg_ver ]; then echo 1; else echo 0; fi;;
"lt" ) if [ $libc_ver -lt $arg_ver ]; then echo 1; else echo 0; fi;;
"le" ) if [ $libc_ver -le $arg_ver ]; then echo 1; else echo 0; fi;;
"gt" ) if [ $libc_ver -gt $arg_ver ]; then echo 1; else echo 0; fi;;
"ge" ) if [ $libc_ver -ge $arg_ver ]; then echo 1; else echo 0; fi;;
* ) echo "Bad argument $1 (should be eq/ne/ge/gt/le/lt) " ;;
esac