-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.go
64 lines (55 loc) · 1.36 KB
/
setup.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
package libbox
import (
"os"
"os/user"
"strconv"
"github.com/kelleygo/sing-box/common/humanize"
C "github.com/kelleygo/sing-box/constant"
_ "github.com/kelleygo/sing-box/include"
)
var (
sBasePath string
sWorkingPath string
sTempPath string
sUserID int
sGroupID int
sTVOS bool
)
func Setup(basePath string, workingPath string, tempPath string, isTVOS bool) {
sBasePath = basePath
sWorkingPath = workingPath
sTempPath = tempPath
sUserID = os.Getuid()
sGroupID = os.Getgid()
sTVOS = isTVOS
os.MkdirAll(sWorkingPath, 0o777)
os.MkdirAll(sTempPath, 0o777)
}
func SetupWithUsername(basePath string, workingPath string, tempPath string, username string) error {
sBasePath = basePath
sWorkingPath = workingPath
sTempPath = tempPath
sUser, err := user.Lookup(username)
if err != nil {
return err
}
sUserID, _ = strconv.Atoi(sUser.Uid)
sGroupID, _ = strconv.Atoi(sUser.Gid)
os.MkdirAll(sWorkingPath, 0o777)
os.MkdirAll(sTempPath, 0o777)
os.Chown(sWorkingPath, sUserID, sGroupID)
os.Chown(sTempPath, sUserID, sGroupID)
return nil
}
func Version() string {
return C.Version
}
func FormatBytes(length int64) string {
return humanize.Bytes(uint64(length))
}
func FormatMemoryBytes(length int64) string {
return humanize.MemoryBytes(uint64(length))
}
func ProxyDisplayType(proxyType string) string {
return C.ProxyDisplayName(proxyType)
}