Skip to content

Commit

Permalink
Fix for inline / inner double quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian-panek-vmltech committed Nov 16, 2023
1 parent 3debbbd commit 02e4a74
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ func (c Client) envScriptString() string {
return utils.EnvToScript(c.Env)
}

func (c Client) RunShellCommand(cmd string, dir string) ([]byte, error) {
if dir == "" || dir == "." {
return c.RunShellPurely(fmt.Sprintf("source %s && %s", c.envScriptPath(), cmd))
}
return c.RunShellPurely(fmt.Sprintf("source %s && cd %s && %s", c.envScriptPath(), dir, cmd))
}

func (c Client) RunShellScript(cmdName string, cmdScript string, dir string) ([]byte, error) {
remotePath := fmt.Sprintf("%s/%s.sh", c.WorkDir, cmdName)
if err := c.FileWrite(remotePath, cmdScript); err != nil {
Expand All @@ -103,6 +96,13 @@ func (c Client) RunShellScript(cmdName string, cmdScript string, dir string) ([]
return c.RunShellCommand(fmt.Sprintf("sh %s", remotePath), dir)
}

func (c Client) RunShellCommand(cmd string, dir string) ([]byte, error) {
if dir == "" || dir == "." {
return c.RunShellPurely(fmt.Sprintf("source %s && %s", c.envScriptPath(), cmd))
}
return c.RunShellPurely(fmt.Sprintf("source %s && cd %s && %s", c.envScriptPath(), dir, cmd))
}

func (c Client) RunShellPurely(cmd string) ([]byte, error) {
var cmdLine []string
if c.Sudo {
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/instance_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (ic *InstanceClient) runScript(name string, script InstanceScript, dir stri
if len(inlineCmds) > 0 {
for i, cmd := range inlineCmds {
tflog.Info(ic.ctx, fmt.Sprintf("Executing command '%s' of script '%s' (%d/%d)", cmd, name, i+1, len(inlineCmds)))
textOut, err := ic.cl.RunShellCommand(cmd, dir)
textOut, err := ic.cl.RunShellScript(name, cmd, dir)
if err != nil {
return fmt.Errorf("unable to execute command '%s' of script '%s' properly: %w", cmd, name, err)
}
Expand Down

0 comments on commit 02e4a74

Please sign in to comment.