-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathuser.go
41 lines (35 loc) · 822 Bytes
/
user.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
package main
import (
"os/exec"
"os/user"
"github.com/sirupsen/logrus"
)
func createUser() {
if !checkUser() {
bs, err := exec.Command("useradd", "-M", "-s", "/bin/false", clashUser).CombinedOutput()
if err != nil {
logrus.Fatalf("failed to create tpclash user: %s, %v", bs, err)
}
}
}
func checkUser() bool {
u, err := user.Lookup(clashUser)
if err != nil {
return false
}
return u != nil
}
func chownR(p string) error {
bs, err := exec.Command("chown", "-R", clashUser+":"+clashUser, p).CombinedOutput()
if err != nil {
logrus.Fatalf("failed to change dir owner: %s, %v", bs, err)
}
return nil
}
func chmod(p string) error {
bs, err := exec.Command("chmod", "+x", p).CombinedOutput()
if err != nil {
logrus.Fatalf("failed to change file permission: %s, %v", bs, err)
}
return nil
}