Skip to content

Commit

Permalink
Use printf instead of $'' to pass a multi-line string to bash
Browse files Browse the repository at this point in the history
The script will be executed by the default shell of the ssh user,
and `fish` does not support the $'' syntax.

Signed-off-by: Jan Dubois <[email protected]>
  • Loading branch information
jandubois committed Nov 8, 2024
1 parent 7df86f9 commit b2cfd6a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/hostagent/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hostagent
import (
"errors"
"fmt"
"strings"
"time"

"github.com/lima-vm/lima/pkg/limayaml"
Expand Down Expand Up @@ -77,7 +78,11 @@ func prefixExportParam(script string) (string, error) {

// TODO we should have a symbolic constant for `/mnt/lima-cidata`
exportParam := `while read -r line; do [ -n "$line" ] && export "$line"; done<<EOF\n$(sudo cat /mnt/lima-cidata/param.env)\nEOF\n`
return fmt.Sprintf("#!/bin/bash -c $'%s%s'\n%s", exportParam, interpreter, script), nil

// double up all '%' characters so we can pass them through unchanged in the format string of printf
interpreter = strings.ReplaceAll(interpreter, "%", "%%")
exportParam = strings.ReplaceAll(exportParam, "%", "%%")
return fmt.Sprintf("#!/bin/bash -c \"$(printf \"%s%s\")\"\n%s", exportParam, interpreter, script), nil
}

func (a *HostAgent) waitForRequirement(r requirement) error {
Expand Down

0 comments on commit b2cfd6a

Please sign in to comment.