func shellAndArgs(tempDir, script, user string) (string, []string, error) {
	var scriptFile string
	var cmd string
	var args []string
	switch runtime.GOOS {
	case "windows":
		scriptFile = filepath.Join(tempDir, "script.ps1")
		cmd = "powershell.exe"
		args = []string{
			"-NoProfile",
			"-NonInteractive",
			"-ExecutionPolicy", "RemoteSigned",
			"-File", scriptFile,
		}
		// Exceptions don't result in a non-zero exit code by default
		// when using -File. The exit code of an explicit "exit" when
		// using -Command is ignored and results in an exit code of 1.
		// We use -File and trap exceptions to cover both.
		script = "trap {Write-Error $_; exit 1}\n" + script
	default:
		scriptFile = filepath.Join(tempDir, "script.sh")
		if user == "" {
			cmd = "/bin/bash"
			args = []string{scriptFile}
		} else {
			// Need to make the tempDir readable by all so the user can see it.
			err := os.Chmod(tempDir, 0755)
			if err != nil {
				return "", nil, errors.Annotatef(err, "making tempdir readable by %q", user)
			}
			cmd = "/bin/su"
			args = []string{user, "--login", "--command", fmt.Sprintf("/bin/bash %s", scriptFile)}
		}
	}
	err := ioutil.WriteFile(scriptFile, []byte(script), 0644)
	if err != nil {
		return "", nil, err
	}
	return cmd, args, nil
}
// shellAndArgs returns the name of the shell command and arguments to run the
// specified script. shellAndArgs may write into the provided temporary
// directory, which will be maintained until the process exits.
shellAndArgs returns the name of the shell command and arguments to run the
specified script. shellAndArgs may write into the provided temporary
directory, which will be maintained until the process exits.
// shellAndArgs returns the name of the shell command and arguments to run the // specified script . shellAndArgs may write into the provided temporary // directory which will be maintained until the process exits .
func shellAndArgs(tempDir, script, user string) (string, []string, error) {
	var scriptFile string
	var cmd string
	var args []string
	switch runtime.GOOS {
	case "windows":
		scriptFile = filepath.Join(tempDir, "script.ps1")
		cmd = "powershell.exe"
		args = []string{
			"-NoProfile",
			"-NonInteractive",
			"-ExecutionPolicy", "RemoteSigned",
			"-File", scriptFile,
		}
		script = "trap {Write-Error $_; exit 1}\n" + script
	default:
		scriptFile = filepath.Join(tempDir, "script.sh")
		if user == "" {
			cmd = "/bin/bash"
			args = []string{scriptFile}
		} else {
			err := os.Chmod(tempDir, 0755)
			if err != nil {
				return "", nil, errors.Annotatef(err, "making tempdir readable by %q", user)
			}
			cmd = "/bin/su"
			args = []string{user, "--login", "--command", fmt.Sprintf("/bin/bash %s", scriptFile)}
		}
	}
	err := ioutil.WriteFile(scriptFile, []byte(script), 0644)
	if err != nil {
		return "", nil, err
	}
	return cmd, args, nil
}
func shellAndArgs ( tempDir , script , user string ) ( string , [ ] string , error ) { var scriptFile string var cmd string var args [ ] string switch runtime . GOOS { case " " : scriptFile = filepath . Join ( tempDir , " " ) cmd = " " args = [ ] string { " " , " " , " " , " " , " " , scriptFile , } script = " \n " + script default : scriptFile = filepath . Join ( tempDir , " " ) if user == " " { cmd = " " args = [ ] string { scriptFile } } else { err := os . Chmod ( tempDir , 0755 ) if err != nil { return " " , nil , errors . Annotatef ( err , " " , user ) } cmd = " " args = [ ] string { user , " " , " " , fmt . Sprintf ( " " , scriptFile ) } } } err := ioutil . WriteFile ( scriptFile , [ ] byte ( script ) , 0644 ) if err != nil { return " " , nil , err } return cmd , args , nil }
shellAndArgs returns the name of the shell command and arguments to run the
specified script.
shellAndArgs returns the name of the shell command and arguments to run the specified script .
// Exceptions don't result in a non-zero exit code by default // when using -File. The exit code of an explicit "exit" when // using -Command is ignored and results in an exit code of 1. // We use -File and trap exceptions to cover both. // Need to make the tempDir readable by all so the user can see it.