Skip to content

Commit

Permalink
Upload to tmpfile and install into place on linux (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
kke authored Apr 22, 2021
1 parent b8484ff commit 4224870
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ func (c *SSH) uploadLinux(src, dst string) error {
}
defer in.Close()

var tmpFile string
if err := c.Exec("mktemp 2> /dev/null", exec.Output(&tmpFile)); err != nil {
return err
}
defer func() { _ = c.Exec(fmt.Sprintf("rm -f %s", shellescape.Quote(tmpFile))) }()
tmpFile = strings.TrimSpace(tmpFile)

session, err := c.client.NewSession()
if err != nil {
return err
Expand All @@ -358,7 +365,7 @@ func (c *SSH) uploadLinux(src, dst string) error {
return err
}

err = session.Start(fmt.Sprintf(`gzip -d > %s`, shellescape.Quote(dst)))
err = session.Start(fmt.Sprintf(`gzip -d > %s`, shellescape.Quote(tmpFile)))
if err != nil {
return err
}
Expand All @@ -369,7 +376,11 @@ func (c *SSH) uploadLinux(src, dst string) error {
gw.Close()
hostIn.Close()

return session.Wait()
if err := session.Wait(); err != nil {
return err
}

return c.Exec(fmt.Sprintf("sudo install -D %s %s", shellescape.Quote(tmpFile), shellescape.Quote(dst)))
}

func (c *SSH) uploadWindows(src, dst string) error {
Expand Down

0 comments on commit 4224870

Please sign in to comment.