Skip to content

Commit c28e9eb

Browse files
authored
Merge pull request #862 from github/hao/fix-host-check
Revert logic for host check
2 parents 78974b6 + 90d573c commit c28e9eb

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

bin/ghe-host-check

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,38 @@ options="
5252
port=$(ssh_port_part "$host")
5353
hostname=$(ssh_host_part "$host")
5454

55+
set +e
5556
# ghe-negotiate-version verifies if the target is a Github Enterprise Server instance
5657
output=$(echo "ghe-negotiate-version backup-utils $BACKUP_UTILS_VERSION" | ghe-ssh -o BatchMode=no $options $host -- /bin/sh 2>&1)
58+
rc=$?
59+
set -e
60+
61+
if [ $rc -ne 0 ]; then
62+
case $rc in
63+
255)
64+
if echo "$output" | grep -i "port 22: Network is unreachable\|port 22: connection refused\|port 22: no route to host\|ssh_exchange_identification: Connection closed by remote host\|Connection timed out during banner exchange\|port 22: Connection timed out" >/dev/null; then
65+
exec "$(basename $0)" "$hostname:122"
66+
fi
67+
68+
echo "$output" 1>&2
69+
echo "Error: ssh connection with '$host' failed" 1>&2
70+
echo "Note that your SSH key needs to be setup on $host as described in:" 1>&2
71+
echo "* https://enterprise.github.com/help/articles/adding-an-ssh-key-for-shell-access" 1>&2
72+
;;
73+
101)
74+
echo "Error: couldn't read GitHub Enterprise Server fingerprint on '$host' or this isn't a GitHub appliance." 1>&2
75+
;;
76+
1)
77+
if [ "${port:-22}" -eq 22 ] && echo "$output" | grep "use port 122" >/dev/null; then
78+
exec "$(basename $0)" "$hostname:122"
79+
else
80+
echo "$output" 1>&2
81+
fi
82+
;;
83+
84+
esac
85+
exit $rc
86+
fi
5787

5888
CLUSTER=false
5989
if ghe-ssh "$host" -- \

0 commit comments

Comments
 (0)