forked from k8gege/LadonGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.go
48 lines (44 loc) · 940 Bytes
/
install.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
package main
//Usage: go run install.go
//Ladon Scanner for golang
//Author: k8gege
//K8Blog: http://k8gege.org/Ladon
//Github: https://github.com/k8gege/LadonGo
import (
"fmt"
"runtime"
"os/exec"
"os"
)
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
func main() {
fmt.Println("Install to System")
pwd, _ := os.Getwd()
LadonPath:=""
//fmt.Println(pwd)
if runtime.GOOS!="windows" {
LadonPath="/usr/local/bin/Ladon"
cmd :=exec.Command("/bin/sh","-c","go build -o "+LadonPath+" "+pwd+"/Ladon.go")
cmd.Run()
} else if runtime.GOOS=="windows" {
LadonPath="C:\\Windows\\System32\\Ladon.exe"
cmd :=exec.Command("cmd","/c","go build -o "+LadonPath+" "+pwd+"\\Ladon.go")
cmd.Run()
}
exist, _ := PathExists(LadonPath)
if exist{
fmt.Println("Done!")
}else{
fmt.Println("Fail!")
fmt.Println("Admin is needed")
}
}