Skip to content

Commit b2aff97

Browse files
authored
Merge pull request #298 from github/chuckp22-no-command-check
Verify software requirements are installed
2 parents 36249d7 + 0bb784f commit b2aff97

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

bin/ghe-host-check

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,23 @@ DATA_TRANSFER_SIZE
192192
fi
193193

194194
#Check rsync, openssh & jq versions
195+
commands=("jq" "rsync" "ssh")
196+
missing_command=""
197+
for cmd in "${commands[@]}"; do
198+
if ! command -v "$cmd" > /dev/null 2>&1; then
199+
missing_command+="$cmd "
200+
fi
201+
done
202+
203+
# Check if any command is missing
204+
if [[ -n "$missing_command" ]]; then
205+
echo "One or more required tools not found: $missing_command" 1>&2
206+
echo "Please make sure the following utils are installed and available in your PATH: $missing_command" 1>&2
207+
exit 1
208+
fi
209+
195210
echo "### Software versions" 1>&2
196-
rsync_version=$(rsync --version | grep 'version' | awk '{print $3}')
211+
rsync_version=$(rsync --version | grep 'version' | awk '{print $3}' | tr -cd '[:digit:].\n')
197212
if awk "BEGIN {exit !($rsync_version < $min_rsync)}" &> /dev/null; then
198213
echo "rsync version $rsync_version in backup-host does not meet minimum requirements." 1>&2
199214
echo "Please make sure you have the minimum required version of rsync: $min_rsync installed" 1>&2
@@ -202,7 +217,7 @@ DATA_TRANSFER_SIZE
202217
echo "rsync ${rsync_version} >= required ($min_rsync)" 1>&2
203218
fi
204219

205-
ssh_version=$(ssh -V 2>&1 | awk '{print $1}'|grep -oPm 1 '[\d\.]+' |head -1)
220+
ssh_version=$(ssh -V 2>&1 | awk '{print $1}'|grep -oPm 1 '[\d\.]+' |head -1 | tr -cd '[:digit:].\n')
206221
if awk "BEGIN {exit !($ssh_version < $min_openssh)}" &> /dev/null; then
207222
echo "openSSH version $ssh_version in backup-host does not meet minimum requirements." 1>&2
208223
echo "Please make sure the minimum required version of openSSH: $min_openssh is installed" 1>&2
@@ -211,7 +226,7 @@ DATA_TRANSFER_SIZE
211226
echo "openSSH ${ssh_version} >= required ($min_openssh)" 1>&2
212227
fi
213228

214-
jq_version=$(jq --version |awk -F\- '{print $2}')
229+
jq_version=$(jq --version |awk -F\- '{print $2}' | tr -cd '[:digit:].\n')
215230
if awk "BEGIN {exit !($jq_version < $min_jq)}" &> /dev/null; then
216231
echo "jq version $jq_version in backup-host does not meet minimum requirements." 1>&2
217232
echo "Please make sure you have the minimum required version of jq: $min_jq installed" 1>&2

0 commit comments

Comments
 (0)