2019-08-13 09:48:47 -05:00
|
|
|
package main
|
2019-08-14 17:41:15 -05:00
|
|
|
|
2019-09-25 22:17:38 -05:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// this file is for generating the config if it doesn't exist, mainly for the idiots like me :)
|
2019-08-14 17:41:15 -05:00
|
|
|
// this is not really a priority right now so it sitting in the backburner as you read this
|
|
|
|
// signed Wyatt J. Miller, the awesome guy who doesn't generate configs *thumbs up*
|
2019-09-25 22:17:38 -05:00
|
|
|
|
|
|
|
var config string = "config.yaml"
|
|
|
|
|
|
|
|
func doesConfigExist() bool {
|
|
|
|
_, err := os.Stat(config)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
2019-09-29 12:38:58 -05:00
|
|
|
|
|
|
|
return true
|
2019-09-25 22:17:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func createTemplateConfig(result bool) {
|
|
|
|
if result == false {
|
|
|
|
os.Create(config)
|
|
|
|
} else {
|
2019-09-29 12:38:58 -05:00
|
|
|
fmt.Println("Configuration file already created")
|
2019-09-25 22:17:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func writeTemplateConfig(filename string) {
|
2019-09-29 12:38:58 -05:00
|
|
|
hosts := make([]string, 1)
|
|
|
|
logs := make([]string, 1)
|
|
|
|
|
|
|
|
config := Configuration{
|
|
|
|
"jbob",
|
|
|
|
"jbobisawesome",
|
|
|
|
22,
|
|
|
|
hosts,
|
|
|
|
logs,
|
|
|
|
}
|
2019-09-25 22:17:38 -05:00
|
|
|
|
2019-09-29 12:38:58 -05:00
|
|
|
data, err := yaml.Marshal(&config)
|
2019-09-25 22:17:38 -05:00
|
|
|
|
2019-09-29 12:38:58 -05:00
|
|
|
fmt.Printf(string(data))
|
|
|
|
_ = ioutil.WriteFile(filename, data, 0600)
|
2019-09-25 22:17:38 -05:00
|
|
|
|
|
|
|
if err != nil {
|
2019-09-29 12:38:58 -05:00
|
|
|
fmt.Errorf("Couldn't create the configuration file", err)
|
2019-09-25 22:17:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Template for logman's configuration complete!")
|
|
|
|
fmt.Println("")
|
|
|
|
fmt.Println("Fill in the necessary credentials you need. If")
|
|
|
|
fmt.Println("you need assitance, check out the wiki for more.")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|