support newer ssh-add

master
Carlo Capocasa 7 years ago
parent 55bfc353d3
commit bc2a28566d

@ -13,19 +13,31 @@ then
systemctl -q is-active user@$(id -u ${PAM_USER}) || exit 0 systemctl -q is-active user@$(id -u ${PAM_USER}) || exit 0
# Re-execute this script as the user to add their key (while piping STDIN) # Re-execute this script as the user to add their key (while piping STDIN)
cat | exec su ${PAM_USER} -c $(realpath ${BASH_SOURCE[0]}) cat | exec su ${PAM_USER} -c "$0 initialize"
# Handle adding the key as the user # Handle adding the key as the user
else else
# We need to specify the XDG_RUNTIME_DIR because pam_systemd won't have run
export XDG_RUNTIME_DIR=/run/user/$(id -u)
# Get the SSH_AUTH_SOCK variable from the user session # Add key
export $(systemctl --user show-environment | grep ^SSH_AUTH_SOCK=) if [ "$1" = "initialize" ]; then
# We need to specify the XDG_RUNTIME_DIR because pam_systemd won't have run
export XDG_RUNTIME_DIR=/run/user/$(id -u)
# Ensure the ssh-agent service is started # Get the SSH_AUTH_SOCK variable from the user session
systemctl --user start ssh-agent export $(systemctl --user show-environment | grep ^SSH_AUTH_SOCK=)
ssh-add
exit 0 # Ensure the ssh-agent service is started
systemctl --user start ssh-agent
# Newer ssh-add won't read passphrase from stdin but will pipe it to askpass
export SSH_ASKPASS="$0"
cat | ssh-add
exit 0
# Double as askpass
else
cat
exit 0
fi
fi fi

Loading…
Cancel
Save