Skip to content

Commit 7964cde

Browse files
committed
Always default port to 122
1 parent d792b23 commit 7964cde

File tree

2 files changed

+7
-31
lines changed

2 files changed

+7
-31
lines changed

bin/ghe-host-check

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

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

8758
CLUSTER=false
8859
if ghe-ssh "$host" -- \

share/github-backup-utils/ghe-backup-config

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,12 @@ ssh_host_part() {
334334
# This is used primarily to break hostspecs with non-standard ports down for
335335
# rsync commands.
336336
ssh_port_part() {
337-
[ "${1##*:}" = "$1" ] && echo 22 || echo "${1##*:}"
337+
if [ "${1##*:}" != "$1" ] && [ "${1##*:}" -ne "122" ]; then
338+
echo "Error: SSH port has to be 122 connecting to Github Enterprise Server, current value is ${1##*:} for $1." 1>&2
339+
exit 1
340+
fi
341+
342+
echo 122
338343
}
339344

340345
# Usage: ghe_remote_logger <message>...

0 commit comments

Comments
 (0)