-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
check-prerequisites.sh
executable file
·104 lines (82 loc) · 4.58 KB
/
check-prerequisites.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
#!/usr/bin/env bash
set -e
# check wether required tools are available
# Checks for the presence of the GitHub command line tool
if ! command -v "gh" >/dev/null 2>&1
then
echo "ERROR: command line 'gh' required but not found. Exiting."
exit 1
fi
# Checks for the presence of the Json Query tool
if ! command -v "jq" >/dev/null 2>&1
then
echo "ERROR: command line 'jq' required but not found. Exiting."
exit 1
fi
# Check presence of the "datamash" tool (CSV manipulation tool)
if ! command -v "datamash" >/dev/null 2>&1
then
echo "ERROR: command line 'datamash' required but not found. Exiting."
exit 1
fi
# Check for "jenkins-contribution-aggregator" presence and minimal version
if ! command -v "jenkins-contribution-aggregator" >/dev/null 2>&1
then
echo "ERROR: command line 'jenkins-contribution-aggregator' required but not found. Exiting."
exit 1
fi
## TODO: (code duplication) This could be refactored and moved to a bash sub routine
# The target version of the jenkins-contribution-aggregator tool that we want to have installed.
top_target_version=1.2.10
# Fetch the currently installed version of the jenkins-contribution-aggregator tool.
# The 'awk' command is used to extract the version number from the output of the 'jenkins-contribution-aggregator version' command.
top_installed_version=$(jenkins-contribution-aggregator version | awk '{print $NF}')
# Compare the installed version with the target version.
# The 'sort -V' command is used to sort the version numbers in version sort order, and 'head -n 1' is used to get the smallest version.
# If the smallest version is not the target version, it means the installed version is less than the target version.
if [[ $(echo -e "$top_target_version\n$top_installed_version" | sort -V | head -n 1) != "$top_target_version" ]]; then
# If the installed version is less than the target version, print an error message in red and bold.
echo -e "Error: installed version ($top_installed_version) is less than target version ($top_target_version)."
# Suggest the user to update the jenkins-contribution-aggregator tool using the 'brew upgrade' command.
echo -e "Please update the jenkins-contribution-aggregator tool thanks to the following command:"
# Print the 'brew upgrade' command in blue and bold.
echo -e " brew upgrade jenkins-contribution-aggregator"
# Exit the script with a status of 1 to indicate an error.
exit 1
fi
# check for "jenkins-contribution-extractor" presence and minimal version
if ! command -v "jenkins-contribution-extractor" >/dev/null 2>&1
then
echo "ERROR: command line 'jenkins-contribution-extractor' required but not found. Exiting."
exit 1
fi
## TODO: (code duplication) This could be refactored and moved to a bash sub routine
# The target version of the jenkins-contribution-extractor tool that we want to have installed.
stats_target_version=0.2.18
# Fetch the currently installed version of the jenkins-contribution-extractor tool.
# The 'awk' command is used to extract the version number from the output of the 'jenkins-contribution-extractor version' command.
stats_installed_version=$(jenkins-contribution-extractor version | awk '{print $NF}')
# Compare the installed version with the target version.
# The 'sort -V' command is used to sort the version numbers in version sort order, and 'head -n 1' is used to get the smallest version.
# If the smallest version is not the target version, it means the installed version is less than the target version.
if [[ $(echo -e "$stats_target_version\n$stats_installed_version" | sort -V | head -n 1) != "$stats_target_version" ]]; then
# If the installed version is less than the target version, print an error message in red and bold.
echo -e "Error: installed version ($stats_installed_version) is less than target version ($stats_target_version)."
# Suggest the user to update the jenkins-contribution-extractor tool using the 'brew upgrade' command.
echo -e "Please update the jenkins-contribution-extractor tool thanks to the following command:"
# Print the 'brew upgrade' command in blue and bold.
echo -e " brew upgrade jenkins-contribution-extractor"
# Exit the script with a status of 1 to indicate an error.
exit 1
fi
# The scripts require the GNU date. A special executable needs to be installed
if [[ "$OSTYPE" == "darwin"* ]]; then
if ! command -v "gdate" >/dev/null 2>&1
then
echo "ERROR: command line 'gdate' required but not found."
echo "You should be able to install it with \"brew install coreutils\""
echo ""
echo "exiting...."
exit 1
fi
fi