|
@@ -2,13 +2,13 @@ package local
|
|
|
|
|
|
import (
|
|
import (
|
|
//"github.com/davecgh/go-spew/spew"
|
|
//"github.com/davecgh/go-spew/spew"
|
|
- "github.com/gravitl/netmaker/netclient/config"
|
|
|
|
- "fmt"
|
|
|
|
|
|
+ "errors"
|
|
|
|
+ "github.com/gravitl/netmaker/netclient/config"
|
|
|
|
+ "log"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"path/filepath"
|
|
"io"
|
|
"io"
|
|
"strings"
|
|
"strings"
|
|
- "log"
|
|
|
|
"os"
|
|
"os"
|
|
"os/exec"
|
|
"os/exec"
|
|
)
|
|
)
|
|
@@ -19,7 +19,7 @@ func RunCmds(commands []string) error {
|
|
args := strings.Fields(command)
|
|
args := strings.Fields(command)
|
|
out, err := exec.Command(args[0], args[1:]...).Output()
|
|
out, err := exec.Command(args[0], args[1:]...).Output()
|
|
if string(out) != "" {
|
|
if string(out) != "" {
|
|
- fmt.Println(string(out))
|
|
|
|
|
|
+ log.Println(string(out))
|
|
}
|
|
}
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -72,13 +72,11 @@ func ConfigureSystemD(network string) error {
|
|
}
|
|
}
|
|
binarypath := dir + "/netclient"
|
|
binarypath := dir + "/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 {
|
|
- fmt.Println("couldnt find or create /etc/netclient")
|
|
|
|
|
|
+ log.Println("couldnt find or create /etc/netclient")
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
@@ -136,7 +134,6 @@ OnCalendar=*:*:0/30
|
|
WantedBy=timers.target
|
|
WantedBy=timers.target
|
|
`
|
|
`
|
|
|
|
|
|
-
|
|
|
|
servicebytes := []byte(systemservice)
|
|
servicebytes := []byte(systemservice)
|
|
timerbytes := []byte(systemtimer)
|
|
timerbytes := []byte(systemtimer)
|
|
|
|
|
|
@@ -184,23 +181,23 @@ WantedBy=timers.target
|
|
|
|
|
|
err = cmdSysEnableService.Run()
|
|
err = cmdSysEnableService.Run()
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Error enabling [email protected]. Please investigate.")
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ log.Println("Error enabling [email protected]. Please investigate.")
|
|
|
|
+ log.Println(err)
|
|
}
|
|
}
|
|
err = cmdSysDaemonReload.Run()
|
|
err = cmdSysDaemonReload.Run()
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Error reloading system daemons. Please investigate.")
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ log.Println("Error reloading system daemons. Please investigate.")
|
|
|
|
+ log.Println(err)
|
|
}
|
|
}
|
|
err = cmdSysEnableTimer.Run()
|
|
err = cmdSysEnableTimer.Run()
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Error enabling netclient.timer. Please investigate.")
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ log.Println("Error enabling netclient.timer. Please investigate.")
|
|
|
|
+ log.Println(err)
|
|
}
|
|
}
|
|
err = cmdSysStartTimer.Run()
|
|
err = cmdSysStartTimer.Run()
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Error starting netclient-"+network+".timer. Please investigate.")
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ log.Println("Error starting netclient-"+network+".timer. Please investigate.")
|
|
|
|
+ log.Println(err)
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -225,7 +222,7 @@ func RemoveSystemDServices(network string) error {
|
|
|
|
|
|
fullremove, err := isOnlyService(network)
|
|
fullremove, err := isOnlyService(network)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ log.Println(err)
|
|
}
|
|
}
|
|
|
|
|
|
cmdSysDisableService := exec.Command("systemctl","disable","[email protected]")
|
|
cmdSysDisableService := exec.Command("systemctl","disable","[email protected]")
|
|
@@ -234,43 +231,47 @@ func RemoveSystemDServices(network string) error {
|
|
cmdSysStopTimer := exec.Command("systemctl", "stop", "netclient-"+network+".timer")
|
|
cmdSysStopTimer := exec.Command("systemctl", "stop", "netclient-"+network+".timer")
|
|
cmdSysDisableTimer := exec.Command("systemctl", "disable", "netclient-"+network+".timer")
|
|
cmdSysDisableTimer := exec.Command("systemctl", "disable", "netclient-"+network+".timer")
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Error stopping [email protected]. Please investigate.")
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ log.Println("Error stopping [email protected]. Please investigate.")
|
|
|
|
+ log.Println(err)
|
|
}
|
|
}
|
|
if fullremove {
|
|
if fullremove {
|
|
err = cmdSysDisableService.Run()
|
|
err = cmdSysDisableService.Run()
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Error disabling [email protected]. Please investigate.")
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ log.Println("Error disabling [email protected]. Please investigate.")
|
|
|
|
+ log.Println(err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
err = cmdSysStopTimer.Run()
|
|
err = cmdSysStopTimer.Run()
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Error stopping netclient-"+network+".timer. Please investigate.")
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ log.Println("Error stopping netclient-"+network+".timer. Please investigate.")
|
|
|
|
+ log.Println(err)
|
|
}
|
|
}
|
|
err = cmdSysDisableTimer.Run()
|
|
err = cmdSysDisableTimer.Run()
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Error disabling netclient-"+network+".timer. Please investigate.")
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ log.Println("Error disabling netclient-"+network+".timer. Please investigate.")
|
|
|
|
+ log.Println(err)
|
|
}
|
|
}
|
|
if fullremove {
|
|
if fullremove {
|
|
- err = os.Remove("/etc/systemd/system/[email protected]")
|
|
|
|
|
|
+ if FileExists("/etc/systemd/system/[email protected]") {
|
|
|
|
+ err = os.Remove("/etc/systemd/system/[email protected]")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if FileExists("/etc/systemd/system/netclient-"+network+".timer") {
|
|
|
|
+ err = os.Remove("/etc/systemd/system/netclient-"+network+".timer")
|
|
}
|
|
}
|
|
- err = os.Remove("/etc/systemd/system/netclient-"+network+".timer")
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Error removing file. Please investigate.")
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ log.Println("Error removing file. Please investigate.")
|
|
|
|
+ log.Println(err)
|
|
}
|
|
}
|
|
err = cmdSysDaemonReload.Run()
|
|
err = cmdSysDaemonReload.Run()
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Error reloading system daemons. Please investigate.")
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ log.Println("Error reloading system daemons. Please investigate.")
|
|
|
|
+ log.Println(err)
|
|
}
|
|
}
|
|
err = cmdSysResetFailed.Run()
|
|
err = cmdSysResetFailed.Run()
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Error reseting failed system services. Please investigate.")
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ log.Println("Error reseting failed system services. Please investigate.")
|
|
|
|
+ log.Println(err)
|
|
}
|
|
}
|
|
return err
|
|
return err
|
|
|
|
|
|
@@ -286,9 +287,15 @@ func WipeLocal(network string) error{
|
|
|
|
|
|
//home, err := homedir.Dir()
|
|
//home, err := homedir.Dir()
|
|
home := "/etc/netclient"
|
|
home := "/etc/netclient"
|
|
- _ = os.Remove(home + "/netconfig-" + network)
|
|
|
|
- _ = os.Remove(home + "/nettoken-" + network)
|
|
|
|
- _ = os.Remove(home + "/wgkey-" + network)
|
|
|
|
|
|
+ if FileExists(home + "/netconfig-" + network) {
|
|
|
|
+ _ = os.Remove(home + "/netconfig-" + network)
|
|
|
|
+ }
|
|
|
|
+ if FileExists(home + "/nettoken-" + network) {
|
|
|
|
+ _ = os.Remove(home + "/nettoken-" + network)
|
|
|
|
+ }
|
|
|
|
+ if FileExists(home + "/wgkey-" + network) {
|
|
|
|
+ _ = os.Remove(home + "/wgkey-" + network)
|
|
|
|
+ }
|
|
|
|
|
|
ipExec, err := exec.LookPath("ip")
|
|
ipExec, err := exec.LookPath("ip")
|
|
|
|
|
|
@@ -301,13 +308,13 @@ func WipeLocal(network string) error{
|
|
}
|
|
}
|
|
err = cmdIPLinkDel.Run()
|
|
err = cmdIPLinkDel.Run()
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ log.Println(err)
|
|
}
|
|
}
|
|
if nodecfg.PostDown != "" {
|
|
if nodecfg.PostDown != "" {
|
|
runcmds := strings.Split(nodecfg.PostDown, "; ")
|
|
runcmds := strings.Split(nodecfg.PostDown, "; ")
|
|
err = RunCmds(runcmds)
|
|
err = RunCmds(runcmds)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Error encountered running PostDown: " + err.Error())
|
|
|
|
|
|
+ log.Println("Error encountered running PostDown: " + err.Error())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -345,7 +352,7 @@ func copy(src, dst string) (int64, error) {
|
|
}
|
|
}
|
|
|
|
|
|
if !sourceFileStat.Mode().IsRegular() {
|
|
if !sourceFileStat.Mode().IsRegular() {
|
|
- return 0, fmt.Errorf("%s is not a regular file", src)
|
|
|
|
|
|
+ return 0, errors.New(src + " is not a regular file")
|
|
}
|
|
}
|
|
|
|
|
|
source, err := os.Open(src)
|
|
source, err := os.Open(src)
|