38 lines
883 B
Go
38 lines
883 B
Go
//go:build gokrazy
|
|
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/antelman107/net-wait-go/wait"
|
|
"github.com/gokrazy/gokrazy"
|
|
)
|
|
|
|
func main() {
|
|
gokrazy.WaitForClock()
|
|
if !wait.New(wait.WithDeadline(time.Minute), wait.WithWait(time.Second), wait.WithBreak(time.Second)).Do([]string{"www.comics.org:443"}) {
|
|
log.Println("Failed to connect to www.comics.org")
|
|
os.Exit(1) // Exit code 1 will cause gokrazy to restart the service
|
|
}
|
|
flag.Parse()
|
|
if os.Getenv("GCD_USERNAME") == "" || os.Getenv("GCD_PASSWORD") == "" {
|
|
log.Println("Username and password not provided")
|
|
os.Exit(0)
|
|
}
|
|
for {
|
|
createDirs()
|
|
lastUpdate := getLatestDate()
|
|
if shouldUpdate(lastUpdate) {
|
|
download(lastUpdate)
|
|
log.Println("update complete, waiting 1h to check again")
|
|
} else {
|
|
log.Println("It's too early, waiting 1h to check again")
|
|
}
|
|
time.Sleep(time.Hour)
|
|
}
|
|
}
|