diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-04-05 00:28:47 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-04-05 00:39:49 -0600 |
commit | 34e3a000c561fd2c8ef65bdb5a296f0b03095a99 (patch) | |
tree | 92557d70ea2433808636e9aafed27bcd5c12bcc2 /main.go | |
parent | syntax: insist on 256-bit keys, not 257-bit or 258-bit (diff) | |
download | wireguard-windows-34e3a000c561fd2c8ef65bdb5a296f0b03095a99.tar.xz wireguard-windows-34e3a000c561fd2c8ef65bdb5a296f0b03095a99.zip |
updater: allow updating from the command line
The administrator user may run `wireguard.exe /update`, which will check
for updates and install it if available. A log file may be written using
`wireguard.exe /update path\to\log\file.txt`.
Requested-by: Elliot Saba <staticfloat@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -7,6 +7,7 @@ package main import ( "fmt" + "log" "os" "strconv" "strings" @@ -20,6 +21,7 @@ import ( "golang.zx2c4.com/wireguard/windows/ringlogger" "golang.zx2c4.com/wireguard/windows/tunnel" "golang.zx2c4.com/wireguard/windows/ui" + "golang.zx2c4.com/wireguard/windows/updater" ) func fatal(v ...interface{}) { @@ -46,6 +48,7 @@ func usage() { "/tunnelservice CONFIG_PATH", "/ui CMD_READ_HANDLE CMD_WRITE_HANDLE CMD_EVENT_HANDLE LOG_MAPPING_HANDLE", "/dumplog OUTPUT_PATH", + "/update [LOG_FILE]", } builder := strings.Builder{} for _, flag := range flags { @@ -224,6 +227,42 @@ func main() { fatal(err) } return + case "/update": + if len(os.Args) != 2 && len(os.Args) != 3 { + usage() + } + var f *os.File + var err error + if len(os.Args) == 2 { + f = os.Stdout + } else { + f, err = os.Create(os.Args[2]) + if err != nil { + fatal(err) + } + defer f.Close() + } + l := log.New(f, "", log.LstdFlags) + for progress := range updater.DownloadVerifyAndExecute(0) { + if len(progress.Activity) > 0 { + if progress.BytesTotal > 0 || progress.BytesDownloaded > 0 { + var percent float64 + if progress.BytesTotal > 0 { + percent = float64(progress.BytesDownloaded) / float64(progress.BytesTotal) * 100.0 + } + l.Printf("%s: %d/%d (%.2f%%)\n", progress.Activity, progress.BytesDownloaded, progress.BytesTotal, percent) + } else { + l.Println(progress.Activity) + } + } + if progress.Error != nil { + l.Printf("Error: %v\n", progress.Error) + } + if progress.Complete || progress.Error != nil { + return + } + } + return } usage() } |