Skip to content

Commit

Permalink
fix: .ssh config file generation
Browse files Browse the repository at this point in the history
  • Loading branch information
seriouspoop committed Oct 23, 2024
1 parent 36bc519 commit 4f74e54
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions svc/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package svc

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -190,13 +191,14 @@ func (s *Svc) SetRemoteSSHAuth() error {
utils.Logger(utils.LOG_SUCCESS, "keys generated")
// add keys to known hosts
hostCode := fmt.Sprintf("Host %s\n AddKeysToAgent yes\n IdentityFile \"%s\"", remoteDetails.Provider().HostURL(), filepath.Join(gopushDirPath, keyName))

fileContent, err := os.ReadFile(filepath.Join(os.Getenv("HOME"), ".ssh", "config"))
if err != nil {
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
fileContent = []byte(strings.Join([]string{string(fileContent), hostCode}, "\n"))
err = os.Remove(filepath.Join(os.Getenv("HOME"), ".ssh", "config"))
if err != nil {
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
err = os.WriteFile(filepath.Join(os.Getenv("HOME"), ".ssh", "config"), fileContent, 0777)
Expand Down

0 comments on commit 4f74e54

Please sign in to comment.