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

scripts containing limactl terminated unexpectedly when piped to sh #2924

Open
RafalSkolasinski opened this issue Nov 20, 2024 · 1 comment
Labels
area/cli limactl CLI user experience

Comments

@RafalSkolasinski
Copy link

Description

I wanted to automate some operations using lima with shell scripts. Just for my own convenience and to be able to quickly demonstrate things I wanted to put script on github pages and just nicely curl to sh, like one does with k3s [1]
when I hit quite unexpected issue.

It can be reproduced with simple script, let's call it script.sh

#!/usr/bin/env sh

limactl shell default sudo apt-get update
limactl shell default sudo apt-get -y install avahi-daemon

If I run it directly it works fine:

$ ./script.sh                                                        
Hit:1 http://ports.ubuntu.com/ubuntu-ports oracular InRelease
Hit:2 http://ports.ubuntu.com/ubuntu-ports oracular-updates InRelease
Hit:3 http://ports.ubuntu.com/ubuntu-ports oracular-backports InRelease
Hit:4 http://ports.ubuntu.com/ubuntu-ports oracular-security InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
avahi-daemon is already the newest version (0.8-13ubuntu6).
0 upgraded, 0 newly installed, 0 to remove and 35 not upgraded.

but if I try to pipe it to sh, like I would do if I was curl-ing it in with one-liners i terminates at the end of apt-get update command

cat script.sh | sh
Hit:1 http://ports.ubuntu.com/ubuntu-ports oracular InRelease
Hit:2 http://ports.ubuntu.com/ubuntu-ports oracular-updates InRelease
Hit:3 http://ports.ubuntu.com/ubuntu-ports oracular-backports InRelease
Hit:4 http://ports.ubuntu.com/ubuntu-ports oracular-security InRelease
Reading package lists...

Notice lack of Done in "Reading package lists... Done".


Lima: 1.0.1
Macos: 15.1.1


[1] curl -sfL https://get.k3s.io | sh -s - --disable servicelb --disable traefik

@AkihiroSuda AkihiroSuda added the area/cli limactl CLI user experience label Nov 20, 2024
@norio-nomura
Copy link
Contributor

This issue can be reproduced even without using limactl, by starting ssh with stdin not being a terminal.

$ echo ""|ssh -i "/Users/norio/.lima/_config/user" -o StrictHostKeyChecking=no -t -p 49450 127.0.0.1 -- 'sudo apt-get update'
Pseudo-terminal will not be allocated because stdin is not a terminal.
Hit:1 http://deb.debian.org/debian bookworm InRelease
Hit:2 https://download.docker.com/linux/ubuntu noble InRelease
Hit:3 http://ports.ubuntu.com/ubuntu-ports noble InRelease
Hit:4 http://ports.ubuntu.com/ubuntu-ports noble-updates InRelease
Hit:5 http://ports.ubuntu.com/ubuntu-ports noble-backports InRelease
Hit:6 http://ports.ubuntu.com/ubuntu-ports noble-security InRelease
Reading package lists...

The issue does not reproduce when running sudo apt-get update directly inside the VM with stdin not being a terminal, so I believe the cause is related to ssh.

$ limactl shell docker
norio@lima-docker:/Users/norio/ghq/github.com/lima-vm/lima$ echo ""|sudo apt-get update
Hit:1 http://deb.debian.org/debian bookworm InRelease
Hit:2 https://download.docker.com/linux/ubuntu noble InRelease                          
Hit:3 http://ports.ubuntu.com/ubuntu-ports noble InRelease                              
Hit:4 http://ports.ubuntu.com/ubuntu-ports noble-updates InRelease
Hit:5 http://ports.ubuntu.com/ubuntu-ports noble-backports InRelease
Hit:6 http://ports.ubuntu.com/ubuntu-ports noble-security InRelease
Reading package lists... Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli limactl CLI user experience
Projects
None yet
Development

No branches or pull requests

3 participants