Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use printf instead of $'' to pass a multi-line string to bash #2874

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

jandubois
Copy link
Member

@jandubois jandubois commented Nov 8, 2024

The script will be executed by the default shell of the ssh user, and fish does not support the $'' syntax.

Fixes #2856

Seems to work:

$ limactl shell alpine
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
jan@lima-alpine /U/jan>

@jandubois jandubois marked this pull request as ready for review November 8, 2024 01:33
@jandubois jandubois mentioned this pull request Nov 8, 2024
@AkihiroSuda AkihiroSuda added this to the v1.0.1 milestone Nov 8, 2024
@jandubois
Copy link
Member Author

Seems like TEST| [INFO] Testing that PARAM env variables are exported to all types of provisioning scripts and probes is failing...

@jandubois jandubois marked this pull request as draft November 8, 2024 02:21
@AkihiroSuda
Copy link
Member

Can we move this to v1.0.2?

@jandubois
Copy link
Member Author

Can we move this to v1.0.2?

Sure. It is a regression to pre-1.0.0 releases, but only affects users that have switched their default shell inside the instance to fish.

@AkihiroSuda AkihiroSuda modified the milestones: v1.0.1, v1.0.2 Nov 8, 2024
@jandubois jandubois force-pushed the bash-quotes branch 2 times, most recently from 3a4d151 to 10b5f51 Compare November 8, 2024 04:51
@jandubois jandubois marked this pull request as ready for review November 8, 2024 05:20
@jandubois
Copy link
Member Author

Seems like TEST| [INFO] Testing that PARAM env variables are exported to all types of provisioning scripts and probes is failing...

Just a small quoting issue; should be all good now.

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]>
Comment on lines +85 to +90
// 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, "%", "%%")
// strings will be interpolated into single-quoted strings, so protect any existing single quotes
interpreter = strings.ReplaceAll(interpreter, "'", `'"'"'`)
exportParam = strings.ReplaceAll(exportParam, "'", `'"'"'`)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these replacements are not really needed because the input strings don't include % or ' characters. but it feels like the right thing to do to make them correct for that case as well.

Copy link
Contributor

@norio-nomura norio-nomura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻
However, I feel that ssh.ExecuteScript should use shellwords.Parse to split the first line into a command and arguments rather than using the entire line as the command itself.

@jandubois
Copy link
Member Author

LGTM 👍🏻

🙏

However, I feel that ssh.ExecuteScript should use shellwords.Parse to split the first line into a command and arguments rather than using the entire line as the command itself.

Given that ssh.ExecuteScript is in https://github.com/lima-vm/sshocker/blob/master/pkg/ssh/ssh.go (in a different repo), and that this is a separate issue from what this PR is trying to fix, I assume you will create a different issue for that.

@jandubois jandubois merged commit 77cbbda into lima-vm:master Nov 12, 2024
29 checks passed
@jandubois jandubois deleted the bash-quotes branch November 12, 2024 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changing the VM user's shell to fish causes lima to wait forever for the SSH requirement to be satisfied
3 participants