-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (51 loc) · 1.43 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/opensourcelan/linksys-config/configprovider"
"github.com/opensourcelan/linksys-config/inventory"
"github.com/opensourcelan/linksys-config/telnetpusher"
"github.com/opensourcelan/linksys-config/tftpserver"
)
func main() {
if len(os.Args) < 3 {
fmt.Printf("Expects 2 or more arguments. First argument: print (the config) or push (the config to a switch)\nThen at least one or more Switch IPs to generate for")
return
}
cfg := loadConfig()
switches := inventory.ReadTheData(cfg.GoogleSheetID)
cfgProvider := configprovider.GetConfigProvider(switches)
if os.Args[1] == "print" {
cfg, err := cfgProvider(os.Args[2])
if err != nil {
panic(err)
}
fmt.Println(cfg)
return
} else if os.Args[1] == "push" {
go tftpserver.ServeTFTP(cfg.TftpFilename, cfgProvider)
telnetpusher.AskSwitchToPullConfig(os.Args[2], cfg.Username, cfg.Password, cfg.TftpServerIp, cfg.TftpFilename)
} else {
fmt.Println("print or push required for first arg")
}
}
type config struct {
GoogleSheetID string `json:"google_spreadsheet_id"`
Username string `json:"username"`
Password string `json:"password"`
TftpServerIp string `json:"tftp_server_ip"`
TftpFilename string `json:"tftp_filename"`
}
func loadConfig() config {
d, err := os.ReadFile("config.json")
if err != nil {
panic(err)
}
var c config
err = json.Unmarshal(d, &c)
if err != nil {
panic(err)
}
return c
}