Fixed path issue for install. Added sudo check for binary

This commit is contained in:
afeiszli
2021-03-27 12:50:27 -04:00
parent 14fc83fabf
commit b790730825
2 changed files with 31 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ import (
//"github.com/davecgh/go-spew/spew" //"github.com/davecgh/go-spew/spew"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"path/filepath"
"io" "io"
"log" "log"
"os" "os"
@@ -11,14 +12,21 @@ import (
) )
func ConfigureSystemD() error { func ConfigureSystemD() error {
/*
path, err := os.Getwd() path, err := os.Getwd()
if err != nil { if err != nil {
log.Println(err) log.Println(err)
return err return err
} }
*/
//binarypath := path + "/netclient"
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return err
}
binarypath := dir + "/netclient"
binarypath := path + "/netclient" fmt.Println("Installing Binary from Path: " + binarypath)
_, err = os.Stat("/etc/netclient") _, err = os.Stat("/etc/netclient")
if os.IsNotExist(err) { if os.IsNotExist(err) {

View File

@@ -7,6 +7,8 @@ import (
nodepb "github.com/gravitl/netmaker/grpc" nodepb "github.com/gravitl/netmaker/grpc"
"flag" "flag"
"os" "os"
"os/exec"
"strconv"
"log" "log"
) )
@@ -41,6 +43,24 @@ func main() {
flag.Parse() flag.Parse()
getID := exec.Command("id", "-u")
out, err := getID.Output()
if err != nil {
log.Fatal(err)
}
id, err := strconv.Atoi(string(out[:len(out)-1]))
if err != nil {
log.Fatal(err)
}
if id != 0 {
log.Fatal("This program must be run with elevated privileges (sudo). This program installs a SystemD service and configures WireGuard and networking rules. Please re-run with sudo/root.")
}
switch *command { switch *command {
case "required": case "required":
fmt.Println("command flag 'c' is required. Pick one of |install|checkin|update|remove|") fmt.Println("command flag 'c' is required. Pick one of |install|checkin|update|remove|")