Skip to content

Commit

Permalink
fix: get ssh agent details via regex instead
Browse files Browse the repository at this point in the history
doesn't seem like eval persists the environment variables
  • Loading branch information
Sn0wCrack committed Sep 19, 2024
1 parent dca1d5d commit 7e185f2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ async function ssh() {
fs.mkdirSync(sshHomeDir)
}

await $`eval \`ssh-agent\``
const sshAgentOutput = await $`ssh-agent`

const sshAgentSocket = await $`echo \$SSH_AUTH_SOCKET`
const sshAgentSocket = sshAgentOutput
.stdout
.match(/SSH_AUTH_SOCK=(?<path>.*); export SSH_AUTH_SOCK;/)
?.groups['path'] ?? null;

const sshAgentProcessId = await $`echo \$SSH_AGENT_PID`
const sshAgentProcessId = sshAgentOutput
.stdout
.match(/SSH_AGENT_PID=(?<pid>\d+); export SSH_AGENT_PID;/)
?.groups['pid'] ?? null;

if (!sshAgentSocket || !sshAgentProcessId) {
throw new Error('Failed to start ssh-agent')
Expand Down

0 comments on commit 7e185f2

Please sign in to comment.