mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
Builds on top of https://github.com/coder/coder/pull/16623/ and wires up the ReconnectingPTY server. This does nothing to wire up the web terminal yet but the added test demonstrates the functionality working. Other changes: * Refactors and moves the `SystemEnvInfo` interface to the `agent/usershell` package to address follow-up from https://github.com/coder/coder/pull/16623#discussion_r1967580249 * Marks `usershellinfo.Get` as deprecated. Consumers should use the `EnvInfoer` interface instead. --------- Co-authored-by: Mathias Fredriksson <mafredri@gmail.com> Co-authored-by: Danny Kopping <danny@coder.com>
31 lines
875 B
Go
31 lines
875 B
Go
package usershell
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
// Get returns the $SHELL environment variable.
|
|
// Deprecated: use SystemEnvInfo.UserShell instead.
|
|
func Get(username string) (string, error) {
|
|
// This command will output "UserShell: /bin/zsh" if successful, we
|
|
// can ignore the error since we have fallback behavior.
|
|
if !filepath.IsLocal(username) {
|
|
return "", xerrors.Errorf("username is nonlocal path: %s", username)
|
|
}
|
|
//nolint: gosec // input checked above
|
|
out, _ := exec.Command("dscl", ".", "-read", filepath.Join("/Users", username), "UserShell").Output()
|
|
s, ok := strings.CutPrefix(string(out), "UserShell: ")
|
|
if ok {
|
|
return strings.TrimSpace(s), nil
|
|
}
|
|
if s = os.Getenv("SHELL"); s != "" {
|
|
return s, nil
|
|
}
|
|
return "", xerrors.Errorf("shell for user %q not found via dscl or in $SHELL", username)
|
|
}
|