| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 | package ncutilsimport (	"context"	"fmt"	"log"	"os/exec"	"strconv"	"strings"	"syscall"	"time"	"github.com/gravitl/netmaker/models"	"golang.zx2c4.com/wireguard/wgctrl/wgtypes")// RunCmdFormatted - run a command formatted for freebsdfunc RunCmdFormatted(command string, printerr bool) (string, error) {	return "", nil}// GetEmbedded - if files required for freebsd, put herefunc GetEmbedded() error {	return nil}// Runs Commands for FreeBSDfunc RunCmd(command string, printerr bool) (string, error) {	args := strings.Fields(command)	ctx, cancel := context.WithTimeout(context.Background(), time.Second)	defer cancel()	cmd := exec.Command(args[0], args[1:]...)	cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}	go func() {		<-ctx.Done()		_ = syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)	}()	out, err := cmd.CombinedOutput()	if err != nil && printerr {		log.Println("error running command:", command)		log.Println(strings.TrimSuffix(string(out), "\n"))	}	return string(out), err}// CreateWireGuardConf - creates a WireGuard conf stringfunc CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, peers []wgtypes.PeerConfig) (string, error) {	peersString, err := parsePeers(node.PersistentKeepalive, peers)	var listenPortString string	if node.MTU <= 0 {		node.MTU = 1280	}	if listenPort != "" {		listenPortString += "ListenPort = " + listenPort	}	if err != nil {		return "", err	}	config := fmt.Sprintf(`[Interface]Address = %sPrivateKey = %sMTU = %s%s%s`,		node.Address+"/32",		privatekey,		strconv.Itoa(int(node.MTU)),		listenPortString,		peersString)	return config, nil}
 |