consolidate ssh utils
[webi-installers/.git] / ssh-utils / ssh-pubkey.sh
1 #!/bin/bash
2
3 set -e
4 set -u
5
6 mkdir -p "$HOME/.ssh/"
7
8 if [ ! -f "$HOME/.ssh/id_rsa" ]; then
9     ssh-keygen -b 2048 -t rsa -f "$HOME/.ssh/id_rsa" -q -N ""
10     echo ""
11 fi
12
13 if [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then
14     ssh-keygen -y -f "$HOME/.ssh/id_rsa" > "$HOME/.ssh/id_rsa.pub"
15     echo ""
16 fi
17
18 # TODO use the comment (if any) for the name of the file
19 echo ""
20 echo "~/Downloads/id_rsa.$(whoami).pub":
21 echo ""
22 rm -f "$HOME/Downloads/id_rsa.$(whoami).pub":
23 cp -r "$HOME/.ssh/id_rsa.pub" "$HOME/Downloads/id_rsa.$(whoami).pub"
24 cat "$HOME/Downloads/id_rsa.$(whoami).pub"
25 echo ""