aboutsummaryrefslogtreecommitdiff
path: root/dot_config/hypr/scripts/executable_ssh-agent-session
blob: 6a05ba858aadebed93e8883c1c08ebf7d371436c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 #!/bin/sh

  agent_socket="${XDG_RUNTIME_DIR:?XDG_RUNTIME_DIR is not set}/ssh-agent.sock"

  SSH_AUTH_SOCK="$agent_socket" /usr/bin/ssh-add -l >/dev/null 2>&1
  agent_status=$?

  case "$agent_status" in
      0|1)
          # Agent exists; status 1 only means it currently has no keys.
          exit 0
          ;;
      2)
          # No reachable agent. Remove only its stale runtime socket.
          rm -f -- "$agent_socket"
          exec /usr/bin/ssh-agent \
              -D \
              -a "$agent_socket" \
              -t 8h
          ;;
      *)
          exit "$agent_status"
          ;;
  esac