From ee91f79cb6a3b1cb8fe86fbfeaaec4f5698d82c6 Mon Sep 17 00:00:00 2001 From: Midgard <2885-Midgard@users.noreply.framagit.org> Date: Thu, 13 Jun 2019 19:20:54 +0200 Subject: [PATCH] [lock.sh] Handle SSH agent off, don't check i3lock retval Give a more appropriate message when no SSH agent is running. In newer versions of i3lock, the return value isn't useful any more. --- i3/lock.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/i3/lock.sh b/i3/lock.sh index ec793a2..344f5b4 100755 --- a/i3/lock.sh +++ b/i3/lock.sh @@ -1,13 +1,19 @@ #!/bin/bash -if ! ssh-add -D; then - notify-send -u normal -i lock -a i3 'Failed to clear SSH key cache' 'ssh-add had a non-zero exit code.' +set -euo pipefail + +ssh_agent_file="/run/user/$EUID/ssh-agent-session" +if pgrep -u "$USER" ssh-agent > /dev/null && [[ -f "$ssh_agent_file" ]]; then + source "$ssh_agent_file" + if ! ssh-add -D; then + notify-send -u normal -i lock -a i3 'Failed to clear SSH key cache' 'ssh-add had a non-zero exit code.' + fi +else + notify-send -u normal -i lock -a i3 'No SSH agent running' 'No running SSH agent detected, so not clearing the key cache.' fi if ! gpg-connect-agent reloadagent /bye; then notify-send -u normal -i lock -a i3 'Failed to clear GPG key cache' 'gpg-connect-agent had a non-zero exit code.' fi -if ! i3lock --tiling --lock-console --show-failed-attempts --color=000000 --image="$HOME/img/bg/Red-billed_streamertail_Trochilus_polytmus_female_in_flight_2_lock.png"; then - notify-send -u normal -i lock -a i3 'Failed to lock screen' 'i3lock had a non-zero exit code.' -fi +exec i3lock --tiling --lock-console --show-failed-attempts --color=000000 --image="$HOME/img/bg/Red-billed_streamertail_Trochilus_polytmus_female_in_flight_2_lock.png"