Coder Social home page Coder Social logo

Usage with sudo? about sake HOT 1 OPEN

MCMDEV avatar MCMDEV commented on August 19, 2024
Usage with sudo?

from sake.

Comments (1)

alajmo avatar alajmo commented on August 19, 2024

sake does not yet support interactive shells, it's something on the roadmap but no timeline available atm since I'm swamped with other stuff. The tty parameter just means that the sake command is replaced with the cmd in the task which allows interactive use.

So for instance, given this task:

  test:
    tty: false
    cmd: echo "Press enter to continue"; read var1

Basically without tty:

  1. sake run <cmd>
  2. sake uses the ssh client to send text to a server which is executed on the server (note, the ssh client process is a child process of sake)
  3. User presses enter, nothing happens since it's not an interactive shell

With tty set to true:

  1. sake run <cmd>
  2. sake replaces the current shell with the command (so it's not longer a child process but the main)
  3. User presses enter, you return to the shell

The code responsible for tty:

func ExecTTY(cmd string, envs []string) error {
	shell := "bash"
	foundShell, found := os.LookupEnv("SHELL")
	if found {
		shell = foundShell
	}

	execBin, err := exec.LookPath(shell)
	if err != nil {
		return err
	}

	userEnv := append(os.Environ(), envs...)
	err = unix.Exec(execBin, []string{shell, "-c", cmd}, userEnv)
	if err != nil {
		return err
	}

	return nil
}

There's 2 solutions I can think of to solve your problem:

  1. Use sudoless password for the user? https://serverfault.com/questions/160581/how-to-setup-passwordless-sudo-on-linux, that's how I get around interactive prompts for sudo.

  2. Write a custom ssh command using the -t flag, see https://unix.stackexchange.com/questions/243821/run-a-command-in-an-interactive-shell-with-ssh-after-sourcing-bashrc, so something like:

  test:
    tty: true
    cmd: ssh -t $S_USER@$S_HOST "read var1; echo 123"

from sake.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.