11#! /usr/bin/env bash
2- set -eu
2+ # set -eu
3+ set +eu
34
45SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd ) "
56. " ${SCRIPT_DIR} /setup_common.sh"
7+ set +eu
68
79CONF_SCRIPT=" ${CONF_DIR} /setup_agent.sh"
810
911if [ ! -f " ${CONF_SCRIPT} " ]; then
10- echo " The agent configuration was not found at: ${CONF_SCRIPT} "
12+ echo " The SSH agent configuration was not found at: ${CONF_SCRIPT} "
1113 exit 1
1214fi
1315
14- echo " Configuring SSH agent."
16+ if ! pgrep -u " ${USER} " ' ^ssh-agent$' > /dev/null; then
17+ echo " Warning: No SSH agent seems to be running for the user \" ${USER} \" ."
18+ fi
19+
20+ echo " Configuring SSH agent using the socket \" ${SSH_AUTH_SOCK:- WARNING_NOT_SET} \" ."
1521
1622# Wait for kwallet
1723if command -v kwallet-query & > /dev/null; then
18- set +e
24+ # set +e
1925 kwallet-query -l kdewallet > /dev/null
2026 KWALLET_EXIT_CODE=$?
21- set -e
27+ # set -e
2228 if [ " ${KWALLET_EXIT_CODE} " -eq 4 ]; then
2329 echo " Warning: kwallet-query exited with code 4. "
2430 echo " Please create a folder named \" Passwords\" in KDE Wallet with e.g. KWalletManager."
@@ -27,10 +33,17 @@ if command -v kwallet-query &> /dev/null; then
2733 fi
2834fi
2935
30- echo " Removing existing identities."
36+ # echo "KDE Wallet is loaded. Waiting for SSH agent to be ready."
37+ # sleep 10
38+
39+ echo " Removing existing identities from the SSH agent."
3140ssh-add -D
41+ SSH_ADD_EXIT_CODE=$?
42+ if [ " ${SSH_ADD_EXIT_CODE} " -ne 0 ]; then
43+ echo " Warning: ssh-add -D exited with code ${SSH_ADD_EXIT_CODE} . Future ssh-add commands may fail as well."
44+ fi
3245
33- echo " Adding new identities."
46+ echo " Adding new identities to the SSH agent ."
3447# Warning! All added keys that are used for multiple devices
3548# must be on FIDO2 security keys and require physical confirmation.
3649# Otherwise the server you connect to can use the SSH keys
@@ -41,13 +54,13 @@ echo "Adding new identities."
4154LIBTPM2_PKCS11=" /usr/lib/x86_64-linux-gnu/pkcs11/libtpm2_pkcs11.so"
4255LIBTPM2_PKCS11_OLD=" /usr/lib/x86_64-linux-gnu/libtpm2_pkcs11.so.1"
4356if [ -f " ${LIBTPM2_PKCS11} " ]; then
44- set +e
57+ # set +e
4558 ssh-add -s " ${LIBTPM2_PKCS11} "
46- set -e
59+ # set -e
4760elif [ -f " ${LIBTPM2_PKCS11_OLD} " ]; then
48- set +e
61+ # set +e
4962 ssh-add -s " ${LIBTPM2_PKCS11_OLD} "
50- set -e
63+ # set -e
5164fi
5265
5366# The id_rsa is only used for specific purposes
5972# https://www.linux.fi/wiki/HST#Ssh_2
6073OPENSC_PKCS11=" /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so"
6174if [ -f " ${OPENSC_PKCS11} " ]; then
62- set +e
75+ # set +e
6376 ssh-add -s " ${OPENSC_PKCS11} "
64- set -e
77+ # set -e
6578fi
6679
6780. " ${CONF_SCRIPT} "
6881
69- echo " Configured identities:"
82+ echo " Configured identities in the SSH agent :"
7083ssh-add -L
0 commit comments