main: move root and node UUID checks to setup():

to prevent log messages on 'hvpn-node --help'

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2024-03-15 00:29:08 +03:00
parent 39d3b55a34
commit 79463c18b9
Signed by: Hesham
GPG Key ID: 74876157D199B09E

View File

@ -40,21 +40,9 @@ func main() {
// TODO: Define error exit codes
slog.SetLogLoggerLevel(slog.LevelDebug)
uid := os.Getuid()
if uid == -1 {
slog.Warn("Running on windows! whatrr u doing?")
} else if uid == 0 {
slog.Warn("Running as root! avoid running as root by setting CAP_NET_ADMIN")
}
uuid, err := hvpnnode3.InitNodeUUID()
if err != nil {
slog.Error(err.Error())
os.Exit(-1)
}
slog.Info("Node UUID: " + uuid.String())
app := createCliApp()
err = app.Run(os.Args)
err := app.Run(os.Args)
if err != nil {
slog.Error(err.Error())
os.Exit(1)
@ -195,6 +183,19 @@ func createCliApp() *cli.App {
func setup() error {
slog.Debug("Starting setup()")
uid := os.Getuid()
if uid == -1 {
slog.Warn("Running on windows! whatrr u doing?")
} else if uid == 0 {
slog.Warn("Running as root! avoid running as root by setting CAP_NET_ADMIN")
}
uuid, err := hvpnnode3.InitNodeUUID()
if err != nil {
slog.Error(err.Error())
os.Exit(-1)
}
slog.Info("Node UUID: " + uuid.String())
privKeyFile, err := os.Open(PrivateKeyPath)
if err != nil {
return cli.Exit(err, 1)