2020-06-21 12:33:43 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-09-27 16:26:18 +02:00
|
|
|
"fmt"
|
2021-08-05 20:19:25 +02:00
|
|
|
"os"
|
2021-09-27 17:24:34 +02:00
|
|
|
"runtime"
|
2021-08-05 20:19:25 +02:00
|
|
|
"time"
|
2020-06-21 12:33:43 +02:00
|
|
|
|
2021-08-06 08:29:57 +02:00
|
|
|
"github.com/efekarakus/termcolor"
|
2021-04-28 16:15:45 +02:00
|
|
|
"github.com/juanfont/headscale/cmd/headscale/cli"
|
2021-08-05 20:19:25 +02:00
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/spf13/viper"
|
2021-09-27 16:26:18 +02:00
|
|
|
"github.com/tcnksm/go-latest"
|
2020-06-21 12:33:43 +02:00
|
|
|
)
|
|
|
|
|
2021-04-25 17:24:42 +02:00
|
|
|
func main() {
|
2021-08-06 08:29:57 +02:00
|
|
|
var colors bool
|
|
|
|
switch l := termcolor.SupportLevel(os.Stderr); l {
|
|
|
|
case termcolor.Level16M:
|
|
|
|
colors = true
|
|
|
|
case termcolor.Level256:
|
|
|
|
colors = true
|
|
|
|
case termcolor.LevelBasic:
|
|
|
|
colors = true
|
|
|
|
default:
|
|
|
|
// no color, return text as is.
|
|
|
|
colors = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adhere to no-color.org manifesto of allowing users to
|
|
|
|
// turn off color in cli/services
|
|
|
|
if _, noColorIsSet := os.LookupEnv("NO_COLOR"); noColorIsSet {
|
|
|
|
colors = false
|
|
|
|
}
|
|
|
|
|
2021-08-05 20:19:25 +02:00
|
|
|
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
|
|
|
log.Logger = log.Output(zerolog.ConsoleWriter{
|
|
|
|
Out: os.Stdout,
|
|
|
|
TimeFormat: time.RFC3339,
|
2021-08-06 08:29:57 +02:00
|
|
|
NoColor: !colors,
|
2021-08-05 20:19:25 +02:00
|
|
|
})
|
|
|
|
|
2021-06-05 11:13:28 +02:00
|
|
|
err := cli.LoadConfig("")
|
2021-04-27 02:30:06 +02:00
|
|
|
if err != nil {
|
2021-08-05 20:19:25 +02:00
|
|
|
log.Fatal().Err(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
logLevel := viper.GetString("log_level")
|
|
|
|
switch logLevel {
|
|
|
|
case "trace":
|
|
|
|
zerolog.SetGlobalLevel(zerolog.TraceLevel)
|
|
|
|
case "debug":
|
|
|
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
|
|
case "info":
|
|
|
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
|
|
case "warn":
|
|
|
|
zerolog.SetGlobalLevel(zerolog.WarnLevel)
|
|
|
|
case "error":
|
|
|
|
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
|
|
|
|
default:
|
|
|
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
2021-04-27 02:30:06 +02:00
|
|
|
}
|
2021-04-24 04:54:15 +02:00
|
|
|
|
2021-10-13 00:18:55 +02:00
|
|
|
jsonOutput := cli.HasJsonOutputFlag()
|
|
|
|
if !viper.GetBool("disable_check_updates") && !jsonOutput {
|
2021-09-27 17:24:34 +02:00
|
|
|
if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && cli.Version != "dev" {
|
|
|
|
githubTag := &latest.GithubTag{
|
|
|
|
Owner: "juanfont",
|
|
|
|
Repository: "headscale",
|
|
|
|
}
|
|
|
|
res, err := latest.Check(githubTag, cli.Version)
|
|
|
|
if err == nil && res.Outdated {
|
|
|
|
fmt.Printf("An updated version of Headscale has been found (%s vs. your current %s). Check it out https://github.com/juanfont/headscale/releases\n",
|
|
|
|
res.Current, cli.Version)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-25 15:14:09 +02:00
|
|
|
cli.Execute()
|
2021-02-21 01:30:03 +01:00
|
|
|
}
|