2023-10-16 02:47:14 -07:00
|
|
|
//go:build gokrazy
|
2023-10-23 19:41:43 -07:00
|
|
|
|
2023-10-16 02:47:14 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2023-10-16 03:05:21 -07:00
|
|
|
"github.com/antelman107/net-wait-go/wait"
|
2023-10-23 19:41:43 -07:00
|
|
|
"github.com/gokrazy/gokrazy"
|
2023-10-16 02:47:14 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gokrazy.WaitForClock()
|
2023-10-16 03:05:21 -07:00
|
|
|
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
|
|
|
|
}
|
2023-10-16 02:47:14 -07:00
|
|
|
flag.Parse()
|
|
|
|
if os.Getenv("GCD_USERNAME") == "" || os.Getenv("GCD_PASSWORD") == "" {
|
|
|
|
log.Println("Username and password not provided")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
for {
|
|
|
|
createDirs()
|
2023-10-23 19:41:43 -07:00
|
|
|
lastUpdate := getLatestDate()
|
|
|
|
if shouldUpdate(lastUpdate) {
|
|
|
|
download(lastUpdate)
|
2023-10-16 02:47:14 -07:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|