Skip to content

Commit d01f6b8

Browse files
ar13pitMatthijsBurgh
authored andcommitted
fix(networking): Ask for confirmation before updating ssh key
1 parent 7a5714a commit d01f6b8

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

networking/install.bash

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,29 @@ else
4747
# Generate new ssh key if length < 4096
4848
if [ "$(ssh-keygen -l -f "$ssh_key" | awk '{print $1}')" -lt 4096 ]
4949
then
50-
tue-install-info "Generating new ssh key as length < 4096, you might need to copy the new key to the robots, GitHub, etc."
51-
generate_ssh="true"
50+
# Ask user whether the ssh key should be updated
51+
while true
52+
do
53+
exec < /dev/tty
54+
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 "\
55+
"on the hosts. Do you want to update your key? " -n 1 -r
56+
exec <&-
57+
echo # (optional) move to a new line
58+
59+
if [[ $REPLY =~ ^[Yy]$ ]]
60+
then
61+
tue-install-info "Generating new ssh key as length < 4096, you might need to copy the new key to the robots, GitHub, etc."
62+
generate_ssh="true"
63+
break
64+
fi
65+
66+
if [[ $REPLY =~ ^[Nn]$ ]]
67+
then
68+
tue-install-info "Generating new ssh key as length < 4096, you might need to copy the new key to the robots, GitHub, etc."
69+
break
70+
fi
71+
echo -e "\033[1mPlease answer with 'y' or 'n' to continue\033[0m"
72+
done
5273
else
5374
tue-install-debug "ssh key available with length >= 4096"
5475
fi
@@ -61,20 +82,6 @@ then
6182
rm -r ${ssh_controlmasters_dir:?}/* 2>/dev/null # close all connections, to prevent any possible weird behaviour
6283
ssh-add # Start using the new key
6384

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

8087
# Enable persistent connection multiplexing

0 commit comments

Comments
 (0)