2021-11-17 09:10:11 +08:00
|
|
|
package ncutils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RunCmd - runs a local command
|
|
|
|
func RunCmd(command string, printerr bool) (string, error) {
|
2021-11-18 10:57:27 +08:00
|
|
|
args := strings.Fields(command)
|
|
|
|
cmd := exec.Command(args[0], args[1:]...)
|
|
|
|
cmd.Wait()
|
|
|
|
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
|
2021-11-17 09:10:11 +08:00
|
|
|
}
|
2021-11-17 23:21:35 +08:00
|
|
|
|
2021-12-13 07:04:41 +08:00
|
|
|
// RunCmdFormatted - run a command formatted for MacOS
|
2021-11-18 13:01:05 +08:00
|
|
|
func RunCmdFormatted(command string, printerr bool) (string, error) {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
2021-12-13 07:04:41 +08:00
|
|
|
// GetEmbedded - if files required for MacOS, put here
|
|
|
|
func GetEmbedded() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-04 23:00:59 +08:00
|
|
|
// CreateWireGuardConf - creates a WireGuard conf string
|
2022-01-22 02:15:54 +08:00
|
|
|
//func 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 = %s
|
|
|
|
//PrivateKey = %s
|
|
|
|
//MTU = %s
|
|
|
|
//%s
|
|
|
|
//
|
|
|
|
//%s
|
|
|
|
//
|
|
|
|
//`,
|
|
|
|
// node.Address+"/32",
|
|
|
|
// privatekey,
|
|
|
|
// strconv.Itoa(int(node.MTU)),
|
|
|
|
// listenPortString,
|
|
|
|
// peersString)
|
|
|
|
// return config, nil
|
|
|
|
//}
|