-
Notifications
You must be signed in to change notification settings - Fork 290
/
setup.sh
executable file
·130 lines (111 loc) · 3.82 KB
/
setup.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
#
# Check required JVM.
#
function check-jvm() {
local JAVA_HOME_NAME=$1
local EXPECTED_JAVA_VERSION=$2
if [ -z "${!JAVA_HOME_NAME}" ]; then
echo "❌ $JAVA_HOME_NAME is not set. Please set $JAVA_HOME_NAME to refer to a JDK $EXPECTED_JAVA_VERSION installation." >&2
exit 1
elif ! "${!JAVA_HOME_NAME}/bin/java" -version 2>&1 | grep -q "version \"$EXPECTED_JAVA_VERSION" ; then
echo "❌ $JAVA_HOME_NAME is set to ${!JAVA_HOME_NAME}, but it does not refer to a JDK $EXPECTED_JAVA_VERSION installation." >&2
exit 1
else
echo "✅ $JAVA_HOME_NAME is set to $(readlink -f "${!JAVA_HOME_NAME}")."
fi
}
echo "ℹ️ Checking required JVM:"
if [ -e "$JAVA_HOME" ]; then
check-jvm "JAVA_HOME" "1.8"
fi
check-jvm "JAVA_8_HOME" "1.8"
check-jvm "JAVA_11_HOME" "11"
check-jvm "JAVA_17_HOME" "17"
check-jvm "JAVA_21_HOME" "21"
check-jvm "JAVA_GRAALVM17_HOME" "17"
#
# Check git configuration.
#
function check-command() {
local COMMAND_NAME=$1
if command -v "$COMMAND_NAME" &> /dev/null; then
echo "✅ The $COMMAND_NAME command line is installed."
else
echo "❌ The $COMMAND_NAME command line is missing. Please install $COMMAND_NAME." >&2
exit 1
fi
}
function get-file-hash() {
local FILE=$1
md5sum "$FILE" | awk '{print $1}'
}
function look-for-hook() {
local HOOK_NAME=$1
local HOOK_CHECKSUM
HOOK_CHECKSUM=$(get-file-hash .githooks/$HOOK_NAME)
local HOOKS_PATH
HOOKS_PATH=$(git config core.hooksPath)
if [ -e ".git/hooks/$HOOK_NAME" ] && [ "$(get-file-hash .git/hooks/$HOOK_NAME)" == "$HOOK_CHECKSUM" ]; then
echo "✅ $HOOK_NAME hook is installed in repository."
elif [ -e "$HOOKS_PATH/$HOOK_NAME" ] && [ "$(get-file-hash $HOOKS_PATH/$HOOK_NAME)" == "$HOOK_CHECKSUM" ]; then
echo "✅ $HOOK_NAME hook is installed in git hooks path."
else
echo "🟨 $HOOK_NAME hook was not found (optional but recommended)."
fi
}
function check-git-config() {
local CONFIG_NAME=$1
local EXPECTED_VALUE=$2
local ACTUAL_VALUE
ACTUAL_VALUE=$(git config "$CONFIG_NAME")
if [ "$ACTUAL_VALUE" == "$EXPECTED_VALUE" ]; then
echo "✅ git config $CONFIG_NAME is set to $EXPECTED_VALUE."
elif [ -z "$ACTUAL_VALUE" ]; then
echo "❌ git config $CONFIG_NAME is not set. Please locally set $CONFIG_NAME to $EXPECTED_VALUE."
else
echo "🟨 git config $CONFIG_NAME is set to $ACTUAL_VALUE (expected: $EXPECTED_VALUE)."
fi
}
function check-submodule-initialization() {
if [ -e ".gitmodules" ]; then
if git submodule status | grep '^-' > /dev/null; then
echo "❌ A git submodule are not initialized. Please run 'git submodule update --init --recursive'."
else
echo "✅ All git submodules are initialized."
fi
fi
}
echo "ℹ️ Checking git configuration:"
check-command "git"
look-for-hook "pre-commit"
check-git-config "submodule.recurse" "true"
check-submodule-initialization
#
# Check Docker environment.
#
function check-docker-server() {
if docker info &> /dev/null; then
echo "✅ The Docker server is running."
else
echo "🟨 The Docker server is not running. Please start it be able to run all tests."
fi
}
echo "ℹ️ Checking Docker environment:"
check-command "docker"
check-docker-server
#
# Check shell environment.
# (unused for now)
#
function check-ulimit() {
local LIMIT_NAME="File descriptor limit"
local EXPECTED_LIMIT=$1
local ACTUAL_LIMIT
ACTUAL_LIMIT=$(ulimit -n)
if [ "$ACTUAL_LIMIT" -ge "$EXPECTED_LIMIT" ]; then
echo "✅ $LIMIT_NAME is set to $ACTUAL_LIMIT."
else
echo "🟨 $LIMIT_NAME is set to $ACTUAL_LIMIT, which could be an issue for gradle build. Please set it locally to $EXPECTED_LIMIT or greater using ulimit."
fi
}