Auto-update server-only Macs and replace Sparkle's update UI
This commit is contained in:
@@ -8,8 +8,10 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
@@ -42,6 +44,7 @@ func serveCmd(args []string) {
|
||||
ctx, replaced := context.WithCancel(ctx)
|
||||
defer replaced()
|
||||
go watchExecutable(ctx, replaced)
|
||||
go updateDaily(ctx)
|
||||
|
||||
hs := &http.Server{
|
||||
Addr: *listenAddr,
|
||||
@@ -92,3 +95,30 @@ func watchExecutable(ctx context.Context, replaced context.CancelFunc) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func updateDaily(ctx context.Context) {
|
||||
for {
|
||||
update(ctx)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-time.After(24 * time.Hour):
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func update(ctx context.Context) {
|
||||
bin, err := exec.LookPath("byre-update")
|
||||
if err != nil {
|
||||
slog.Error("find byre-update", "err", err)
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(ctx, 30*time.Minute)
|
||||
defer cancel()
|
||||
out, err := exec.CommandContext(ctx, bin).CombinedOutput()
|
||||
if err != nil {
|
||||
slog.Error("byre-update", "err", err, "output", strings.TrimSpace(string(out)))
|
||||
return
|
||||
}
|
||||
slog.Info("byre-update", "output", strings.TrimSpace(string(out)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user