mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-03-23 15:23:22 +01:00
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:
parent
b59e9e95bd
commit
7d0fb0391f
@ -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"
|
||||
}
|
||||
|
@ -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":
|
||||
|
Loading…
Reference in New Issue
Block a user