mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 02:59:23 +08:00
fix: 不使用环境变量获取shell
This commit is contained in:
@@ -13,21 +13,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func newTerminalImpl() (*terminalImpl, error) {
|
func newTerminalImpl() (*terminalImpl, error) {
|
||||||
// 优先获取用户默认 shell
|
shell := ""
|
||||||
shell := os.Getenv("SHELL")
|
// 从 /etc/passwd 获取
|
||||||
if shell == "" {
|
user, err := os.UserHomeDir() // 当前用户
|
||||||
// 如果 SHELL 环境变量为空,尝试从 /etc/passwd 获取
|
if err == nil {
|
||||||
user, err := os.UserHomeDir() // 当前用户
|
passwd, err := os.ReadFile("/etc/passwd")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
passwd, err := os.ReadFile("/etc/passwd")
|
for _, line := range strings.Split(string(passwd), "\n") {
|
||||||
if err == nil {
|
if strings.Contains(line, user) {
|
||||||
for _, line := range strings.Split(string(passwd), "\n") {
|
parts := strings.Split(line, ":")
|
||||||
if strings.Contains(line, user) {
|
if len(parts) >= 7 && parts[6] != "" {
|
||||||
parts := strings.Split(line, ":")
|
shell = parts[6]
|
||||||
if len(parts) >= 7 && parts[6] != "" {
|
break
|
||||||
shell = parts[6]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user