From 3052888b9feb28f8903ce39cc4eed10e96a602ca Mon Sep 17 00:00:00 2001 From: David Kebler Date: Thu, 21 Dec 2023 11:03:09 -0800 Subject: [PATCH] improved script to start ssh-agent only if not started also gets the socket environment set in the the call to unlock --- apps/keepassxc/keepassxc-ssh-unlock.sh | 31 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/apps/keepassxc/keepassxc-ssh-unlock.sh b/apps/keepassxc/keepassxc-ssh-unlock.sh index 1ca8a31..950fbd8 100755 --- a/apps/keepassxc/keepassxc-ssh-unlock.sh +++ b/apps/keepassxc/keepassxc-ssh-unlock.sh @@ -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 "$@" -else -no ssh-agent service file for user $USER +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 + 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 + + +