Improved Shell Detection (#1658)

Use the SHELL environment variable instead of the /etc/passwd file for
determining the shell on Linux.
This commit is contained in:
Sylvie Crowe 2024-12-30 22:18:56 -08:00 committed by GitHub
parent b59e9e95bd
commit 7d0fb0391f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 26 deletions

View File

@ -6,9 +6,7 @@
package cmd
import (
"bufio"
"os"
"os/user"
"runtime"
"strings"
@ -33,30 +31,10 @@ func shellCmdInner() string {
if runtime.GOOS == "darwin" {
return shellutil.GetMacUserShell() + "\n"
}
user, err := user.Current()
if err != nil {
shell := os.Getenv("SHELL")
if shell == "" {
return "/bin/bash\n"
}
passwd, err := os.Open("/etc/passwd")
if err != nil {
return "/bin/bash\n"
}
scanner := bufio.NewScanner(passwd)
for scanner.Scan() {
line := scanner.Text()
line = strings.TrimSpace(line)
parts := strings.Split(line, ":")
if len(parts) != 7 {
continue
}
if parts[0] == user.Username {
return parts[6] + "\n"
}
}
// none found
return "/bin/bash\n"
return strings.TrimSpace(shell) + "\n"
}

View File

@ -974,7 +974,9 @@ func FilterValidArch(arch string) (string, error) {
formatted := strings.TrimSpace(strings.ToLower(arch))
switch formatted {
case "amd64":
return "x64", nil
case "x86_64":
return "x64", nil
case "x64":
return "x64", nil
case "arm64":