Merge pull request #1309 from gravitl/hotfix_v0.14.4_macos

changes for macos installer
This commit is contained in:
Alex Feiszli 2022-07-07 11:38:00 -04:00 committed by GitHub
commit 1fcf7023da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 13 deletions

View file

@ -29,10 +29,6 @@ func SetupMacDaemon() error {
return err
}
_, errN := os.Stat("~/Library/LaunchAgents")
if os.IsNotExist(errN) {
os.Mkdir("~/Library/LaunchAgents", 0755)
}
err = CreateMacService(MAC_SERVICE_NAME)
if err != nil {
return err
@ -64,7 +60,7 @@ func RestartLaunchD() {
// StopLaunchD - stop launch daemon
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

View file

@ -41,6 +41,9 @@ const NO_DB_RECORDS = "could not find any records"
// LINUX_APP_DATA_PATH - linux path
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
const WINDOWS_APP_DATA_PATH = "C:\\Program Files (x86)\\Netclient"
@ -265,7 +268,7 @@ func GetNetclientPath() string {
if IsWindows() {
return WINDOWS_APP_DATA_PATH
} else if IsMac() {
return "/etc/netclient/"
return MAC_APP_DATA_PATH
} else {
return LINUX_APP_DATA_PATH
}
@ -301,7 +304,7 @@ func GetNetclientServerPath(server string) string {
if IsWindows() {
return WINDOWS_APP_DATA_PATH + "\\" + server + "\\"
} else if IsMac() {
return "/etc/netclient/" + server + "/"
return MAC_APP_DATA_PATH + "/" + server + "/"
} else {
return LINUX_APP_DATA_PATH + "/" + server
}
@ -312,7 +315,7 @@ func GetNetclientPathSpecific() string {
if IsWindows() {
return WINDOWS_APP_DATA_PATH + "\\"
} else if IsMac() {
return "/etc/netclient/config/"
return MAC_APP_DATA_PATH + "/config/"
} else {
return LINUX_APP_DATA_PATH + "/config/"
}
@ -491,11 +494,9 @@ func CheckUID() {
// CheckWG - Checks if WireGuard is installed. If not, exit
func CheckWG() {
var _, err = exec.LookPath("wg")
uspace := GetWireGuard()
if err != nil {
if !HasWG() {
if uspace == "wg" {
logger.Log(0, err.Error())
log.Fatal("WireGuard not installed. Please install WireGuard (wireguard-tools) and try again.")
}
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
func ConvertKeyToBytes(key *[32]byte) ([]byte, error) {
var buffer bytes.Buffer

View file

@ -1,19 +1,28 @@
package ncutils
import (
"github.com/gravitl/netmaker/logger"
"os/exec"
"strings"
"github.com/gravitl/netmaker/logger"
)
// WHITESPACE_PLACEHOLDER - used with RunCMD - if a path has whitespace, use this to avoid running path as 2 args in RunCMD
const WHITESPACE_PLACEHOLDER = "+-+-+-+"
// RunCmd - runs a local command
func RunCmd(command string, printerr bool) (string, error) {
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.Wait()
out, err := cmd.CombinedOutput()
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"))
}
return string(out), err

View file

@ -208,6 +208,7 @@ func addRoute(addr string, iface string) error {
// setConfig - sets configuration of the wireguard interface from the config file
func setConfig(realIface string, confPath string) error {
confString := getConfig(confPath)
// pathFormatted := strings.Replace(confPath, " ", "\\ ", -1)
err := os.WriteFile(confPath+".tmp", []byte(confString), 0600)
if err != nil {
return err
@ -219,6 +220,7 @@ func setConfig(realIface string, confPath string) error {
// getConfig - gets config from config file and strips out incompatible fields
func getConfig(path string) string {
// pathFormatted := strings.Replace(path, " ", "\\ ", -1)
var confCmd = "grep -v -e Address -e MTU -e PostUp -e PostDown "
confRaw, _ := ncutils.RunCmd(confCmd+path, false)
return confRaw