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
_dir="$(dirname $(realpath "${BASH_SOURCE:-$0}"))"
if systemctl --user cat ssh-agent &> /dev/null ; then
echo starting user ssh-agent
systemctl --user restart ssh-agent
echo agent socket should be ssh-agent.sock not keyring
env | grep SSH_AUTH
echo sourcing ssh-agent properties at $HOME/ssh-agent.properties
cat $HOME/ssh-agent.properties
source $HOME/ssh-agent.properties
$_dir/keepassxc-unlock.sh "$@"
if systemctl --user is-active ssh-agent; then
echo starting keepass unlock for $1
BASH_ENV=$HOME/ssh-agent.properties $_dir/keepassxc-unlock.sh "$@"
else
no ssh-agent service file for user $USER
if systemctl --user list-unit-files "ssh-agent.service"; then
echo starting user ssh-agent
if systemctl --user restart ssh-agent;then
sleep 2
cat $HOME/ssh-agent.properties
echo starting keepass unlock for $1
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