Skip to content

Commit

Permalink
Fix SSH agent on Wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
AgenttiX committed Oct 31, 2024
1 parent 9ebe4f4 commit 3d13306
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .profile
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ fi

# Pre-startup scripts don't seem to work on Plasma Wayland,
# and therefore the pre-startup script has to be loaded here.
. "${HOME}/Git/linux-scripts/startup/agx-user-pre-startup.sh"
# . "${HOME}/Git/linux-scripts/startup/agx-user-pre-startup.sh"
if [ -f "${HOME}/.ssh-agent-info" ]; then
eval "$(<"${HOME}/.ssh-agent-info")" > /dev/null
fi
19 changes: 15 additions & 4 deletions startup/agx-user-pre-startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@
export SSH_ASKPASS="/usr/bin/ksshaskpass"
export SSH_ASKPASS_REQUIRE=prefer

if ! pgrep -u "${USER}" ssh-agent > /dev/null; then
# Wait for kwallet
# This is necessary on Wayland, but not on X11
# if command -v kwallet-query &> /dev/null; then
# kwallet-query -l kdewallet > /dev/null
# fi

SSH_AGENT_UPDATED=false
# Pgrep finds regexes, and without the specification for the start and end of the line,
# it could find e.g. the gcr-ssh-agent provided by the package gcr,
# and not start the correct SSH agent.
if ! pgrep -u "${USER}" '^ssh-agent$' > /dev/null; then
# echo "SSH agent seems not to be started. Starting, and saving its configuration."
ssh-agent > ~/.ssh-agent-info
ssh-agent > "${HOME}/.ssh-agent-info"
SSH_AGENT_UPDATED=true
fi
if [[ "${SSH_AGENT_PID}" == "" ]]; then
if [[ "${SSH_AGENT_PID}" == "" ]] || [ "${SSH_AGENT_UPDATED}" = true ]; then
# echo "SSH agent configuration seems not to be loaded. Loading."
eval "$(<~/.ssh-agent-info)" > /dev/null
eval "$(<"${HOME}/.ssh-agent-info")" > /dev/null
fi

# echo "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}" >> "${LOG_PATH}"
Expand Down
6 changes: 5 additions & 1 deletion startup/agx-user-startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ set -u
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
REPO_DIR="$(dirname "${SCRIPT_DIR}")"

if command -v kwallet-query &> /dev/null; then
kwallet-query -l kdewallet > /dev/null
fi

# Run the pre-startup script again to ensure that the SSH agent is available
# . "${SCRIPT_DIR}/agx-user-pre-startup.sh"
. "${SCRIPT_DIR}/agx-user-pre-startup.sh"

echo "Starting SSH agent configuration script."
SETUP_AGENT="${REPO_DIR}/ssh/setup_agent.sh"
Expand Down
7 changes: 5 additions & 2 deletions zsh/.zshenv
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
ZDOTDIR="${HOME}/Git/linux-scripts/zsh"

if [ -f "${HOME}/.cargo/env" ]; then
. "${HOME}/.cargo/env"
. "${HOME}/.cargo/env"
fi

# Pre-startup scripts don't seem to work on Plasma Wayland,
# and therefore the pre-startup script has to be loaded here.
. "${HOME}/Git/linux-scripts/startup/agx-user-pre-startup.sh"
# . "${HOME}/Git/linux-scripts/startup/agx-user-pre-startup.sh"
if [ -f "${HOME}/.ssh-agent-info" ]; then
eval "$(<"${HOME}/.ssh-agent-info")" > /dev/null
fi

0 comments on commit 3d13306

Please sign in to comment.