-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.sh
44 lines (40 loc) · 931 Bytes
/
utils.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#Sunday, October 21, 2018
#utils.sh
#shared with enable_* scripts
# example: is a variable set already? If not, give it a default value
# if [ -z $FOO ]; then
# FOO=0
# fi
add_to_path()
{
case ":$PATH:" in
*":$1:"*) :;; # already there: ignore
*) PATH="$1:$PATH";; # add to PATH
esac
# this is what the (obscure) case statement above does:
# echo $PATH | grep -q -s "/usr/local/bin"
# if [ $? -eq 1 ] ; then
# PATH=/usr/local/bin:$PATH
# fi
}
#
# test two versions of something (in this case, gcc)
#
# example usage:
#
# currentver="$(gcc -dumpversion)"
# requiredver="5.0.0"
# at_least_required_version $currentver $requiredver
#
at_least_required_version()
{
current=$1
required=$2
if [ "$(printf '%s\n' "$required" "$current" | sort -V | head -n1)" = "$required" ]; then
echo "Greater than or equal to $required"
return 1
else
echo "Less than $required"
return 0
fi
}