From 0ecde0c1ef5cab0bfb37c9a91c1a1260095643ee Mon Sep 17 00:00:00 2001 From: sysops Date: Fri, 12 Jun 2026 23:45:15 +0200 Subject: [PATCH] =?UTF-8?q?feat(cli):=20archivmail=20update=20=E2=80=94=20?= =?UTF-8?q?Wrapper=20f=C3=BCr=20update.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Statt update.sh manuell zu suchen/laden kann jetzt `archivmail update` (als root) ausgeführt werden. Nutzt /opt/archivmail/update.sh falls vorhanden, sonst Download von Gitea. --- cmd/archivmail/cmd_import.go | 1 + cmd/archivmail/cmd_update.go | 56 ++++++++++++++++++++++++++++++++++++ cmd/archivmail/main.go | 3 ++ 3 files changed, 60 insertions(+) create mode 100644 cmd/archivmail/cmd_update.go diff --git a/cmd/archivmail/cmd_import.go b/cmd/archivmail/cmd_import.go index 1b26dd9..5aeb6a7 100644 --- a/cmd/archivmail/cmd_import.go +++ b/cmd/archivmail/cmd_import.go @@ -287,6 +287,7 @@ Commands: recompress Bestehende Mails nachträglich gzip-komprimieren rethread Thread-IDs rückwirkend aus In-Reply-To/References befüllen ocr-reprocess OCR für Anhänge nachholen (alle oder pro Mandant/Status) + update Auf neueste Version aktualisieren (führt update.sh aus) version Version anzeigen help Diese Hilfe anzeigen diff --git a/cmd/archivmail/cmd_update.go b/cmd/archivmail/cmd_update.go new file mode 100644 index 0000000..fd53e40 --- /dev/null +++ b/cmd/archivmail/cmd_update.go @@ -0,0 +1,56 @@ +package main + +import ( + "fmt" + "os" + "os/exec" +) + +const updateScriptURL = "https://gitea.perlbach24.de/scripte/archivmail/raw/branch/main/update.sh" +const updateScriptPath = "/opt/archivmail/update.sh" + +// runUpdate fetches and executes update.sh, which pulls the latest version +// from git, rebuilds frontend + backend, and restarts the services. +// Usage: archivmail update +func runUpdate(args []string) { + if os.Geteuid() != 0 { + fmt.Fprintln(os.Stderr, "archivmail update: muss als root ausgeführt werden (sudo archivmail update)") + os.Exit(1) + } + + script := updateScriptPath + if _, err := os.Stat(script); err != nil { + var dlErr error + script, dlErr = downloadUpdateScript() + if dlErr != nil { + fmt.Fprintf(os.Stderr, "archivmail update: %s nicht gefunden und Download fehlgeschlagen: %v\n", updateScriptPath, dlErr) + os.Exit(1) + } + defer os.Remove(script) + } + + cmd := exec.Command("bash", script) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.Stdin = os.Stdin + if err := cmd.Run(); err != nil { + fmt.Fprintf(os.Stderr, "archivmail update: %v\n", err) + os.Exit(1) + } +} + +func downloadUpdateScript() (string, error) { + tmp, err := os.CreateTemp("", "archivmail-update-*.sh") + if err != nil { + return "", err + } + tmp.Close() + + cmd := exec.Command("curl", "-fsSL", updateScriptURL, "-o", tmp.Name()) + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + os.Remove(tmp.Name()) + return "", err + } + return tmp.Name(), nil +} diff --git a/cmd/archivmail/main.go b/cmd/archivmail/main.go index b7f4dae..b1d7514 100644 --- a/cmd/archivmail/main.go +++ b/cmd/archivmail/main.go @@ -67,6 +67,9 @@ func main() { case "ocr-reprocess": runOCRReprocess(os.Args[2:]) return + case "update": + runUpdate(os.Args[2:]) + return case "version": fmt.Printf("archivmail %s\n", AppVersion) for mod, ver := range Modules {