feat(cli): archivmail update — Wrapper für update.sh

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.
This commit is contained in:
sysops
2026-06-12 23:45:15 +02:00
parent 501ee8f7ea
commit 0ecde0c1ef
3 changed files with 60 additions and 0 deletions
+1
View File
@@ -287,6 +287,7 @@ Commands:
recompress Bestehende Mails nachträglich gzip-komprimieren recompress Bestehende Mails nachträglich gzip-komprimieren
rethread Thread-IDs rückwirkend aus In-Reply-To/References befüllen 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) 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 version Version anzeigen
help Diese Hilfe anzeigen help Diese Hilfe anzeigen
+56
View File
@@ -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
}
+3
View File
@@ -67,6 +67,9 @@ func main() {
case "ocr-reprocess": case "ocr-reprocess":
runOCRReprocess(os.Args[2:]) runOCRReprocess(os.Args[2:])
return return
case "update":
runUpdate(os.Args[2:])
return
case "version": case "version":
fmt.Printf("archivmail %s\n", AppVersion) fmt.Printf("archivmail %s\n", AppVersion)
for mod, ver := range Modules { for mod, ver := range Modules {