forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell_functions.inc
35 lines (32 loc) · 1.1 KB
/
shell_functions.inc
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
# Copyright 2015, Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can
# be found in the LICENSE file.
# Library of functions which are used by bootstrap.sh or the Makefile.
# goversion_min returns true if major.minor go version is at least some value.
function goversion_min() {
[[ "$(go version)" =~ go([0-9]+)\.([0-9]+) ]]
gotmajor=${BASH_REMATCH[1]}
gotminor=${BASH_REMATCH[2]}
[[ "$1" =~ ([0-9]+)\.([0-9]+) ]]
wantmajor=${BASH_REMATCH[1]}
wantminor=${BASH_REMATCH[2]}
[ "$gotmajor" -lt "$wantmajor" ] && return 1
[ "$gotmajor" -gt "$wantmajor" ] && return 0
[ "$gotminor" -lt "$wantminor" ] && return 1
return 0
}
# prepend_path returns $2 prepended the colon separated path $1.
# If it's already part of the path, it won't be added again.
# If $1 is a directory, it will also be prepended to $PATH.
function prepend_path() {
# $1 path variable
# $2 path to add
if [ -d "$2" ] && [[ ":$1:" != *":$2:"* ]]; then
echo "$2:$1"
else
echo "$1"
fi
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
export PATH="$1:$PATH"
fi
}