mirror of
https://github.com/Matir/skel.git
synced 2026-05-25 21:19:09 -07:00
Compare commits
4 Commits
2510f1ad87
...
ce973d5bbf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce973d5bbf | ||
|
|
f326992306 | ||
|
|
7f76b24cb9 | ||
|
|
a5b08680c5 |
@@ -97,31 +97,87 @@ export EARTHLY_SSH_AUTH_SOCK=""
|
|||||||
|
|
||||||
# Handle SSH_AUTH_SOCK for tmux consistency
|
# Handle SSH_AUTH_SOCK for tmux consistency
|
||||||
_SSH_AUTH_LINK="${HOME}/.ssh/ssh_auth_sock"
|
_SSH_AUTH_LINK="${HOME}/.ssh/ssh_auth_sock"
|
||||||
if [ -z "${SSH_AUTH_SOCK:-}" ] || [ ! -S "${SSH_AUTH_SOCK}" ] ; then
|
|
||||||
# Try to find a working GPG agent SSH socket if no agent is set or current is broken
|
# Helper to check if a path is our link or points to it
|
||||||
if command -v gpgconf >/dev/null 2>&1; then
|
_is_link_path() {
|
||||||
_GPG_SSH_SOCK=$(gpgconf --list-dirs agent-ssh-socket 2>/dev/null)
|
[ -z "$1" ] && return 1
|
||||||
|
[ "$1" = "${_SSH_AUTH_LINK}" ] && return 0
|
||||||
|
if [ -L "$1" ] && command -v readlink >/dev/null 2>&1; then
|
||||||
|
_T=$(readlink "$1")
|
||||||
|
# Handle relative symlinks
|
||||||
|
case "${_T}" in /*) ;; *) _T="$(dirname "$1")/${_T}" ;; esac
|
||||||
|
[ "${_T}" = "${_SSH_AUTH_LINK}" ] && return 0
|
||||||
fi
|
fi
|
||||||
# Fallback to common paths if gpgconf fails or isn't present
|
return 1
|
||||||
if [ -z "${_GPG_SSH_SOCK}" ] || [ ! -S "${_GPG_SSH_SOCK}" ]; then
|
}
|
||||||
_GPG_SSH_SOCK="${GNUPGHOME:-$HOME/.gnupg}/S.gpg-agent.ssh"
|
|
||||||
[ -S "$_GPG_SSH_SOCK" ] || _GPG_SSH_SOCK="/run/user/$(id -u)/gnupg/S.gpg-agent.ssh"
|
_CANDIDATE=""
|
||||||
|
|
||||||
|
# 1. If current environment has a valid socket that is NOT our link, it's a prime candidate (e.g. SSH forwarding).
|
||||||
|
if [ -S "${SSH_AUTH_SOCK:-}" ] && ! _is_link_path "${SSH_AUTH_SOCK}"; then
|
||||||
|
_CANDIDATE="${SSH_AUTH_SOCK}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -S "${_GPG_SSH_SOCK}" ] ; then
|
# 2. If no candidate yet, or we're currently using the link, try to find the "real" system agent.
|
||||||
export SSH_AUTH_SOCK="$_GPG_SSH_SOCK"
|
if [ -z "${_CANDIDATE}" ] || _is_link_path "${SSH_AUTH_SOCK:-}"; then
|
||||||
|
_FOUND=""
|
||||||
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
|
_FOUND=$(launchctl getenv SSH_AUTH_SOCK 2>/dev/null)
|
||||||
|
elif command -v systemctl >/dev/null 2>&1; then
|
||||||
|
# Query systemd socket units directly to avoid environment overrides.
|
||||||
|
for _u in ssh-agent.socket openssh-agent.socket gcr-ssh-agent.socket gpg-agent-ssh.socket; do
|
||||||
|
_P=$(systemctl --user show "${_u}" -p Listen 2>/dev/null | cut -d= -f2- | cut -d' ' -f1)
|
||||||
|
if [ -S "${_P}" ]; then
|
||||||
|
_FOUND="${_P}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# Fallback to systemd environment
|
||||||
|
if [ -z "${_FOUND}" ] || _is_link_path "${_FOUND}"; then
|
||||||
|
_FOUND=$(systemctl --user show-environment 2>/dev/null | grep "^SSH_AUTH_SOCK=" | cut -d= -f2-)
|
||||||
fi
|
fi
|
||||||
unset _GPG_SSH_SOCK
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If we have a valid socket but it's not our stable link, sync the link and use it.
|
if [ -S "${_FOUND}" ] && ! _is_link_path "${_FOUND}"; then
|
||||||
# This ensures tmux (using the static path) always finds the most recent agent.
|
_CANDIDATE="${_FOUND}"
|
||||||
if [ -S "${SSH_AUTH_SOCK:-}" ] && [ "${SSH_AUTH_SOCK}" != "${_SSH_AUTH_LINK}" ] ; then
|
fi
|
||||||
[ -d "$(dirname "${_SSH_AUTH_LINK}")" ] || mkdir -p "$(dirname "${_SSH_AUTH_LINK}")"
|
fi
|
||||||
ln -sf "${SSH_AUTH_SOCK}" "${_SSH_AUTH_LINK}"
|
|
||||||
|
# 3. Last resort: search common paths if we still don't have a valid candidate.
|
||||||
|
if [ ! -S "${_CANDIDATE}" ]; then
|
||||||
|
_U=$(id -u)
|
||||||
|
for _p in "/run/user/${_U}/keyring/ssh" "/run/user/${_U}/ssh-agent.socket" "/run/user/${_U}/openssh_agent" "/run/user/${_U}/gnupg/S.gpg-agent.ssh"; do
|
||||||
|
if [ -S "${_p}" ] && ! _is_link_path "${_p}"; then
|
||||||
|
_CANDIDATE="${_p}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ -z "${_CANDIDATE}" ]; then
|
||||||
|
# Build search path list based on what actually exists
|
||||||
|
_SEARCH=""
|
||||||
|
for _d in "/run/user/${_U}" /tmp; do [ -d "${_d}" ] && _SEARCH="${_SEARCH} ${_d}"; done
|
||||||
|
if [ -n "${_SEARCH}" ]; then
|
||||||
|
_CANDIDATE=$(find ${_SEARCH} -maxdepth 2 -type s -name 'agent.*' 2>/dev/null | grep -F -v "${_SSH_AUTH_LINK}" | head -n 1)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 4. Sync the stable link if we found a valid "real" socket.
|
||||||
|
if [ -S "${_CANDIDATE}" ] && ! _is_link_path "${_CANDIDATE}"; then
|
||||||
|
mkdir -p "$(dirname "${_SSH_AUTH_LINK}")"
|
||||||
|
ln -sf "${_CANDIDATE}" "${_SSH_AUTH_LINK}"
|
||||||
|
export SSH_AUTH_SOCK="${_SSH_AUTH_LINK}"
|
||||||
|
# Update systemd if present to keep everything in sync
|
||||||
|
if command -v systemctl >/dev/null 2>&1; then
|
||||||
|
systemctl --user set-environment SSH_AUTH_SOCK="${_SSH_AUTH_LINK}" 2>/dev/null
|
||||||
|
fi
|
||||||
|
elif [ -S "${_SSH_AUTH_LINK}" ]; then
|
||||||
|
# If we found nothing better but the link is valid, use it.
|
||||||
export SSH_AUTH_SOCK="${_SSH_AUTH_LINK}"
|
export SSH_AUTH_SOCK="${_SSH_AUTH_LINK}"
|
||||||
fi
|
fi
|
||||||
unset _SSH_AUTH_LINK
|
|
||||||
|
unset _SSH_AUTH_LINK _CANDIDATE _FOUND _T _P _U _u _SEARCH _d
|
||||||
|
unset -f _is_link_path
|
||||||
|
|
||||||
# Setup XDG-like dirs on MacOS
|
# Setup XDG-like dirs on MacOS
|
||||||
# Based on https://leebyron.com/til/mac-xdg/
|
# Based on https://leebyron.com/til/mac-xdg/
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ install_main() {
|
|||||||
# macOS specific Homebrew bundle installation
|
# macOS specific Homebrew bundle installation
|
||||||
if [[ "$(uname)" == "Darwin" ]] && have_command brew && [[ -f "${BASEDIR}/Brewfile" ]]; then
|
if [[ "$(uname)" == "Darwin" ]] && have_command brew && [[ -f "${BASEDIR}/Brewfile" ]]; then
|
||||||
verbose "Checking Homebrew bundle..."
|
verbose "Checking Homebrew bundle..."
|
||||||
brew bundle install --file="${BASEDIR}/Brewfile" --no-lock
|
brew bundle install --file="${BASEDIR}/Brewfile"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ "$INSTALL_KEYS" = 1 ]] && install_keys
|
[[ "$INSTALL_KEYS" = 1 ]] && install_keys
|
||||||
|
|||||||
Reference in New Issue
Block a user