Skip to content

Commit

Permalink
✨ improve key generation process
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhomer committed Nov 19, 2023
1 parent f521c02 commit 5f065d8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bin/dotme-apk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ log:: "updating apk"
apk add bash
apk add curl
apk add git
apk add openssh-client
apk add openssh-keygen
apk add python3
apk add stow

Expand Down
39 changes: 37 additions & 2 deletions bin/dotme-key
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
#!/usr/bin/env bash

$(shim) && cd ${ME} && . bin/i.sh

OPTIND=1
while getopts "hn:" o; do case "$o" in
h) help="y" ;;
n) key_name=$OPTARG ;; # Qualifying name of key file
esac done

if [[ -n "$help" ]] ; then
cat <<EOF
Usage
Set up a default key
dotme-key
Use a different email address
dotme-key [email protected]
Use a different key name, e.g. ~/.ssh/id_dotme_alt
dotme-key -n alt
EOF
exit
fi


log::info "Setting up SSH key"

if [[ -z "$1" ]] ; then
Expand All @@ -16,7 +43,11 @@ if [[ -z "$MY_EMAIL" ]] ; then
exit 1
fi

keyFile=~/.ssh/id_dotme
if [[ -n "${key_name}" ]] ; then
keyFile=~/.ssh/id_dotme_${key_name}
else
keyFile=~/.ssh/id_dotme
fi

if [[ ! -f $keyFile ]] ; then
log:: "... creating SSH key for : $MY_EMAIL"
Expand All @@ -39,8 +70,12 @@ if [[ ! -f ${sshConfig} ]] ; then
cat <<EOF > ${sshConfig}
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ${keyFile}
EOF
if is-macos ; then
cat <<EOF >> ${sshConfig}
UseKeychain yes
EOF
fi
fi

0 comments on commit 5f065d8

Please sign in to comment.