gnu: Add kafs-client
[jackhill/guix/guix.git] / gnu / packages / patches / yggdrasil-extra-config.patch
CommitLineData
d814246e 1diff --git a/cmd/yggdrasil/main.go b/cmd/yggdrasil/main.go
2index 813e950..08d35cc 100644
3--- a/cmd/yggdrasil/main.go
4+++ b/cmd/yggdrasil/main.go
5@@ -40,11 +40,12 @@ type node struct {
6 admin module.Module // admin.AdminSocket
7 }
8
9-func readConfig(useconf *bool, useconffile *string, normaliseconf *bool) *config.NodeConfig {
10+func readConfig(useconf *bool, useconffile *string, extraconffile *string, normaliseconf *bool) *config.NodeConfig {
11 // Use a configuration file. If -useconf, the configuration will be read
12 // from stdin. If -useconffile, the configuration will be read from the
13 // filesystem.
14 var conf []byte
15+ var extraconf []byte
16 var err error
17 if *useconffile != "" {
18 // Read the file from the filesystem
19@@ -56,6 +57,21 @@ func readConfig(useconf *bool, useconffile *string, normaliseconf *bool) *config
20 if err != nil {
21 panic(err)
22 }
23+ if *extraconffile != "" {
24+ extraconf, err = ioutil.ReadFile(*extraconffile);
25+ }
26+ if err != nil {
27+ panic(err)
28+ }
29+ // Generate a new configuration - this gives us a set of sane defaults -
30+ // then parse the configuration we loaded above on top of it. The effect
31+ // of this is that any configuration item that is missing from the provided
32+ // configuration will use a sane default.
33+ cfg := config.GenerateConfig()
34+ var confs [2][]byte
35+ confs[0]=conf
36+ confs[1]=extraconf
37+ for _, conf := range confs { if len(conf)>0 {
38 // If there's a byte order mark - which Windows 10 is now incredibly fond of
39 // throwing everywhere when it's converting things into UTF-16 for the hell
40 // of it - remove it and decode back down into UTF-8. This is necessary
41@@ -69,11 +85,6 @@ func readConfig(useconf *bool, useconffile *string, normaliseconf *bool) *config
42 panic(err)
43 }
44 }
45- // Generate a new configuration - this gives us a set of sane defaults -
46- // then parse the configuration we loaded above on top of it. The effect
47- // of this is that any configuration item that is missing from the provided
48- // configuration will use a sane default.
49- cfg := config.GenerateConfig()
50 var dat map[string]interface{}
51 if err := hjson.Unmarshal(conf, &dat); err != nil {
52 panic(err)
53@@ -112,6 +123,7 @@ func readConfig(useconf *bool, useconffile *string, normaliseconf *bool) *config
54 if err = mapstructure.Decode(dat, &cfg); err != nil {
55 panic(err)
56 }
57+ }}
58 return cfg
59 }
60
61@@ -164,6 +176,7 @@ func main() {
62 genconf := flag.Bool("genconf", false, "print a new config to stdout")
63 useconf := flag.Bool("useconf", false, "read HJSON/JSON config from stdin")
64 useconffile := flag.String("useconffile", "", "read HJSON/JSON config from specified file path")
65+ extraconffile := flag.String("extraconffile", "", "extra (usually private) HJSON/JSON config from specified file path")
66 normaliseconf := flag.Bool("normaliseconf", false, "use in combination with either -useconf or -useconffile, outputs your configuration normalised")
67 confjson := flag.Bool("json", false, "print configuration from -genconf or -normaliseconf as JSON instead of HJSON")
68 autoconf := flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)")
69@@ -187,7 +200,7 @@ func main() {
70 cfg = config.GenerateConfig()
71 case *useconffile != "" || *useconf:
72 // Read the configuration from either stdin or from the filesystem
73- cfg = readConfig(useconf, useconffile, normaliseconf)
74+ cfg = readConfig(useconf, useconffile, extraconffile, normaliseconf)
75 // If the -normaliseconf option was specified then remarshal the above
76 // configuration and print it back to stdout. This lets the user update
77 // their configuration file with newly mapped names (like above) or to
78@@ -332,7 +345,7 @@ func main() {
79 goto exit
80 case _ = <-r:
81 if *useconffile != "" {
82- cfg = readConfig(useconf, useconffile, normaliseconf)
83+ cfg = readConfig(useconf, useconffile, extraconffile, normaliseconf)
84 logger.Infoln("Reloading configuration from", *useconffile)
85 n.core.UpdateConfig(cfg)
86 n.tuntap.UpdateConfig(cfg)