question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to use sudo midway through script execution

See original GitHub issue

Is your feature request related to a problem? Please describe. I’m currently trying to use pyinfra to install brew. The target machine that I am working on is running Windows 10 with WSL. I have ssh enabled, and am able to issue pyinfra commands that connect to WSL and work (mostly) correctly.

The standard way to install brew is to use: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)". To avoid the prompt in the script, I am using the env var env CI=1, however I am running into a snag with the sudo prompt that comes up midway through the script. I cannot just run the script as root or using sudo, because it explicitly checks for this and disallows it, but I still need to be able to pass a sudo prompt midway through for it to install brew at the standard location in /home/linuxbrew/.linuxbrew. I am wondering if there is way to get around this?

Based on the discussion in #305, I thought I might be able to get the password from the user in the deploy using getpass, and then feed that to the brew install script using the stdin global parameter, but that didn’t seem to work.

If I cannot find a solution I could write my own installation script, but I was hoping to be able to use the standard installation method that already exists.

Describe the solution you’d like I’m not entirely sure what the ideal solution would look like for this, since it is a pretty specific case… If the stdin solution I had mentioned worked, then maybe it would be nice to be able to “hold onto” the password that is captured via use_sudo_password so that it can be used later? It may also be the case that there is a better supported way to automate installation of brew, but I haven’t had any luck finding an easy method.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Fizzadarcommented, Nov 18, 2020

This is now supported as of https://github.com/Fizzadar/pyinfra/commit/ff40f50f840c9a73a041aa0d8d80defd2375f6ef; expecting to have a dev version of 1.3 out today/tomorrow.

1reaction
Fizzadarcommented, Nov 18, 2020

So this does work - but sudo needs to be called with -A, and brew appears to handle this nicely!

I’ll make the change to enable use_sudo_password to work irrespective of whether sudo is set.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I execute a script that needs sudo permission in the ...
One way is to use sudo -i instead of sudo The command is run with an environment similar to the one a user...
Read more >
sudo - proceed execution of script after change user
You can not change user identity in the middle of a script and then continue running the script as that new user. You...
Read more >
Using sudo to delegate permissions in Linux | Enable Sysadmin
As a sysadmin, I can use the /etc/sudoers file to allow users or groups of users access to a single command, defined groups...
Read more >
Should I use sudo in a script or sudo an entire script?
I'm writing a bash script to automatically install all the things needed on each computer. Some of the commands I'll be using require...
Read more >
Change to sudo user within a python script - Stack Overflow
In this case you need to sudo rights to run a specific program. In that case just sub to "sudo theprogram" instead. Share....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found