0
0
mirror of https://github.com/termux/termux-packages.git synced 2025-08-05 09:30:35 +00:00
Files
termux-packages/packages/openssh/sv/ssh-agent.run.in
Henrik Grimler a54156ae68 fix(main/openssh): rm ssh-agent socket file in service script
ssh-agent fails to run if the termux is force-stopped or the device is
rebooted, with error:

    unix_listener: cannot bind to path $PREFIX/var/run/ssh-agent.socket: Address already in use

Workaround it by removing the socket file before starting ssh-agent.
2025-07-30 15:48:55 +02:00

28 lines
1.0 KiB
Bash

#!@TERMUX_PREFIX@/bin/sh
# Run `sv-enable ssh-agent` and add the following to your bashrc (or
# equivalent) to use ssh-agent:
# export SSH_AUTH_SOCK="$PREFIX"/var/run/ssh-agent.socket
# After that you can add your key to the agent with `ssh-add`, and
# then make use of the credentials across all terminal sessions
service_agent() {
# If agent is not turned off before device is rebooted or
# termux force-stopped, then it fails to start with:
# unix_listener: cannot bind to path /data/data/com.termux/files/usr/var/run/ssh-agent.socket: Address already in use
# Therefore unlink socket file before trying to use it
if [ -S "$1" ]; then
unlink "$1"
fi
exec ssh-agent -D -a "$1" 2>&1
}
# Allow overriding the service_agent function easily.
if [ -r "${TERMUX__PREFIX:-"${PREFIX}"}"/etc/ssh/start_agent.sh ]; then
. "${TERMUX__PREFIX:-"${PREFIX}"}"/etc/ssh/start_agent.sh
fi
export SSH_AUTH_SOCK="${XDG_RUNTIME_DIR:-"${TERMUX__PREFIX:-"${PREFIX}"}/var/run"}"/ssh-agent.socket
service_agent "${SSH_AUTH_SOCK}"