Skip to content

Commit

Permalink
Feat: SSH file name based on algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
yakuhzi committed Nov 1, 2023
1 parent 7a3ad67 commit 5e571fa
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@ import fs from 'fs'
function run(): void {
try {
const sshDir = `${process.env.HOME}/.ssh`
const privateFile = `${sshDir}/id_rsa`
const publicFile = `${sshDir}/id_rsa.pub`

const publicKey = core.getInput('ssh-public-key')
const privateKey = core.getInput('ssh-private-key')
const algorithm = publicKey.split(' ')[0].split('-')[1]
const privateFile = `${sshDir}/id_${algorithm}`
const publicFile = `${sshDir}/id_${algorithm}.pub`

fs.mkdirSync(`${sshDir}`, { recursive: true })
fs.writeFileSync(publicFile, publicKey)
fs.writeFileSync(privateFile, privateKey)
fs.chmodSync(privateFile, '600')

childProcess.execSync(
'for ip in $(dig @8.8.8.8 github.com +short); do ssh-keyscan github.com,$ip; ' +
'ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts',
)

fs.writeFileSync(publicFile, core.getInput('ssh-public-key'))
fs.writeFileSync(privateFile, core.getInput('ssh-private-key'))

fs.chmodSync(privateFile, '600')

childProcess.execSync('eval "$(ssh-agent -s)"')
childProcess.execSync(`ssh-add -K ${sshDir}/id_rsa`)
childProcess.execSync(`ssh-add --apple-use-keychain ${sshDir}/id_${algorithm}`)
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message)
Expand Down

0 comments on commit 5e571fa

Please sign in to comment.