diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2016-07-25 17:03:17 +0200 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2016-07-29 02:32:54 +0100 |
commit | 4cebe1ac6b50c7bc74313e26d44c4fc0af8886aa (patch) | |
tree | d33233488eac0023ec3a4e5e7edd0180b53318b1 /debian/agent-launch | |
parent | 556ee3d2d433dc70512003667398f0979b0940a9 (diff) |
Add debian/agent-launch: Helper script for conditionally starting the SSH agent in the user session
Use it in ssh-agent.user-session.upstart. This will also be used in a
corresponding systemd user unit.
This replaces the backgrounded "ssh-agent -s" with a foreground task which
works more nicely with modern init systems for logging/debugging and
starting/stopping.
Also use a fixed socket file name in $XDG_RUNTIME_DIR -- under both upstart and
systemd we can assume this, and it allows restarting the service in a running
session.
Diffstat (limited to 'debian/agent-launch')
-rwxr-xr-x | debian/agent-launch | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/debian/agent-launch b/debian/agent-launch new file mode 100755 index 000000000..40479b868 --- /dev/null +++ b/debian/agent-launch | |||
@@ -0,0 +1,29 @@ | |||
1 | #!/bin/sh | ||
2 | # helper script for launching ssh-agent, used by systemd unit and upstart job | ||
3 | set -e | ||
4 | |||
5 | if [ ! -d "$XDG_RUNTIME_DIR" ]; then | ||
6 | echo 'This needs $XDG_RUNTIME_DIR to be set' >&2 | ||
7 | exit 1 | ||
8 | fi | ||
9 | |||
10 | if [ "$1" = start ]; then | ||
11 | if [ -z "$SSH_AUTH_SOCK" ] && grep -s -q '^use-ssh-agent$' /etc/X11/Xsession.options; then | ||
12 | S="$XDG_RUNTIME_DIR/openssh_agent" | ||
13 | dbus-update-activation-environment --verbose --systemd SSH_AUTH_SOCK=$S SSH_AGENT_LAUNCHER=openssh | ||
14 | if type initctl >/dev/null 2>&1; then | ||
15 | initctl set-env --global SSH_AUTH_SOCK=$S | ||
16 | fi | ||
17 | exec ssh-agent -D -a $S | ||
18 | fi | ||
19 | elif [ "$1" = stop ]; then | ||
20 | if [ "$SSH_AGENT_LAUNCHER" = openssh ]; then | ||
21 | dbus-update-activation-environment --systemd SSH_AUTH_SOCK= | ||
22 | if type initctl >/dev/null 2>&1; then | ||
23 | initctl unset-env --global SSH_AUTH_SOCK | ||
24 | fi | ||
25 | fi | ||
26 | else | ||
27 | echo "Unknown command $1" >&2 | ||
28 | exit 1 | ||
29 | fi | ||