-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (57 loc) · 1.73 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
60
61
62
63
64
65
66
67
68
package main
import (
"flag"
"log"
"os"
"path/filepath"
"time"
"github.com/DemmyDemon/glesys-dns-client/config"
"github.com/DemmyDemon/glesys-dns-client/glesys"
)
func main() {
ip, err := config.GetExternalIPv4()
if err != nil {
log.Fatalf("Could not determine external IPv4: %s\n", err)
}
log.SetOutput(os.Stdout)
log.SetPrefix("[" + ip + "] ")
homedir, err := os.UserHomeDir()
if err != nil {
log.Fatalf("Could not determine homedir: %s\n", err)
}
var certBotClean string
var configFile string
flag.StringVar(&configFile, "cfg", homedir+"/.glesys_dns.json", "Path to where the Configuration is stored.")
flag.StringVar(&ip, "ip", ip, "IP address to check against, and update to.")
flag.StringVar(&certBotClean, "certbotclean", "", "Domain to clean up certbot validations for")
flag.Parse()
configFile = filepath.Clean(configFile)
cfg, err := config.Load(configFile)
if err != nil {
log.Fatalf("Could not load configuration file: %s", err)
}
client := glesys.NewGlesysClient(cfg.Credentials.User, cfg.Credentials.Key)
if certBotClean != "" {
err := client.CertbotCleanup(certBotClean)
if err != nil {
log.Fatal(err)
}
os.Exit(0) // Because if we're cleaning, we are *just* cleaning.
}
certbotDomain := os.Getenv("CERTBOT_DOMAIN")
if certbotDomain != "" {
// That is, we're in CERTBOT mode...
certbotValidation := os.Getenv("CERTBOT_VALIDATION")
if certbotValidation == "" {
certbotValidation = "dry-run"
}
err := client.Certbot(certbotDomain, certbotValidation)
if err != nil {
log.Fatal(err)
}
log.Println("Will idle for 60 seconds for TXT records to settle.")
time.Sleep(60 * time.Second)
os.Exit(0) // DO NOT do the updates if we're in certbot mode.
}
client.Update(ip, cfg.Hosts)
}