|
@@ -0,0 +1,40 @@
|
|
|
+package ncutils
|
|
|
+
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "crypto/tls"
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "io"
|
|
|
+ "io/ioutil"
|
|
|
+ "log"
|
|
|
+ "math/rand"
|
|
|
+ "net"
|
|
|
+ "net/http"
|
|
|
+ "os"
|
|
|
+ "os/exec"
|
|
|
+ "regexp"
|
|
|
+ "runtime"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "syscall"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ "golang.zx2c4.com/wireguard/wgctrl"
|
|
|
+ "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
|
|
+ "google.golang.org/grpc"
|
|
|
+ "google.golang.org/grpc/credentials"
|
|
|
+)
|
|
|
+
|
|
|
+// RunCmd - runs a local command
|
|
|
+func RunCmd(command string, printerr bool) (string, error) {
|
|
|
+ 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
|
|
|
+}
|