mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-10 23:24:32 +08:00
commit
cd02e93466
3 changed files with 57 additions and 5 deletions
|
@ -203,7 +203,6 @@ func readConfig() *ClientConfig {
|
||||||
f, err := os.Open(file)
|
f, err := os.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
nofile = true
|
nofile = true
|
||||||
fmt.Println("Could not access " + home + "/.netconfig, proceeding...")
|
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
|
|
|
@ -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,16 +12,23 @@ 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) {
|
||||||
os.Mkdir("/etc/netclient", 744)
|
os.Mkdir("/etc/netclient", 744)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
|
|
@ -7,6 +7,9 @@ import (
|
||||||
nodepb "github.com/gravitl/netmaker/grpc"
|
nodepb "github.com/gravitl/netmaker/grpc"
|
||||||
"flag"
|
"flag"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,19 +37,61 @@ func main() {
|
||||||
taccesskey := flag.String("k", "badkey", "an access key generated by the server and used for one-time access (install only)")
|
taccesskey := flag.String("k", "badkey", "an access key generated by the server and used for one-time access (install only)")
|
||||||
tserver := flag.String("s", "localhost:50051", "The location (including port) of the remote gRPC server.")
|
tserver := flag.String("s", "localhost:50051", "The location (including port) of the remote gRPC server.")
|
||||||
tgroup := flag.String("g", "badgroup", "The node group you are attempting to join.")
|
tgroup := flag.String("g", "badgroup", "The node group you are attempting to join.")
|
||||||
tnoauto := flag.Bool("na", false, "No auto mode. If true, netmaker will not be installed as a system service and you will have to retrieve updates manually via checkin command.")
|
tnoauto := flag.Bool("na", false, "No auto mode. If true, netmclient will not be installed as a system service and you will have to retrieve updates manually via checkin command.")
|
||||||
|
tnoforward := flag.Bool("nf", false, "No Forward mode. If true, netclient will not check for IP forwarding. This may break functionality")
|
||||||
command := flag.String("c", "required", "The command to run")
|
command := flag.String("c", "required", "The command to run")
|
||||||
|
|
||||||
|
|
||||||
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.")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_, err = exec.LookPath("wg")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
log.Fatal("WireGuard not installed. Please install WireGuard (wireguard-tools) and try again.")
|
||||||
|
}
|
||||||
|
|
||||||
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|")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
log.Fatal("Exiting")
|
log.Fatal("Exiting")
|
||||||
case "install":
|
case "install":
|
||||||
|
if !*tnoforward {
|
||||||
|
forward := exec.Command("sysctl", "net.ipv4.ip_forward")
|
||||||
|
out, err := forward.Output()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
//s := strings.Split(string(out), " ", "\n")
|
||||||
|
s := strings.Fields(string(out))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if s[2] != "1" {
|
||||||
|
log.Fatal("It is recommended to enable IP Forwarding. Current status is: " + s[2] + ", but should be 1. if you would like to run without IP Forwarding, re-run with flag '-nf true'")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("Beginning agent installation.")
|
fmt.Println("Beginning agent installation.")
|
||||||
err := functions.Install(*taccesskey, *tpassword, *tserver, *tgroup, *tnoauto)
|
err := functions.Install(*taccesskey, *tpassword, *tserver, *tgroup, *tnoauto)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue