2021-02-18 10:11:44 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-10-31 16:12:41 +01:00
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
# An script to lazy-add all of my SSH keys to keychain or ssh-agent (if left blank) or
|
|
|
|
# auto-load an specific ssh key when $1 is defined.
|
|
|
|
|
|
|
|
if [[ $1 != "" ]]; then
|
2021-06-27 08:12:42 +02:00
|
|
|
echo "==> Adding your SSH key ($1) to SSH agent..."
|
2022-10-31 16:12:41 +01:00
|
|
|
ssh-add $HOME/.ssh/$1
|
|
|
|
elif [[ $1 == "" ]]; then
|
2021-06-27 08:12:42 +02:00
|
|
|
echo "==> Adding all of your SSH keys from ~/.ssh directory..."
|
2022-10-31 16:12:41 +01:00
|
|
|
for key in ~/.ssh/*; do
|
|
|
|
if [[ $key == "$HOME/.ssh/*config" ]] || [[ $key == "$HOME/.ssh/*known_hosts*" ]]; then
|
|
|
|
true
|
|
|
|
elif [[ $key == "$HOME/.ssh/*.pub" ]]; then
|
|
|
|
true
|
|
|
|
else
|
|
|
|
if command -v keychain >> /dev/null; then
|
|
|
|
eval "$(keychain --eval $key)"
|
|
|
|
else
|
|
|
|
ssh-add "$key"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2021-02-27 17:02:24 +01:00
|
|
|
fi
|