From 16f951b6fcddb9c2c00131eb612b19448c34cc1f Mon Sep 17 00:00:00 2001 From: Mari Date: Fri, 26 Jun 2020 19:53:53 -0400 Subject: [PATCH] Update new-host.sh --- new-host.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/new-host.sh b/new-host.sh index fc7fc48..0723a7d 100644 --- a/new-host.sh +++ b/new-host.sh @@ -28,9 +28,15 @@ fi function getCurrentGithubId() { local RESULT; - RESULT=$(ssh -o "IdentitiesOnly=yes" -i ~/.ssh/id_ed25519 -T git@github.com &1) - [[ $? -ne 255 ]] || { echo "$RESULT" >&2; exit 1; } - USERNAME=$(echo "$RESULT" | sed -n 's/^Hi \([^!]\+\)! You'"'"'ve successfully authenticated, but GitHub does not provide shell access\.$/Successfully authenticated to GitHub as \1/; T; p') || exit 1 + set +e + RESULT=$(ssh -o "IdentitiesOnly=yes" -i ~/.ssh/id_ed25519 -T git@github.com &1) + if [[ $? -eq 255 ]]; then + echo "$RESULT" >&2 + return 1 + fi + if ! USERNAME=$(echo "$RESULT" | sed -n 's/^Hi \([^!]\+\)! You'"'"'ve successfully authenticated, but GitHub does not provide shell access\.$/\1/; T; p'); then + return 1 + fi echo "$USERNAME" [[ -n "$USERNAME" ]]; }