forked from gojue/ecapture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_bash.go
67 lines (57 loc) · 1.33 KB
/
config_bash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
Copyright © 2022 CFC4N <cfc4n.cs@gmail.com>
*/
package user
import (
"errors"
"os"
"strings"
)
// Bashpath 与 readline 两个参数,使用时二选一
type BashConfig struct {
eConfig
Bashpath string `json:"bashpath"` //bash的文件路径
Readline string `json:"readline"`
ErrNo int
elfType uint8 //
}
func NewBashConfig() *BashConfig {
config := &BashConfig{}
return config
}
func (this *BashConfig) Check() error {
// 如果readline 配置,且存在,则直接返回。
if this.Readline != "" || len(strings.TrimSpace(this.Readline)) > 0 {
_, e := os.Stat(this.Readline)
if e != nil {
return e
}
this.elfType = ELF_TYPE_SO
return nil
}
//如果配置 bash的地址,且存在,则直接返回
if this.Bashpath != "" || len(strings.TrimSpace(this.Bashpath)) > 0 {
_, e := os.Stat(this.Bashpath)
if e != nil {
return e
}
this.elfType = ELF_TYPE_BIN
return nil
}
//如果没配置,则自动查找。
bash, b := os.LookupEnv("SHELL")
if b {
soPath, e := getDynPathByElf(bash, "libreadline.so")
if e != nil {
//this.logger.Printf("get bash:%s dynamic library error:%v.\n", bash, e)
this.Bashpath = bash
this.elfType = ELF_TYPE_BIN
} else {
this.Bashpath = soPath
this.elfType = ELF_TYPE_SO
}
} else {
return errors.New("cant found $SHELL path.")
}
return nil
}