This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
helpers.lib.sh
72 lines (63 loc) · 1.91 KB
/
helpers.lib.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
# not executable ! use prifi.sh, simul.sh, test.sh
# min required go version
min_go_version=19 # min required go version, without the '.', e.g. 17 for 1.7.x
#pretty colored message
highlightOn="\033[33m"
highlightOff="\033[0m"
shell="\033[35m[script]${highlightOff}"
warningMsg="${highlightOn}[warning]${highlightOff}"
errorMsg="\033[31m\033[1m[error]${highlightOff}"
okMsg="\033[32m[ok]${highlightOff}"
if [ "$colors" = "false" ]; then
highlightOn=""
highlightOff=""
shell="[script]"
warningMsg="[warning]"
errorMsg="[error]"
okMsg="[ok]"
fi
#tests if GOPATH is set and exists
test_go(){
if [ -z "$GOPATH" ]; then
echo -e "$errorMsg GOPATH is unset ! make sure you installed the Go language."
exit 1
fi
if [ ! -d "$GOPATH" ]; then
echo -e "$errorMsg GOPATH ($GOPATH) is not a folder ! make sure you installed the Go language correctly."
exit 1
fi
GO_VER=$(go version 2>&1 | sed 's/.*version go\([[:digit:]]*\)\.\([[:digit:]]*\)\(.*\)/\1\2/; 1q')
if [ "$GO_VER" -lt "$min_go_version" ]; then
echo -e "$errorMsg Go >= 1.7.0 is required"
exit 1
fi
}
# test if $1 is a digit, if not, prints "argument $2 invalid" and exit.
test_digit() {
case $1 in
''|*[!0-9]*)
echo -e "$errorMsg parameter $2 need to be an integer."
exit 1;;
*) ;;
esac
}
#test if all the files we need are there.
test_files() {
if [ ! -f "$bin_file" ]; then
echo -e "$errorMsg Runnable go file does not seems to exists: $bin_file"
exit
fi
if [ ! -f "$identity_file2" ]; then
echo -e "$errorMsg Cothority config file does not exist: $identity_file2"
exit
fi
if [ ! -f "$group_file2" ]; then
echo -e "$errorMsg Cothority group file does not exist: $group_file2"
exit
fi
if [ ! -f "$prifi_file2" ]; then
echo -e "$errorMsg PriFi config file does not exist: $prifi_file2"
exit
fi
}