2022-05-07 03:21:57 +08:00
|
|
|
//go:generate goversioninfo -icon=windowsdata/resource/netclient.ico -manifest=netclient.exe.manifest.xml -64=true -o=netclient.syso
|
2022-05-06 00:36:13 +08:00
|
|
|
// -build gui
|
2021-08-31 03:58:23 +08:00
|
|
|
|
2021-03-26 00:17:52 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-07-26 02:22:20 +08:00
|
|
|
"os"
|
2021-09-20 02:03:47 +08:00
|
|
|
"runtime/debug"
|
|
|
|
|
2022-09-20 03:37:00 +08:00
|
|
|
"github.com/gravitl/netmaker/logger"
|
2021-12-09 05:52:32 +08:00
|
|
|
"github.com/gravitl/netmaker/netclient/cli_options"
|
2022-05-05 23:11:37 +08:00
|
|
|
"github.com/gravitl/netmaker/netclient/config"
|
2022-08-24 02:18:12 +08:00
|
|
|
"github.com/gravitl/netmaker/netclient/functions"
|
2021-09-20 02:03:47 +08:00
|
|
|
"github.com/gravitl/netmaker/netclient/ncutils"
|
2021-08-31 03:58:23 +08:00
|
|
|
"github.com/gravitl/netmaker/netclient/ncwindows"
|
2021-07-26 02:22:20 +08:00
|
|
|
"github.com/urfave/cli/v2"
|
2021-03-26 00:17:52 +08:00
|
|
|
)
|
|
|
|
|
2022-02-08 20:01:39 +08:00
|
|
|
var version = "dev"
|
|
|
|
|
2021-03-26 00:17:52 +08:00
|
|
|
func main() {
|
2021-07-26 02:22:20 +08:00
|
|
|
app := cli.NewApp()
|
2022-03-24 23:27:42 +08:00
|
|
|
app.Name = "Netclient"
|
2022-02-08 20:01:39 +08:00
|
|
|
app.Version = version
|
|
|
|
ncutils.SetVersion(version)
|
2021-12-09 05:52:32 +08:00
|
|
|
cliFlags := cli_options.GetFlags(ncutils.GetHostname())
|
|
|
|
app.Commands = cli_options.GetCommands(cliFlags[:])
|
2022-03-24 23:27:42 +08:00
|
|
|
app.Description = "Used to perform interactions with Netmaker server and set local WireGuard config."
|
|
|
|
app.Usage = "Netmaker's netclient agent and CLI."
|
2022-03-25 01:50:35 +08:00
|
|
|
app.UsageText = "netclient [global options] command [command options] [arguments...]. Adjust verbosity of given command with -v, -vv or -vvv (max)."
|
2021-03-28 00:50:27 +08:00
|
|
|
|
2021-09-11 03:48:18 +08:00
|
|
|
setGarbageCollection()
|
2022-08-24 02:18:12 +08:00
|
|
|
functions.SetHTTPClient()
|
2021-09-11 03:48:18 +08:00
|
|
|
|
2021-09-20 02:03:47 +08:00
|
|
|
if ncutils.IsWindows() {
|
2021-08-31 03:58:23 +08:00
|
|
|
ncwindows.InitWindows()
|
|
|
|
} else {
|
2021-12-09 05:52:32 +08:00
|
|
|
ncutils.CheckUID()
|
|
|
|
ncutils.CheckWG()
|
2022-08-19 22:43:51 +08:00
|
|
|
if ncutils.IsLinux() {
|
|
|
|
ncutils.CheckFirewall()
|
|
|
|
}
|
2021-08-31 03:58:23 +08:00
|
|
|
}
|
2022-02-02 13:18:02 +08:00
|
|
|
|
2022-05-05 23:11:37 +08:00
|
|
|
if len(os.Args) <= 1 && config.GuiActive {
|
|
|
|
config.GuiRun.(func())()
|
2022-05-05 21:48:02 +08:00
|
|
|
} else {
|
|
|
|
err := app.Run(os.Args)
|
|
|
|
if err != nil {
|
2022-09-20 03:37:00 +08:00
|
|
|
logger.FatalLog(err.Error())
|
2022-05-05 21:48:02 +08:00
|
|
|
}
|
2021-07-26 02:22:20 +08:00
|
|
|
}
|
2021-03-26 00:17:52 +08:00
|
|
|
}
|
2021-09-11 03:48:18 +08:00
|
|
|
|
2021-09-20 02:03:47 +08:00
|
|
|
func setGarbageCollection() {
|
|
|
|
_, gcset := os.LookupEnv("GOGC")
|
2021-09-11 03:48:18 +08:00
|
|
|
if !gcset {
|
2021-09-20 02:03:47 +08:00
|
|
|
debug.SetGCPercent(ncutils.DEFAULT_GC_PERCENT)
|
2021-09-11 03:48:18 +08:00
|
|
|
}
|
2021-09-20 02:03:47 +08:00
|
|
|
}
|