improved script to start ssh-agent only if not started

also gets the socket environment set in the the call to unlock
master
David Kebler 2023-12-21 11:03:09 -08:00
parent be41e228fe
commit 3052888b9f
1 changed files with 20 additions and 11 deletions

View File

@ -1,14 +1,23 @@
#!/bin/bash #!/bin/bash
_dir="$(dirname $(realpath "${BASH_SOURCE:-$0}"))" _dir="$(dirname $(realpath "${BASH_SOURCE:-$0}"))"
if systemctl --user cat ssh-agent &> /dev/null ; then if systemctl --user is-active ssh-agent; then
echo starting user ssh-agent echo starting keepass unlock for $1
systemctl --user restart ssh-agent BASH_ENV=$HOME/ssh-agent.properties $_dir/keepassxc-unlock.sh "$@"
echo agent socket should be ssh-agent.sock not keyring else
env | grep SSH_AUTH if systemctl --user list-unit-files "ssh-agent.service"; then
echo sourcing ssh-agent properties at $HOME/ssh-agent.properties echo starting user ssh-agent
cat $HOME/ssh-agent.properties if systemctl --user restart ssh-agent;then
source $HOME/ssh-agent.properties sleep 2
$_dir/keepassxc-unlock.sh "$@" cat $HOME/ssh-agent.properties
else echo starting keepass unlock for $1
no ssh-agent service file for user $USER BASH_ENV=$HOME/ssh-agent.properties $_dir/keepassxc-unlock.sh "$@"
else
echo unable to start ssh-agent
fi
else
echo can not start ageent, no user unit file ssh-agent.service for user $USER
fi
fi fi