forked from openitg/openitg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.sh
67 lines (52 loc) · 1.56 KB
/
common.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
# common.sh - defines common operations so we can quickly check the
# sanity of the environment our scripts run in.
# Somewhat counterintuitively, these return 0 if true and 1 if false.
# That's so we can set -e and do sanity checking quickly.
#
# global constants, relative to the repository root
#
ASSETS_DIR="assets"
ITG2_UTIL_DIR="$ASSETS_DIR/utilities/itg2-util/src"
ITG2_UTIL_FILE="itg2ac-util"
ITG2_UTIL_PATH="$ITG2_UTIL_DIR/$ITG2_UTIL_FILE"
VERIFY_SIG_DIR="src/verify_signature/java"
VERIFY_SIG_FILE="SignFile.java"
VERIFY_SIG_PATH="$VERIFY_SIG_DIR/$VERIFY_SIG_FILE"
#
# generic sanity checking functions and their generic error messages
#
COMMAND_ERROR="Command \"%s\" not found! Please fix that so we can continue."
FILE_ERROR="File \"%s\" not found! We need that to continue; please find it."
# has_command [cmd] [error] - if cmd cannot be found, display "error" if
# supplied, (which may use %s to get the cmd name) or use a generic error.
function has_command
{
if [ -z "$1" ]; then
echo "$0: no command given to check!"
return 1
fi
set +e
which $1 &> /dev/null
RET="$?"
set -e
if [ $RET -eq 0 ]; then return 0; fi
# use the custom error message if we have it
printf "${2-$COMMAND_ERROR}\n" $1
return 1
}
# has_file [file] [error] - has_command, but for files. Same rules apply.
function has_file
{
if [ -z "$1" ]; then
echo "$0: no file given to check!"
return 1
fi
set +e
file "$1" &> /dev/null
RET=$?
set -e
if [ $RET -eq 0 ]; then return 0; fi
# use the custom error message if we have it
printf "${2-$FILE_ERROR}\n" $1
return 1
}