Skip to content

Commit

Permalink
fix(networking): Ask for confirmation before updating ssh key
Browse files Browse the repository at this point in the history
  • Loading branch information
ar13pit authored and MatthijsBurgh committed Oct 28, 2020
1 parent 7a5714a commit d01f6b8
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions networking/install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,29 @@ else
# Generate new ssh key if length < 4096
if [ "$(ssh-keygen -l -f "$ssh_key" | awk '{print $1}')" -lt 4096 ]
then
tue-install-info "Generating new ssh key as length < 4096, you might need to copy the new key to the robots, GitHub, etc."
generate_ssh="true"
# Ask user whether the ssh key should be updated
while true
do
exec < /dev/tty
read -p $"\033[1m[networking]\033[0m: Your ssh key '$ssh_key' is not secure anymore and needs to be updated. If you use this key for git, you will need to update your public key "\
"on the hosts. Do you want to update your key? " -n 1 -r
exec <&-
echo # (optional) move to a new line

if [[ $REPLY =~ ^[Yy]$ ]]
then
tue-install-info "Generating new ssh key as length < 4096, you might need to copy the new key to the robots, GitHub, etc."
generate_ssh="true"
break
fi

if [[ $REPLY =~ ^[Nn]$ ]]
then
tue-install-info "Generating new ssh key as length < 4096, you might need to copy the new key to the robots, GitHub, etc."
break
fi
echo -e "\033[1mPlease answer with 'y' or 'n' to continue\033[0m"
done
else
tue-install-debug "ssh key available with length >= 4096"
fi
Expand All @@ -61,20 +82,6 @@ then
rm -r ${ssh_controlmasters_dir:?}/* 2>/dev/null # close all connections, to prevent any possible weird behaviour
ssh-add # Start using the new key

# prompt for continuing
while true
do
exec < /dev/tty
read -p $'\033[1m[networking]\033[0m: Your ssh key has been updated. If you use SSH for git, update your public key '\
'on the hosts before continuing. Continue? ' -n 1 -r
exec <&-
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
break
fi
echo -e "\033[1mPlease answer with 'y' to continue\033[0m"
done
fi

# Enable persistent connection multiplexing
Expand Down

0 comments on commit d01f6b8

Please sign in to comment.