Switched to OS version of write file

This commit is contained in:
Leon Mika 2024-07-13 11:13:40 +10:00
parent 70c024b387
commit e872bcccae

View file

@ -24,18 +24,14 @@ func (s *Services) AddPrivateKey() error {
return err return err
} }
if err := writeFile(`${HOME}/.ssh/id_rsa`, s.cfg.PrivateKey, 0400); err != nil {
return err
}
if err := runCmd(`chmod 700 $HOME/.ssh`); err != nil { if err := runCmd(`chmod 700 $HOME/.ssh`); err != nil {
return err return err
} }
if err := writeFile(`${HOME}/.ssh/id_rsa`, s.cfg.PrivateKey); err != nil {
return err
}
if err := runCmd(`chmod -R 400 $HOME/.ssh/.`); err != nil {
return err
}
return nil return nil
} }
@ -53,11 +49,7 @@ func (s *Services) ConfigureSSH() error {
return err return err
} }
if err := writeFile(`${HOME}/.ssh/config`, bfr.String()); err != nil { if err := writeFile(`${HOME}/.ssh/config`, bfr.String(), 0400); err != nil {
return err
}
if err := runCmd(`chmod 400 $HOME/.ssh/config`); err != nil {
return err return err
} }
@ -91,12 +83,11 @@ func runCmd(cmd string) error {
return script.Exec(fullCmd).Error() return script.Exec(fullCmd).Error()
} }
func writeFile(path string, content string) error { func writeFile(path string, content string, mode os.FileMode) error {
fullPath := os.ExpandEnv(path) fullPath := os.ExpandEnv(path)
log.Printf(" .. [file] %v", fullPath) log.Printf(" .. [file] %v", fullPath)
_, err := script.Echo(content).WriteFile(fullPath) return os.WriteFile(fullPath, []byte(content), mode)
return err
} }
var ( var (