mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-29 03:12:36 +08:00
changes for macos installer
This commit is contained in:
@@ -29,10 +29,6 @@ func SetupMacDaemon() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, errN := os.Stat("~/Library/LaunchAgents")
|
|
||||||
if os.IsNotExist(errN) {
|
|
||||||
os.Mkdir("~/Library/LaunchAgents", 0755)
|
|
||||||
}
|
|
||||||
err = CreateMacService(MAC_SERVICE_NAME)
|
err = CreateMacService(MAC_SERVICE_NAME)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -64,7 +60,7 @@ func RestartLaunchD() {
|
|||||||
|
|
||||||
// StopLaunchD - stop launch daemon
|
// StopLaunchD - stop launch daemon
|
||||||
func StopLaunchD() {
|
func StopLaunchD() {
|
||||||
ncutils.RunCmd("launchctl unload /System/Library/LaunchDaemons/"+MAC_SERVICE_NAME+".plist", true)
|
ncutils.RunCmd("launchctl unload /Library/LaunchDaemons/"+MAC_SERVICE_NAME+".plist", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateMacService - Creates the mac service file for LaunchDaemons
|
// CreateMacService - Creates the mac service file for LaunchDaemons
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ const NO_DB_RECORDS = "could not find any records"
|
|||||||
// LINUX_APP_DATA_PATH - linux path
|
// LINUX_APP_DATA_PATH - linux path
|
||||||
const LINUX_APP_DATA_PATH = "/etc/netclient"
|
const LINUX_APP_DATA_PATH = "/etc/netclient"
|
||||||
|
|
||||||
|
// MAC_APP_DATA_PATH - linux path
|
||||||
|
const MAC_APP_DATA_PATH = "/Applications/Netclient"
|
||||||
|
|
||||||
// WINDOWS_APP_DATA_PATH - windows path
|
// WINDOWS_APP_DATA_PATH - windows path
|
||||||
const WINDOWS_APP_DATA_PATH = "C:\\Program Files (x86)\\Netclient"
|
const WINDOWS_APP_DATA_PATH = "C:\\Program Files (x86)\\Netclient"
|
||||||
|
|
||||||
@@ -265,7 +268,7 @@ func GetNetclientPath() string {
|
|||||||
if IsWindows() {
|
if IsWindows() {
|
||||||
return WINDOWS_APP_DATA_PATH
|
return WINDOWS_APP_DATA_PATH
|
||||||
} else if IsMac() {
|
} else if IsMac() {
|
||||||
return "/etc/netclient/"
|
return MAC_APP_DATA_PATH
|
||||||
} else {
|
} else {
|
||||||
return LINUX_APP_DATA_PATH
|
return LINUX_APP_DATA_PATH
|
||||||
}
|
}
|
||||||
@@ -301,7 +304,7 @@ func GetNetclientServerPath(server string) string {
|
|||||||
if IsWindows() {
|
if IsWindows() {
|
||||||
return WINDOWS_APP_DATA_PATH + "\\" + server + "\\"
|
return WINDOWS_APP_DATA_PATH + "\\" + server + "\\"
|
||||||
} else if IsMac() {
|
} else if IsMac() {
|
||||||
return "/etc/netclient/" + server + "/"
|
return MAC_APP_DATA_PATH + "/" + server + "/"
|
||||||
} else {
|
} else {
|
||||||
return LINUX_APP_DATA_PATH + "/" + server
|
return LINUX_APP_DATA_PATH + "/" + server
|
||||||
}
|
}
|
||||||
@@ -312,7 +315,7 @@ func GetNetclientPathSpecific() string {
|
|||||||
if IsWindows() {
|
if IsWindows() {
|
||||||
return WINDOWS_APP_DATA_PATH + "\\"
|
return WINDOWS_APP_DATA_PATH + "\\"
|
||||||
} else if IsMac() {
|
} else if IsMac() {
|
||||||
return "/etc/netclient/config/"
|
return MAC_APP_DATA_PATH + "/config/"
|
||||||
} else {
|
} else {
|
||||||
return LINUX_APP_DATA_PATH + "/config/"
|
return LINUX_APP_DATA_PATH + "/config/"
|
||||||
}
|
}
|
||||||
@@ -491,11 +494,9 @@ func CheckUID() {
|
|||||||
|
|
||||||
// CheckWG - Checks if WireGuard is installed. If not, exit
|
// CheckWG - Checks if WireGuard is installed. If not, exit
|
||||||
func CheckWG() {
|
func CheckWG() {
|
||||||
var _, err = exec.LookPath("wg")
|
|
||||||
uspace := GetWireGuard()
|
uspace := GetWireGuard()
|
||||||
if err != nil {
|
if !HasWG() {
|
||||||
if uspace == "wg" {
|
if uspace == "wg" {
|
||||||
logger.Log(0, err.Error())
|
|
||||||
log.Fatal("WireGuard not installed. Please install WireGuard (wireguard-tools) and try again.")
|
log.Fatal("WireGuard not installed. Please install WireGuard (wireguard-tools) and try again.")
|
||||||
}
|
}
|
||||||
logger.Log(0, "running with userspace wireguard: ", uspace)
|
logger.Log(0, "running with userspace wireguard: ", uspace)
|
||||||
@@ -504,6 +505,12 @@ func CheckWG() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasWG - returns true if wg command exists
|
||||||
|
func HasWG() bool {
|
||||||
|
var _, err = exec.LookPath("wg")
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
// ConvertKeyToBytes - util to convert a key to bytes to use elsewhere
|
// ConvertKeyToBytes - util to convert a key to bytes to use elsewhere
|
||||||
func ConvertKeyToBytes(key *[32]byte) ([]byte, error) {
|
func ConvertKeyToBytes(key *[32]byte) ([]byte, error) {
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
|
|||||||
@@ -1,19 +1,27 @@
|
|||||||
package ncutils
|
package ncutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gravitl/netmaker/logger"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gravitl/netmaker/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const WHITESPACE_PLACEHOLDER = "+-+-+-+"
|
||||||
|
|
||||||
// RunCmd - runs a local command
|
// RunCmd - runs a local command
|
||||||
func RunCmd(command string, printerr bool) (string, error) {
|
func RunCmd(command string, printerr bool) (string, error) {
|
||||||
|
|
||||||
args := strings.Fields(command)
|
args := strings.Fields(command)
|
||||||
|
// return whitespace after split
|
||||||
|
for i, arg := range args {
|
||||||
|
args[i] = strings.Replace(arg, WHITESPACE_PLACEHOLDER, " ", -1)
|
||||||
|
}
|
||||||
cmd := exec.Command(args[0], args[1:]...)
|
cmd := exec.Command(args[0], args[1:]...)
|
||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil && printerr {
|
if err != nil && printerr {
|
||||||
logger.Log(0, "error running command:", command)
|
logger.Log(0, "error running command:", strings.Join(args, " "))
|
||||||
logger.Log(0, strings.TrimSuffix(string(out), "\n"))
|
logger.Log(0, strings.TrimSuffix(string(out), "\n"))
|
||||||
}
|
}
|
||||||
return string(out), err
|
return string(out), err
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ func addRoute(addr string, iface string) error {
|
|||||||
// setConfig - sets configuration of the wireguard interface from the config file
|
// setConfig - sets configuration of the wireguard interface from the config file
|
||||||
func setConfig(realIface string, confPath string) error {
|
func setConfig(realIface string, confPath string) error {
|
||||||
confString := getConfig(confPath)
|
confString := getConfig(confPath)
|
||||||
|
// pathFormatted := strings.Replace(confPath, " ", "\\ ", -1)
|
||||||
err := os.WriteFile(confPath+".tmp", []byte(confString), 0600)
|
err := os.WriteFile(confPath+".tmp", []byte(confString), 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -219,6 +220,7 @@ func setConfig(realIface string, confPath string) error {
|
|||||||
|
|
||||||
// getConfig - gets config from config file and strips out incompatible fields
|
// getConfig - gets config from config file and strips out incompatible fields
|
||||||
func getConfig(path string) string {
|
func getConfig(path string) string {
|
||||||
|
// pathFormatted := strings.Replace(path, " ", "\\ ", -1)
|
||||||
var confCmd = "grep -v -e Address -e MTU -e PostUp -e PostDown "
|
var confCmd = "grep -v -e Address -e MTU -e PostUp -e PostDown "
|
||||||
confRaw, _ := ncutils.RunCmd(confCmd+path, false)
|
confRaw, _ := ncutils.RunCmd(confCmd+path, false)
|
||||||
return confRaw
|
return confRaw
|
||||||
|
|||||||
Reference in New Issue
Block a user