forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit
More file actions
executable file
·32 lines (30 loc) · 1.27 KB
/
init
File metadata and controls
executable file
·32 lines (30 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
# Copyright (c) 2025 b-data GmbH
# Copyright (c) 2023 Microsoft Corporation
# Distributed under the terms of the MIT License.
#
# https://code.visualstudio.com/remote/advancedcontainers/sharing-git-credentials
# https://docs.github.com/en/authentication/connecting-to-github-with-ssh/working-with-ssh-key-passphrases?platform=windows
#
# Modified by b-data for seamless use with development containers.
set -e
if [ -z "$CODESPACES" ] && [ "$(command -v ssh-agent)" ]; then
if [ -z "$SSH_AUTH_SOCK" ]; then
# Check for a currently running instance of the agent
RUNNING_AGENT="$(pgrep -f 'ssh-agent -s' | wc -l | tr -d '[:space:]')"
if [ "$RUNNING_AGENT" = "0" ] || [ ! -f "$HOME/.ssh/ssh-agent" ]; then
mkdir -p -m 0700 "$HOME/.ssh"
# Launch a new instance of the agent
ssh-agent -s &> "$HOME/.ssh/ssh-agent"
fi
eval "$(cat "$HOME/.ssh/ssh-agent")" > /dev/null
fi
# Check the state of the currently running instance of the agent
# 0: running with key(s); 1: running w/o key(s); 2: not running
AGENT_RUN_STATE="$(ssh-add -l > /dev/null 2>&1; echo $?)"
# Only add key(s) if running w/o key(s)
if [ "$AGENT_RUN_STATE" = "1" ]; then
ssh-add 2> /dev/null || true
fi
# Means: Not adding key(s) to a forwarded agent with key(s)
fi